Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Transaction Models

Updated on 2023-01-13 GMT+08:00

Tables in each DDM instance are usually sharded, so data in the tables may be distributed across different database shards in multiple RDS instances. In DDM, one transaction to add, delete, update, or query a logical table is possibly executed on different database shards in multiple RDS instances, so a series of operations on data tables in one shard of an RDS instance can be deemed as a local transaction. Therefore, one DDM transaction is actually a distributed transaction that consists of local transactions on multiple RDS instances. These local transactions either all succeed, or all fail.

Implementation of Distributed Transactions in DDM

DDM executes 2PC distributed transactions based on the MySQL XA protocol, and these transactions can guarantee strong write consistency. For more information about the consistency, see the MySQL official documentation.

In a distributed system, each participant knows whether their operation succeeds or fails, but cannot know the status of the operation on other nodes. If a transaction encompasses multiple nodes, to guarantee atomicity and consistency of a transaction, a coordinator is introduced to control operation results of all participants so that all of the transaction's changes either take effect or do not. The DDM node acts as a coordinator in the distributed transaction, and RDS instances are participants.

The two-phase commit protocol breaks a database commit into two phases:

  1. Prepare phase: Participants notify the coordinator of the operation result. If the participants give a response that they are prepared, they must reserve the required resources before the coordinator makes a decision.
  2. Commit phase: After receiving a notification from the participants, the coordinator sends a notification to the participants again and determines whether the participant needs to commit or roll back the operation based on their response.

For example:

Four people A, B, C, and D want to have a dinner party, so they need to determine the time. Now assume that A is the coordinator and B, C, and D are participants.

Prepare phase:

  1. A sends a text message to B, C, and D, asking them whether they are available on Tuesday noon.
  2. D replies yes.
  3. B replies yes.
  4. C does not reply for a long time. The time is not determined, so A, B, C, and D cannot continue their dinner party.
  5. C replies yes or no.

Commit phase:

  1. Coordinator A sends the collected results (Tuesday dinner party) to B, C, and D. What the result is and when does A feed it back to the other three depends on the time when C replies.
  2. B received.
  3. C received.
  4. D received.
  5. If any of them does not receive the result, A continues to send it until all of them receive the result.

2-Phase Commit

When DDM processes a transaction, applications run BEGIN/COMMIT as they do on a common transaction, without worrying about whether there are distributed transactions at the underlying layer. DDM automatically processes distributed transactions using the two-phase commit (2PC) protocol. If a transaction involves only one data shard, DDM will process it using the one-phase commit protocol. The one-phase commit protocol will not be described in detail here.

Figure 1 Flowchart for executing a distributed transaction

XID is the global unique serial number of each distributed transaction. It consists of the transaction serial number, node ID, and timestamp. The XID and the corresponding shard name together constitute the XA_ID that initiates a distributed transaction on a physical database.

Suggestions for Using Transactions

  • DDM supports distributed transactions. If all SQL statements in a transaction use the same sharding key, DDM can process the transaction as a single-shard transaction to achieve optimal performance.
  • DDM uses the 2PC protocol to process distributed transactions. RDS deadlock detection does not take effect for distributed transactions across RDS instances. If a lock wait times out, there may be a cross-shard deadlock. In this case, check your business model.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback