You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shardingsphere.apache.org by tsubasaotl <ts...@qq.com> on 2019/01/25 06:51:12 UTC

Re: [Discuss]Business exception cannot be rollbackedinShardingSpherewith saga transaction.

If there is SQL execution error before the commit. ShardingSphere will throw the exception
to user if policy is backward. User catches the exception and call rollback generally.
And if policy is forward, it means user think SQL should be executed successfully.
So ShardingSphere will catch the SQLException and go ahead. After user committing, 
the failed SQL will retry.


Currently, my plan is ShardingSphere should get snapshot and do SQL user given, 
and saga-actuator only is responsible for control recovery.


------------------
Yi Yang (Sion)
Apache ShardingSphere contributor


 




------------------ Original ------------------
From:  "Willem Jiang"<wi...@gmail.com>;
Date:  Fri, Jan 25, 2019 02:25 PM
To:  "dev"<de...@shardingsphere.apache.org>;
Cc:  "dev"<de...@servicecomb.apache.org>; 
Subject:  Re: [Discuss]Business exception cannot be rollbackedinShardingSpherewith saga transaction.



It looks like the ShardingSphere hijack the SQL execution before the
commit or the rollback call, what if there is SQL execution error
before the commit.
What's your plan to let saga-actuator interact with ShardingSphere.

Willem Jiang

Twitter: willemjiang
Weibo: 姜宁willem

On Fri, Jan 25, 2019 at 10:06 AM tsubasaotl <ts...@qq.com> wrote:
>
> When users execute SQL with saga transaction, ShardingSphere will execute the SQL immediately.
> After `commit` or `rollback` called, ShardingSphere starts to generate the saga execution graph.
> At this time, all SQL and their order in transaction has be known by ShardingSphere,
> so the saga execution graph can be generated.
>
>
> Specially, for `rollback`, ShardingSphere add a rollback request at the end of graph.
>
>
>
> ------------------
> Yi Yang (Sion)
> Apache ShardingSphere contributor
>
>
>
>
>
> ------------------ Original ------------------
> From:  "Willem Jiang"<wi...@gmail.com>;
> Date:  Fri, Jan 25, 2019 08:50 AM
> To:  "dev"<de...@servicecomb.apache.org>;
> Cc:  "dev"<de...@shardingsphere.apache.org>;
> Subject:  Re: [Discuss]Business exception cannot be rollbacked inShardingSpherewith saga transaction.
>
>
>
> Hi Sion,
>
> My question is how can we generate the saga execution graph with the
> rollback request at the first place?
>
> Willem Jiang
>
> Twitter: willemjiang
> Weibo: 姜宁willem
>
> On Thu, Jan 24, 2019 at 6:04 PM tsubasaotl <ts...@qq.com> wrote:
> >
> > I think we think it too complicated. In fact, no matter what the exception is, As long as the rollback is called, a rollback request is added at the end of the call graph of saga. The actuator reads the rollback request and starts to reverse the compensation. The saga definition should be
> >
> >
> > {
> >         "policy": "BackwardRecovery",
> >         "requests": [{
> >                 "id": "xxx",
> >                 "datasource": "ds",
> >                 "type": "sql",
> >                 "transaction": {
> >                         ...
> >                 },
> >                 "compensation": {
> >                         ...
> >                 },
> >                 "parents": [],
> >         },
> >         ...
> >         ,{
> >                 "id": "yyy",
> >                 "datasource": "ds",
> >                 "type": "sql",
> >                 "transaction": {
> >                         "sql": "ROLLBACK_EVENT",
> >                          ...
> >                 },
> >                 "compensation": {
> >                          ...
> >                 },
> >                 "parents": [the last ids of actual requests],
> >         }]
> > }
> >
> >
> >
> > ------------------
> > Yi Yang (Sion)
> > Apache ShardingSphere contributor
> >
> >
> >
> >
> >
> > ------------------ Original ------------------
> > From:  "Zheng Feng"<zh...@gmail.com>;
> > Date:  Fri, Jan 18, 2019 10:26 AM
> > To:  "dev"<de...@servicecomb.apache.org>;
> > Cc:  "dev"<de...@shardingsphere.apache.org>;
> > Subject:  Re: [Discuss]Business exception cannot be rollbacked inShardingSphere with saga transaction.
> >
> >
> >
> > I think it could be be resolved in ShardingSphere and catch the business
> > exception and mark the cached result "ROLLBACK_ONLY".
> > Anyway, this should be done before submitting to the saga actor.
> >
> > tsubasaotl <ts...@qq.com> 于2019年1月16日周三 下午8:06写道:
> >
> > > Hi, everyone.
> > >
> > >
> > > In ShardingSphere, SQL and their execution result will be cached in saga
> > > transaction manager.
> > > When users call `commit` or `rollback` method, the cached SQL will
> > > generate `SagaDefinition`
> > > and submit it to the saga actuator.
> > >
> > >
> > > Saga actuator do `Transaction` first and get execution result from cached.
> > > When the result is successful, the actuator will directly judge that the
> > > Transaction is successful
> > > and execute the next Transaction.
> > > When the result not found in cached or the result is failed, the actuator
> > > will do retry or compensation
> > > according to configuration.
> > >
> > >
> > > But there is a problem that saga actuator cannot rollback when business
> > > exception happened.
> > > The situation will happen in following workflow.
> > >
> > >
> > >                                -----------multiple times-----------
> > > begin transaction --> | execute SQL --> cached result | --> throw business
> > > exception --> call rollback
> > >                                --------------------------------------
> > >                                                      |
> > >
> > >                                                                  |
> > >
> > >                                                                  |
> > > but all SQL success, saga actuator don't run compensation  <-- get result
> > > from cache <-- saga actuator
> > >
> > >
> > > All SQL is executed successfully, but the business program throws an
> > > exception. So the actuator will judge
> > > transaction is successful, and not to do compensation, which makes users
> > > confused.
> > >
> > >
> > > On this issue, I would like to ask for advice, should resolved in Saga
> > > actuator or ShardingSphere?
> > > And how to resolve better?
> > >
> > >
> > > ------------------
> > > Yi Yang (Sion)
> > > Apache ShardingSphere contributor