Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Saga Transaction #986

Closed
tuohai666 opened this issue Jul 6, 2018 · 3 comments
Closed

Support Saga Transaction #986

tuohai666 opened this issue Jul 6, 2018 · 3 comments

Comments

@tuohai666
Copy link
Member

What's Saga?
The paper:
https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf
The github project which Sharding-Sphere will integrate with:
https://github.com/apache/incubator-servicecomb-saga
More information from Willem Jiang's presentation:
http://servicecomb.incubator.apache.org/cn/docs/distributed-transactions-saga-implementation/

The second soft transaction (i.e. flexible transaction) which Sharding-Sphere will support is Saga transaction. In the first step, we plan to implement it in Sharding-JDBC.

SS starts a transaction via Saga API(https://github.com/apache/incubator-servicecomb-saga/blob/old-saga/docs/api/api.md). The API looks like this:
{
"policy": "",
"requests": [
{
"id": "",
"type": "",
"serviceName": "",
"parents": [
],
"transaction": {
"method": "",
"path": "",
"params": {
}
},
"compensation": {
"method": "",
"path": "",
"params": {
}
}
}
]
}
Logic SQLs in a SS transaction will be treated as one Saga Request separately. Users of SS should supply the compensatory SQLs correspondingly:
transaction:
INSERT INTO t_order (order_id, user_id, status) VALUES (?, '10', 'INIT');
compensation:
DELETE FROM t_order WHERE order_id=?;
SS need to implement method of both transaction and compensation for Saga. The path parameter seems to have no use for SS, and should be ignored.
The content of params should include SQL and the parameter of SQL, may implement by currently form parameters.
At last, id and serviceName will be generated by SS uniquely. Saga can use these identifier to find transactions.

@tuohai666 tuohai666 self-assigned this Jul 6, 2018
tuohai666 added a commit that referenced this issue Jul 6, 2018
tuohai666 added a commit that referenced this issue Jul 6, 2018
tuohai666 added a commit that referenced this issue Jul 6, 2018
tuohai666 added a commit that referenced this issue Jul 9, 2018
tuohai666 added a commit that referenced this issue Jul 9, 2018
tuohai666 added a commit that referenced this issue Jul 10, 2018
tuohai666 added a commit that referenced this issue Jul 10, 2018
tuohai666 added a commit that referenced this issue Jul 10, 2018
tuohai666 added a commit that referenced this issue Jul 10, 2018
tuohai666 added a commit that referenced this issue Jul 12, 2018
tuohai666 added a commit that referenced this issue Jul 12, 2018
tuohai666 added a commit that referenced this issue Jul 12, 2018
tuohai666 added a commit that referenced this issue Jul 12, 2018
tuohai666 added a commit that referenced this issue Jul 13, 2018
tuohai666 added a commit that referenced this issue Jul 13, 2018
tuohai666 added a commit that referenced this issue Jul 13, 2018
tuohai666 added a commit that referenced this issue Jul 14, 2018
@terrymanu terrymanu assigned KomachiSion and unassigned tuohai666 Aug 8, 2018
@terrymanu terrymanu changed the title Support Saga Transaction in Sharding-JDBC Support Saga Transaction Sep 6, 2018
@KomachiSion
Copy link
Member

In the previous description, Sharding-Sphere uses Service Comb Saga's Restful API to implement saga transactions. But SS would like to use saga coordinator in an internal call.
After discussing with Service Comb, Service Comb Saga will extend some interfaces so that SS can call the saga coordinator internally.
Related issue: https://issues.apache.org/jira/browse/SCB-864

@KomachiSion
Copy link
Member

SS also starts transaction via Saga API https://github.com/apache/incubator-servicecomb-saga/blob/master/docs/api/api.md .
The new API looks like:

{
  "policy": "",
  "requests": [
    {
      "id": "",
      "type": "",
      "datasource": "",
      "parents": [

      ],
      "transaction": {
        "sql": "",
        "params": [
          []
        ]
      },
      "compensation": {
        "sql": "",
        "params": [
          []
        ]
      }
    }
  ]
}

Logic SQLs in a transaction will be parsed and routed, and will be combined into a graph.
This graph will be mapped to saga API json and invoke saga coordinator to execute saga transaction.

@KomachiSion
Copy link
Member

KomachiSion commented Oct 16, 2018

TODO list of saga transaction:

  • Integrate Service Comb Saga
    • Build saga request from SQLs in transaction
    • Invoke Service Comb Saga in SagaTransactionManager
  • Sharding-JDBC support Saga
    • Support JDBC statement
    • Support JDBC preparedStatement
    • Support JDBC BatchPreparedStatement
  • Sharding-Proxy support Saga
    • Support Proxy JDBC backend
  • Support different recover policy
    • Support forward recover policy
      • Configure the max retires
    • Support backward recover policy
      • Generate revert SQL
  • Persistent Store Saga transaction logs
  • Configure Saga params
    • Configure in Sharding-JDBC
      • Init configuration
      • Renew configuration
    • Configure in Sharding-Proxy
      • Init configuration
      • Renew configuration
  • Examples
    • Example for Sharding-JDBC
    • Example for Sharding-Proxy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants