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"<[email protected]>;
Date: Fri, Jan 18, 2019 10:26 AM
To: "dev"<[email protected]>;
Cc: "dev"<[email protected]>;
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 <[email protected]> ??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