Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

ShardingSphere x Seata, a more consistent distributed database middleware

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

A few days ago, the distributed database middleware ShardingSphere integrates the distributed transaction capabilities of Seata in order to create a more consistent distributed database middleware.

Background

In the field of database, the implementation of distributed transaction mainly includes: two-stage XA and BASE flexible transaction.

The underlying layer of XA transactions depends on the specific database vendors' support for the XA two-phase commit protocol. In general, the XA protocol ensures the ACID of distributed transactions by performing 2PL (2-phase locking) in Prepare and Commit phases, which is suitable for short transactions and non-cloud environments. (an IO operation in cloud environment probably requires 20ms, and two-phase locks will lock resources for as long as 40ms, so the TPS of transactions on hot lines will be reduced to about 25 seconds, while in non-cloud environments, it usually takes only a few milliseconds to lock hot data at a time, so the time for locking hot data is relatively low).

However, in terms of BASE flexible transactions, the SPI provided by ShardingSphere to access distributed transactions is only suitable for services with high performance requirements and low consistency requirements.

The AT schema at the core of Seata is suitable for building relational databases that support local ACID transactions. Through the integration of Seata, its AT mode realizes the support of RC isolation level through the global lock of TC on the basis of one-phase commit + compensation, which can improve the consistency of ShardingSphere distributed transactions.

Integration scheme

When integrating Seata AT transactions, it is necessary to integrate the TM,RM,TC model into the SPI ecology of ShardingSphere distributed transactions. On the database resources, Seata connects with DataSource interface, so that JDBC operation can communicate with TC on RPC. Similarly, ShardingSphere aggregates the physical DataSource configured by the user for the DataSource interface, so after the physical DataSource is re-packaged as the DataSource of Seata, the Seata AT transaction can be integrated into the fragmentation of ShardingSphere.

In the Seata model, the context of the global transaction is stored in the thread variable. By extending the transport between services, the thread variable can be transferred, and the branch transaction determines whether it is added to the whole Seata global transaction by the thread variable. The sharding execution engine of ShardingSphere usually executes according to multi-thread, so when integrating Seata AT transactions, it is necessary to extend the transaction context transfer between main thread and child thread, which is exactly the same as the idea of context transfer between services.

Quick Start

ShardingSphere has implemented base-seata-raw-jdbc-example, so you can try it on your own:

Https://github.com/apache/incubator-shardingsphere-example/tree/dev/sharding-jdbc-example/transaction-example/transaction-base-seata-example/transaction-base-seata-raw-jdbc-example

Operation manual:

1. Follow the steps in seata-work-shop to download and start seata server.

Https://github.com/seata/seata-workshop

Refer to Step6 and Step7.

2. Execute the resources/sql/undo_log.sql script in each sharded database instance to create the undo_log table

3 、 Run YamlConfigurationTransactionExample.java

About ShardingSphere

ShardingSphere is an ecological circle of open source distributed database middleware solutions, which is composed of Sharding-JDBC, Sharding-Proxy and Sharding-Sidecar (planned). It provides standardized data sharding, distributed transaction and database governance functions, and can be applied to a variety of application scenarios, such as Java isomorphism, heterogeneous languages, containers, cloud native, and so on. Currently, there are more than 8000 Star,57 bits of Contributors.

About Seata

Seata is a distributed transaction middleware jointly opened by Alibaba and Ant Financial Services Group, which integrates the accumulation of distributed transaction technology and precipitates rich practical experience in new retail, cloud computing and new finance scenarios to solve distributed transaction problems in micro-service scenarios in an efficient and business-intrusive way. Currently, there are more than 9900 Star,83 bits of Contributors.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report