You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by tsubasaotl <ts...@qq.com> on 2019/01/24 10:04:20 UTC
Re: [Discuss]Business exception cannot be rollbacked inShardingSphere with saga transaction.
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
Re: [Discuss]Business exception cannot be rollbacked inShardingSphere
with saga transaction.
Posted by Willem Jiang <wi...@gmail.com>.
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
Re: [Discuss]Business exception cannot be rollbacked inShardingSphere
with saga transaction.
Posted by Willem Jiang <wi...@gmail.com>.
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