This topic describes different types of transaction logs.
Transaction types
Based on the transaction operation type and the distribution of accessed data, transactions can be divided into two types:
- Local transaction: The information about a local transaction is maintained on the same OBServer node as the one that stores data accessed by the transaction. Such a transaction accesses only data in the same partition.
- Distributed transaction: The information about a distributed transaction is maintained on a different node from the one that stores data accessed by the transaction. Such a transaction accesses data in multiple partitions.
Transaction log types
Based on the generation stage of transaction logs, transaction logs can be divided into two types:
- Transaction execution logs
- Transaction commit logs
Transaction execution logs
If the transaction modifications must be persisted when a transaction is executed, a log is generated to persist the modifications of this transaction. Logs of this type are referred to as transaction execution logs. The following table describes different types of transaction execution logs.
| Log type | Internal type value | Description |
|---|---|---|
OB_LOG_MUTATOR |
0x200 | The transaction mutator log, which contains the transaction modifications. |
OB_LOG_TRANS_STATE |
0x400 | The transaction status log. |
OB_LOG_MUTATOR_WITH_STAT |
0x600 | The transaction status log that contains the mutator log. |
OB_LOG_MUTATOR_ABORT |
0x800 | The transaction abort log, which indicates that the transaction has been rolled back. |
Transaction commit logs
After a transaction enters the commit stage, the transaction modifications must be persisted. In this stage, different types of transaction logs are generated based on the transaction type.
The following table describes the types of logs generated when a distributed transaction is committed.
Log type Internal type value Description OB_LOG_TRANS_REDO0x1 The redo log of the distributed transaction, which contains the transaction modifications. OB_LOG_TRANS_PREPARE0x2 The prepare log of the distributed transaction. OB_LOG_TRANS_REDO_WITH_PREPARE0x3 The prepare log that contains the transaction modifications (redo log) of the distributed transaction. OB_LOG_TRANS_COMMIT0x4 The commit log of the distributed transaction, which indicates that the transaction has been committed. OB_LOG_TRANS_ABORT0x8 The abort log of the distributed transaction, which indicates that the transaction has been rolled back. OB_LOG_TRANS_CLEAR0x10 The clear log of the distributed transaction, which is used to release transaction context information. The following table describes the types of logs generated when a local transaction is committed.
Log type Internal type value Description OB_LOG_SP_TRANS_REDO0x20 The redo log of the local transaction, which contains the transaction modifications. OB_LOG_SP_TRANS_COMMIT0x40 The commit log of the local transaction, which indicates that the transaction has been committed. It contains the transaction modifications (redo log). OB_LOG_SP_TRANS_ABORT0x80 The abort log of the local transaction, which indicates that the transaction has been rolled back.
Transaction ID
Transactions on an OBServer node are uniquely identified by transaction IDs. Therefore, transaction IDs must be unique on the same OBServer node. The following example shows the structure of a unique transaction ID:
class ObTransID
{
uint64_t hv_;
common::ObAddr server_;
int64_t inc_;
int64_t timestamp_;
}
The following table describes the fields.
| Field | Description |
|---|---|
server_ |
The IP address of the OBServer node where this transaction belongs. |
inc_ |
The monotonically increasing value on the OBServer node, which is recounted after the OBServer node restarts. |
timestamp_ |
The local physical clock value (Unix timestamp) when the transaction ID is created. |
hv_ |
The hash value obtained based on the preceding three fields. |
Note
OceanBase Database uses 64-bit hash values. Therefore, the hash values of two different transaction IDs seldom conflict. In most cases, hash values can be used to distinguish transactions.