GBase 8c Database Transaction State Preservation: Technical Analysis and Practice – 01 Basic Concepts
In a distributed cluster, a single-node transaction (also known as a single-shard transaction) refers to a transaction in which all operations occur on the same shard (referred to as a DN in GBase 8c). A distributed transaction is a transaction in which two or more shards participate in the execution. For a single-node transaction, the atomicity of write operations and the consistency of read operations are ensured by the DN's own transaction mechanism. For a distributed transaction, additional mechanisms are required to guarantee the atomicity of write operations across different shards and the consistency of read operations across different shards.
Transaction Mechanism
Transactions are one of the most essential and compelling database features for users. Put simply, a transaction is a collection of database operations (such as query, insert, update, or delete) defined by the user. The database internally guarantees the atomicity, consistency, isolation, and durability of this collection as a whole — collectively known as the ACID properties. Here:
A: Atomicity means that all operations in a transaction either succeed completely or fail completely. After a transaction executes, the database can only be in one of these two states. Even if a failure occurs during the execution of these operations, no partial success will be left.
C: Consistency ensures that a transaction moves the data from one consistent state to another consistent state. The transaction will not violate consistency constraints, triggers, or other defined rules.
I: Isolation refers to the degree to which the database state seen during transaction execution is affected by concurrent transactions. According to the severity of this impact, transaction isolation levels are generally categorized into four levels: Read Uncommitted, Read Committed, Repeatable Read, and Serializable (from the most to the least impact by concurrent transactions).
D: Durability means that once a transaction commits, its results will not be lost even if the database crashes and restarts, remaining visible to subsequent transactions.
Single-Node Transaction (Local Transaction)
When a CN node receives a transaction request from the upper-layer application and finds that the data resides on a single local high-availability group (HG), the CN directly requests data from that HG and returns the result. This method bypasses the two-phase commit process, resulting in extremely high processing performance.
Distributed Transaction
GBase 8c's cross-node distributed transactions are implemented through strict two-phase commit (2PC) coordinated by the GTM. When committing data, the CN first sends a prepare state to each DN node. After the DN nodes return a prepare ok state, the CN sends a commit state. Finally, the commit is considered complete only after the DN nodes return a commit ok state.