tencent cloud

TDSQL for MySQL

Announcements
Alarm Upgrade
Product Introduction
Overview
Strengths
Use Cases
Regions and AZs
InnoDB engine
Purchase Guide
Billing Overview (InnoDB)
Product Pricing (InnoDB)
Purchase and Upgrade
Refund
Payment Overdue
Backup Space Billing
Getting Started
InnoDB Engine
Operation Guide(InnoDB)
Instance Management
Disaster Recovery Read-Only Instance
Changing Networks
Account Management
Security Management
Slow Query Analysis
Backup and Rollback
Data Migration
Database Audit
Practical Tutorial
Import from Standalone Instance to TDSQL Instance
Import Between TDSQL Instances
Selection of TDSQL Instance and Shard Configuration
Security White Paper
Platform Security Design
Tenant Security Features
Development Guide
InnoDB
API Documentation
History
Introduction
API Category
Security Group APIs
Other APIs
Making API Requests
TDSQL APIs
Data Types
Error Codes
FAQs
InnoDB
General References
Performance Comparison Data for Strong Sync
Glossary
Contact Us

Distributed Transaction

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2024-01-06 17:34:55
In TDSQL for MySQL, a transaction usually involves data of multiple physical nodes. Such transactions are called distributed transactions. TDSQL supports XA and non-XA distributed transaction protocols. By default, TDSQL (kernel version 5.7 or later) supports distributed transactions which are imperceptible to the client and as easy-to-use as non-distributed transactions. Distributed transactions in TDSQL adopt a two-phase commit protocol (2PC) to ensure the atomicity and consistency of transactions, and support such isolation levels as Read committed, Repeatable read, and Serializable.

Non-XA Distributed Transactions

begin; # Start a transaction
... # Cross-set INSERT, DELETE, UPDATE, SELECT, and other non-DDL operations
commit; # Commit the transaction

XA Distributed Transactions

XA distributed transactions refer to cross-instance transactions.
xa begin ''; # Start an XA transaction. The transaction identifier is generated by the system, so you can pass in an empty string.
... # Cross-set INSERT, DELETE, UPDATE, SELECT, and other non-DDL operations
select gtid(); # Get the XA transaction identifier, which is assumed as 'xid' in the following statements
xa prepare 'xid'; # Prepare the transaction
xa commit/rollback 'xid'; # Commit or roll back the transaction

New Transactions APIs

select gtid(): this API is used to get the globally unique identifier of the distributed transaction. If no value is returned, the transaction is not a distributed transaction.
The format of non-XA distributed transaction identifier is: 'Gateway ID' - 'Proxy random value' - 'Serial number' - 'Timestamp' - 'Partition number', such as c46535fe-b6-dd-595db6b8-25.
The format of XA distributed transaction identifier is: 'ex' - 'Gateway ID' - 'Proxy random value' - 'Serial number' - 'Timestamp' - 'Partition number', such as ex-c46535fe-b6-dd-595db6b8-25.
select gtid_state("Globally unique identifier of the distributed transaction"): this API is used to get the transaction status (in 3 seconds by default) after an exception occurs in committing the transaction. The following status may be returned:
COMMIT: indicates that the transaction has been or is going to be committed.
ABORT: indicates that the transaction is going to be rolled back.
Empty value: the transaction status will be cleared after an hour, so there are two possibilities:
For a query after an hour, it indicates that the transaction status has been cleared.
For a query within an hour, it indicates that the transaction is going to be rolled back.
xa boost 'Globally unique identifier of the distributed transaction' : after an exception occurs in committing a non-XA transaction, the transaction will be automatically committed or rolled back by the backend component in a certain period of time (30 seconds by default). If you are unwilling to wait for such a long time, you can repeatedly call this API to make the system commit or roll back the transaction in a timely manner. This API will return the status of the transaction (i.e., committed or rolled-back).
xa lockwait: this API is used to show the wait-for relationship between the distributed transactions. You can convert it to a graph using the dot tool.
xa show: this API is used to show transactions that are active on the proxy.

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan