Unveiling the Core Distributed Transaction Processing Technology of GBase 8c: The 2PC Protocol
GBase 8c employs the 2PC protocol to deliver strongly consistent transactions across distributed systems, meeting the stringent requirements of the financial industry. For performance-driven emerging businesses, it also supports optional eventual consistency.
Distributed Transaction Atomicity and Two-Phase Commit Protocol
To guarantee the atomicity of distributed transactions and prevent “in-doubt” transactions where some participants commit while others roll back, GBase 8c adopts the 2PC protocol for cross-node distributed transactions.
2PC, short for Two-Phase Commit, divides the commit process into two phases: the Prepare phase and the Commit phase. In a distributed transaction, two entities are involved: a Coordinator that accepts application requests and a Participant that executes the Coordinator’s commands and persists the data. With the 2PC protocol, the Coordinator and Participants work together to realize the ACID properties of the transaction.
Phase 1 – Prepare phase: The Coordinator sends a Prepare message to all Participants, instructing each of them to write all required information and resources to disk and complete the persistent storage, but the transaction is not yet committed.
Phase 2 – Commit phase: The Coordinator tells the Participants to either commit or roll back. If the Coordinator receives a failure or timeout message from any Participant during the Prepare phase, it sends a Rollback message to all Participants; otherwise, it sends a Commit message. Each Participant then executes the commit or rollback according to the Coordinator’s instruction and releases the locks held during the transaction.
Once the Prepare phase succeeds, all the information needed for the commit has been durably written to disk. Even if a Participant fails later during the Commit phase, it can recover from the persisted information and retry the commit until it succeeds. Ultimately, the distributed transaction will reach the same state on all Participants: either all commit or all roll back. Therefore, to the application, the state change of the transaction is atomic.
2PC Transaction State Persistence
Traditional 2PC transactions may fail during the global commit phase – for example, when the Coordinator crashes – leading to inconsistent commit states across cluster nodes and breaking atomicity. Moreover, a 2PC transaction continues to hold the locks it has acquired, which may block other transactions and, in severe cases, cause the entire cluster to halt. Hence, it is essential to detect such in-progress transactions and promptly drive the 2PC to completion (commit or rollback).
To address this issue, GBase 8c optimizes the 2PC workflow and introduces a transaction state persistence mechanism to ensure the cluster can continue serving without interruption.
As illustrated, when the Coordinator crashes, the system immediately detects the failure and automatically elects a healthy Coordinator, which then takes over all outstanding 2PC transactions from the failed Coordinator.
The new Coordinator collects all unresolved 2PC transactions, checks the phase each one is in, decides whether each should be committed or rolled back, and sends the corresponding instruction to the Participants. This completes all 2PC flows and prevents the system from being blocked.
Summary
In summary, GBase 8c uses two-phase commit to implement distributed transactions, ensuring atomicity, consistency, isolation, and durability across all cross-node transactions. The two-phase commit guarantees that a distributed transaction is either fully committed on all nodes or fully rolled back – never partially committed.
For successfully committed distributed transactions, GBase 8c ensures that the same result can be obtained from any node, delivering strong consistency for distributed transactions.
About GBase 8c
GBase 8c is a multi-model, multi-mode distributed database that supports row-store, column-store, and in-memory storage models as well as standalone, primary-standby, and distributed deployment topologies, allowing flexible adaptation to OLTP, OLAP, and extreme-performance scenarios. GBase 8c delivers high performance, high availability, elastic scaling, and strong security, and can be deployed on physical machines, virtual machines, containers, private clouds, and public clouds. It provides secure, stable, and reliable data storage and management services for core systems in critical industries, Internet-based business systems, and government/enterprise applications. Additionally, GBase 8c supports disaster recovery solutions such as intra-city active-active and two-site-three-center architectures, has no single point of failure, and achieves up to 99.999% availability. With key capabilities like global lock manager and transaction state persistence, the database can self-heal in the event of system anomalies. Its elastic scaling capability flexibly handles performance surges under extreme scenarios, and its grayscale deployment capability ensures smooth service rollouts and rollbacks for applications.