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/16 12:05:51 UTC

[Discuss]Business exception cannot be rollbacked in ShardingSphere with saga transaction.

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

Re: [Discuss]Business exception cannot be rollbacked in ShardingSphere with saga transaction.

Posted by Zheng Feng <zh...@gmail.com>.
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

Re: [Discuss]Business exception cannot be rollbacked in ShardingSphere with saga transaction.

Posted by Zheng Feng <zh...@gmail.com>.
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