OceanBase Database enables Global Timestamp Service (GTS) for each tenant. When OceanBase Database commits transactions, it uses GTS of each tenant to retrieve the transaction versions to ensure that the transactions are committed in the order of their versions.
High availability of services
GTS is the core of a cluster and must be highly available.
For user tenants, OceanBase Database takes the leader of the tenant-level internal table "__all_tenant" as the GTS provider. The time comes from the local clock of the leader. GTS contains three replicas by default, so its high availability capability is the same as that of normal tables.
For system tenants, OceanBase takes the leader of "__all_core_table" as the GTS provider. The high availability capability is the same as that of normal tables. The correctness of the timestamp must be ensured.
GTS is globally incremental, which ensures the correctness in exceptions:
Re-election with leader
The original leader proactively initiates the re-election. This is called re-election with a leader. Before a new leader takes effect, it retrieves the last authorized timestamp of the old leader and uses the timestamp as the baseline for its timestamp authorization. Therefore, in this scenario, the timestamp provided by GTS does not roll back.
Election without leader
The original leader is isolated from most followers. After the lease expires, original followers will re-elect the leader. This is called an election without a leader. In the scenario of an election without a leader, the lease of the new leader is different from that of the original leader. Therefore, the local clock value is greater than the maximum timestamp provided by the original leader. The new leader can ensure that the timestamp provided by GTS does not roll back.
GTS retrieval optimization
Retrieval optimization of the statement snapshot
Transactions update the Global Committed Version of the located server when submitting. If the query of a statement only points to one server, the statement directly uses the Global Committed Version of the server, to reduce the request pressure on the global timestamp.
Retrieval optimization of the transaction commit version
Multiple transactions can uniformly obtain the global timestamp. You can send requests to obtain the timestamp in advance to shorten the transaction commit time.