Background knowledge

Seata is a distributed transaction framework jointly built by Alibaba Group and Ant Financial. The current version includes AT transaction and TCC transaction. Among them, the goal of AT transaction is to provide incremental transaction ACID semantics under the microservice architecture, so that users can use distributed transactions like using local transactions, and the core concept is consistent with ShardingSphere.

Github: github.com/seata/seata

Seata AT model

The Seata AT transaction model includes TM(transaction manager), RM(resource manager), and TC(transaction coordinator).

Among them, TC is an independent service that needs to be deployed separately. TM and RM are deployed together with business applications in the form of JAR packages. They establish a long connection with TC and maintain RPC communication during the whole transaction life cycle.

The initiator of the global transaction is TM, and the participant of the global transaction is RM. TM is responsible for BEGIN and COMMIT/ROLLBACK of global transactions, and RM is responsible for execution of branch transactions and COMMIT/ROLLBACK.

ShardingSphere Distributed transaction SPI

ShardingSphere provides an SPI for accessing distributed transactions, designed to ensure the ACID semantics of transactions after data sharding. The implementation of distributed transactions currently mainly consists of two-phase XA and BASE flexible transactions. As an implementation of BASE flexible transactions, Seata AT transactions can be seamlessly connected into the ShardingSphere ecosystem.

In terms of two-phase XA transactions, we have integrated Atomikos, Narayana and Bitronix transaction managers. The underlying XA transaction relies on the support of specific database vendors for XA two-phase Commit protocols. XA usually performs 2PL(two-phase lock) during the Prepare and Commit phases. Ensure the distributed transaction of ACID, usually applies to short transaction and the cloud environment (cloud environment next IO operation probably need 20 ms, two phase lock can lock resources for 40 ms, so the TPS transaction will to around 25 / s, the cloud environment is usually only a few milliseconds, a IO so hot data lock time are relatively low) [1].

In terms of BASE flexible transactions, we have completed the integration of ServiceComb Saga. Saga improves the performance of the whole transaction through one-stage commit + compensation. The compensation method is roughly the same as Seata, that is, to generate the compensated SQL by revert from the fragmented physical SQL. However, the Saga model does not support isolation levels in theory and is suitable for businesses with high performance requirements and low consistency requirements. Seata AT transactions support RC isolation level through TC global locking on a one-phase commit + compensation basis, which is another implementation between XA and Saga. For message flexible transactions, you are also welcome to refer to our SPI for integration solutions.

Integration scheme

When integrating Seata AT transactions, TM, RM and TC models need to be integrated into the SPI ecosystem of ShardingSphere distributed transactions. On the database resource, Seata connects to the DataSource interface so that JDBC operations can communicate with TCS through RPC. Similarly, ShardingSphere also aggregates the user-configured physical DataSource for DataSource interface. Therefore, after the physical DataSource is re-packaged as Seata’s DataSource, You can integrate Seata AT transactions into sharding in the ShardingSphere.

In the Seata model, the context of a global transaction is stored in thread variables. By extending the transport between services, thread variables can be transferred. Branch transactions use thread variables to determine whether to join the whole Seata global transaction. However, sharding execution engine of ShardingSphere usually executes according to multiple threads, so when integrating Seata AT transactions, transaction context transmission of main thread and child thread needs to be extended, which is exactly the same as context transmission between services.

Quick Start

We have implemented base-seata-raw-jdbC-example, so you can try it on your own.

Github.com/apache/incu…

Operation Manual:

1. Download and start the Seata Server by following the steps in Seata-work-shop.

Github.com/seata/seata…

Refer to Step6 and Step7

2. Run the resources/ SQL /undo_log. SQL script in each shard database instance to create the undo_log table

3.Run YamlConfigurationTransactionExample.java

To optimize a

In the case of Seata AT transaction, it is necessary to parse physical SQL after ShardingSphere sharding. In this case, we need to design an SPI to avoid the performance loss of SQL secondary parsing.

The reference papers

[1]: Transactions for Distributed Actors in the Cloud

www.microsoft.com/en-us/resea…

Apache ShardingSphere (Incubating) has been in Incubating since 2016, and has been continuously improved and developed by more and more businesses and individuals: Github received 7,000 + stars and 70+ business success cases. In addition, more and more businesses and individuals are participating in Apache ShardingSphere (Incubating) open source projects, contributing to its growth and development.

ShardingSphere is currently open to recruit full-time r&d personnel on a long-term basis. We welcome outstanding talents from the open source community to join us and jointly build an outstanding open source ecosystem.

ShardingSphere has received increasing attention since it entered the Apache Foundation incubator, and our goal is to establish it as the standard for distributed database middleware. Participation in the development and community building of open source projects not only brings benefits to the participants and the project itself, but also provides them with fun and a sense of accomplishment.

The position is open for long-term participation in the development and community building of ShardingSphere. Preference will be given to students who have a deep understanding of the ShardingSphere and are deeply involved in community building. We are waiting for you to work full time with open source!

Project Address:

Github.com/apache/incu…

For more information, please visit our official website:

shardingsphere.apache.org/

Position Information:

Mp.weixin.qq.com/s/V4qfA5Kji…

Recruitment Email:

[email protected]