High availability is the reliability foundation of distributed databases. OceanBase Database adopts a shared-nothing distributed architecture, where data is stored as multiple replicas across multiple nodes. Data consistency among replicas is ensured through a multi-Paxos-based distributed consensus protocol. When a node fails, such as a crash, the system can automatically elect a new leader replica to continue providing services without manual intervention, achieving disaster recovery capabilities with RPO=0 and RTO<8 seconds.
This topic covers the following experiences:
- Understand the high availability architecture: Understand core concepts such as zones, replicas, log streams, leader and follower replicas, and the Paxos majority.
- Observe replica and leader distribution: View the locations, roles, and synchronization status of log stream replicas through system views.
- Simulate process exceptions: Forcefully terminate an observer process and observe the change in service availability.
- Experience service recovery with zero data loss: Restart the process to restore service and verify that the data remains completely consistent before and after the failure.
Note
This topic is based on OceanBase Database V5.0.1 (Community Edition). The commands and feature descriptions in this topic apply to V5.0.1. This topic uses a single-node environment deployed with the All-in-One package in Deploy OceanBase as an example. In a single-node cluster, each tenant has a single replica (each log stream has only one replica), so this topic covers "observing replica and leader distribution + simulating a process exception + service recovery". The automatic leader switchover capability of a multi-replica cluster requires at least a three-node cluster; its behavior is described in the Failover in a multi-replica cluster section. You can also follow Deploy OceanBase Database in a production environment using the command line to deploy a multi-node cluster for a deeper experience.
Prerequisites
Before you proceed, ensure the following conditions are met:
Item |
Description |
|---|---|
| OceanBase Database | The deployment has been completed with the All-in-One package and started successfully. The deployment name is demo. For more information, see Deploy OceanBase. |
| Server resources | We recommend that you have at least four CPU cores and 16 GB of memory. |
| Access to the sys tenant | You can log in to the sys tenant of the cluster as the root user to perform management operations. The password for the root user of the sys tenant is randomly generated during deployment and is printed in the deployment output; you can also run obd cluster display demo to view it. |
| obclient | obclient is installed and can connect to OceanBase Database normally. It is installed automatically when you deploy with the All-in-One package. |
| Multi-tenancy basics (optional) | This topic creates a tenant for the experience. For information about tenants and resource pools, see Experience multi-tenancy and resource isolation. |
Overview of the high availability architecture
The architecture and implementation of OceanBase Database ensure strong data consistency, integrity, and high availability. Understanding the following core concepts will help you get started with the experiences in this topic:
Concept |
Description |
|---|---|
| Cluster and Zone | An OceanBase cluster consists of multiple zones. A zone is composed of multiple physical servers, each called a data node (or OBServer node). Multiple replicas of a partition (or log stream) are distributed across different zones, enabling server-level, data center-level, and even regional disaster recovery capabilities. |
| Replica | Copies of the same data on different nodes. OceanBase Database leverages the multi-replica architecture based on the Paxos protocol as the foundation for its high availability capabilities, ensuring lossless database service is still provided even when a minority of replicas fail. |
| Log Stream (LS) | An entity automatically created and managed by OceanBase Database, representing a collection of data. It includes several data partitions, as well as the logs and transaction management structures for performing transactional operations on them. Each log stream and its replicas form an independent Paxos group. |
| Primary Replica (Leader)/Secondary Replica (Follower) | Among multiple replicas, only one replica accepts write operations and is called the leader replica, while the others are called follower replicas. The leader replica provides strongly consistent read and write services, while the follower replicas provide weakly consistent read services. If the leader replica fails, a follower replica can quickly switch to become the new leader. |
| Paxos | During transaction commit, logs must be successfully persisted on a majority of replicas. If any minority of replicas fail, data is not lost and service does not stop, as the system can always automatically select new replicas to serve as the primary replica and continue providing service. |
| Primary Zone | A tenant-level parameter that specifies the zone where leaders are preferentially distributed. The election service's priority mechanism considers factors such as the primary zone and the abnormal status of servers to select a better replica as the leader. |
In OceanBase Database, user read and write requests are served by the leader replica of a log stream. All modifications generate logs, which are synchronized to other follower replicas via the Multi-Paxos protocol. If the node hosting the leader fails, a follower is elected as the new leader to continue serving requests. The election service is the cornerstone of high availability: in V4.x, the election service operates at the log stream granularity and no longer relies on external clock synchronization services like NTP. Instead, it ensures consistency through local clocks and an improved lease mechanism.
Note
Depending on the deployment mode, OceanBase can achieve lossless disaster recovery at the server, zone, or region level. For more information, see Overview of High Availability Architecture.
View replica and leader distribution
Log streams have location information (the nodes on which they are distributed) and role information (LEADER or FOLLOWER). This section shows how to view the distribution of log stream replicas for all tenants in a cluster from the sys tenant through system views.
Procedure
Log in to the sys tenant of the cluster as the root user (the password is randomly generated during deployment; for retrieval, see the prerequisites above):
obclient -h127.0.0.1 -uroot@sys -P2881 -p -A oceanbaseView the distribution of log stream replicas for all tenants through the
CDB_OB_LS_LOCATIONSview:obclient [oceanbase]> SELECT TENANT_ID, LS_ID, SVR_IP, ZONE, ROLE, PAXOS_REPLICA_NUMBER, REPLICA_TYPE FROM oceanbase.CDB_OB_LS_LOCATIONS;A sample return result is as follows (the example environment already has a user tenant named
ha_tenantwith tables in it, and the actual tenant IDs vary with the creation order. If you have just finished the deployment and have not created any user tenant or business tables yet, fewer rows are returned here, which is normal):+-----------+-------+-----------+-------+--------+----------------------+--------------+ | TENANT_ID | LS_ID | SVR_IP | ZONE | ROLE | PAXOS_REPLICA_NUMBER | REPLICA_TYPE | +-----------+-------+-----------+-------+--------+----------------------+--------------+ | 1 | 1 | 127.0.0.1 | zone1 | LEADER | 1 | FULL | | 1001 | 1 | 127.0.0.1 | zone1 | LEADER | 1 | FULL | | 1002 | 1 | 127.0.0.1 | zone1 | LEADER | 1 | FULL | | 1002 | 1001 | 127.0.0.1 | zone1 | LEADER | 1 | FULL | +-----------+-------+-----------+-------+--------+----------------------+--------------+ 4 rows in setThe key fields are described as follows:
FieldResult interpretationTENANT_IDTenant ID. 1is the sys tenant. Each user tenant is accompanied by a Meta tenant (an internal system tenant used to store and manage the tenant's own metadata, not directly accessible by users), which can be identified by tenant names starting withMETA$in theDBA_OB_TENANTSview. In the example,1001is the Meta tenant and1002is the user tenantha_tenant.LS_IDLog stream ID. Each tenant has a system log stream numbered 1. User tenants do not have a user log stream immediately after creation. After a user table is created in a tenant, the system automatically creates user log streams numbered1001and later. Business data is stored on these user log streams (in the example, log stream1001for tenant1002appears after its table is created).SVR_IP/ZONENode and zone where the replica resides. In a single-node cluster, all replicas are located on the same node and in the same zone. ROLEReplica role, always LEADER: a single-replica log stream has no followers; its sole replica is the leader.PAXOS_REPLICA_NUMBERNumber of Paxos replicas, always 1. In a multi-replica cluster, this value is typically3(or5). In this case, the same log stream is represented by multiple rows across different nodes and zones, with only one row havingROLEasLEADER.REPLICA_TYPEReplica type. FULLindicates a full-featured replica, possessing complete data and functionality including RedoLog, MemTable, and SSTable. It is a required replica.View the role and synchronization status of log streams through the
V$OB_LOG_STATview:obclient [oceanbase]> SELECT TENANT_ID, LS_ID, SVR_IP, SVR_PORT, ROLE, PAXOS_REPLICA_NUM, IN_SYNC FROM oceanbase.V$OB_LOG_STAT;When you query this view in the sys tenant, it displays the status of the log streams of all tenants. A sample return result is as follows:
+-----------+-------+-----------+----------+--------+-------------------+----------+ | TENANT_ID | LS_ID | SVR_IP | SVR_PORT | ROLE | PAXOS_REPLICA_NUM | IN_SYNC | +-----------+-------+-----------+----------+--------+-------------------+----------+ | 1 | 1 | 127.0.0.1 | 2882 | LEADER | 1 | YES | | 1001 | 1 | 127.0.0.1 | 2882 | LEADER | 1 | YES | | 1002 | 1 | 127.0.0.1 | 2882 | LEADER | 1 | YES | | 1002 | 1001 | 127.0.0.1 | 2882 | LEADER | 1 | YES | +-----------+-------+-----------+----------+--------+-------------------+----------+ 4 rows in setThe
V$OB_LOG_STATview shows the status of the log stream Palf (the Paxos-based logging module). It is commonly used to check whether a log stream has a leader, its member list, and the replica synchronization status. In the results, ifROLEisLEADER, it indicates that the replica is the primary replica for the log stream; ifIN_SYNCisYES, it indicates that the replica is fully synchronized with the leader.
Note
In a multi-replica cluster, the above two views will output multiple rows for the same log stream (one row per replica): the MEMBER_LIST field in CDB_OB_LS_LOCATIONS displays the member list, and the PAXOS_MEMBER_LIST field in V$OB_LOG_STAT displays the Paxos member list. Among the multiple rows, only one row has ROLE as LEADER, and the rest are FOLLOWER. You can view the replica distribution from the perspective of the current tenant through the tenant's own DBA_OB_LS_LOCATIONS view (without the CDB prefix). For more information, see DBA_OB_LS_LOCATIONS and V$OB_LOG_STAT.
Simulate a process exception and observe service recovery
This section simulates a scenario where an observer process crashes abnormally (for example, when it is forcibly terminated by the operating system), observes the change in service availability, then restarts the process to restore service and verifies data consistency before and after the failure.
Procedure
Create an experience tenant and prepare verification data. Execute the following command in the sys tenant to create the tenant
ha_tenant(for detailed information about tenants and resource pools, see Experience multi-tenancy and resource isolation). If you already have a business tenant, you can use it directly:obclient [oceanbase]> CREATE RESOURCE UNIT ha_unit MAX_CPU=1, MIN_CPU=1, MEMORY_SIZE='2G'; obclient [oceanbase]> CREATE RESOURCE POOL ha_pool UNIT='ha_unit', UNIT_NUM=1, ZONE_LIST=('zone1'); obclient [oceanbase]> CREATE TENANT IF NOT EXISTS ha_tenant CHARSET='utf8mb4', PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('ha_pool') SET ob_tcp_invited_nodes='%';Log in to
ha_tenantas the root user (the default password for the root user of a newly created tenant is empty, so press Enter when prompted), then create a test table and write data:obclient -h127.0.0.1 -uroot@ha_tenant -P2881 -p -A testobclient [test]> CREATE TABLE ha_demo_order (id INT PRIMARY KEY, item VARCHAR(50), amount DECIMAL(10,2)); Query OK, 0 rows affected obclient [test]> INSERT INTO ha_demo_order VALUES (1, 'keyboard', 149.00), (2, 'mouse', 79.00), (3, 'monitor', 999.00); Query OK, 3 rows affected obclient [test]> SELECT COUNT(*) FROM ha_demo_order; +----------+ | COUNT(*) | +----------+ | 3 | +----------+ 1 row in setRecord the current row count
3as the baseline before the failure. Keep the current obclient session open, because you will observe what happens to it during the failure later on.Open a new terminal, locate the observer process, and forcibly terminate it to simulate an abnormal process crash:
# Find the observer process. ps -ef | grep observer | grep -v grep # Forcefully terminate the observer process (PID is based on the result of the previous query). kill -9 <PID>Back in the
ha_tenantsession, execute the query again:obclient [test]> SELECT COUNT(*) FROM ha_demo_order; ERROR 2013 (HY000): Lost connection to MySQL server during query No connection. Trying to reconnect... ERROR 2002 (HY000): Can't connect to OceanBase server on '127.0.0.1' (115)The connection is interrupted: the client's automatic reconnection attempt fails and the service becomes unavailable. A new connection attempt also fails:
obclient -h127.0.0.1 -uroot@ha_tenant -P2881 -p -A test ERROR 2002 (HY000): Can't connect to OceanBase server on '127.0.0.1' (115)After the unique node in a single-replica cluster fails, no other replicas can take over the service, and the service remains unavailable until the process is restarted.
Note
The error message may vary slightly depending on the client version and connection method. For example, in some environments, it may display ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:2881' (111). Regardless of the specific error, the core phenomenon is consistent: existing connections are disconnected and new connections cannot be established, indicating the service is currently unavailable.
In the terminal, restart the cluster (
obd demodeploys clusters with the fixed namedemo; if the cluster is not managed by obd, restart the observer process using the startup command recorded during deployment):obd cluster restart demoWait for the command to complete and all component statuses to change to
running.Back in the
ha_tenantsession, execute the query again. The client will automatically reconnect and return the results:obclient [test]> SELECT COUNT(*) FROM ha_demo_order; No connection. Trying to reconnect... Connection id: 3221700101 Current database: test +----------+ | COUNT(*) | +----------+ | 3 | +----------+ 1 row in setThe query returns normally, with the same number of rows as before the failure, indicating zero data loss. The
Connection idin the output is the connection ID of the new session after reconnection (the value varies by environment), andCurrent databaseindicates that the original database context is still maintained. This is because, in single-replica mode, a transaction commit is only successful after Redo logs are persisted to disk; an abnormal process crash does not result in any lost committed transactions.
Note
kill -9is used only for the demonstration scenario in this topic. Directly killing the observer process is strictly prohibited in production environments. For maintenance operations in production environments, see the O&M management chapter of the official OceanBase Database documentation.- The process recovery time depends on the cluster startup duration (including procedures such as Redo log replay). From executing
obd cluster restartto service recovery usually takes less than a minute. In this topic, where the process is restarted directly, service recovery took about 15 seconds from process startup. Be patient during recovery; there is no need to run the restart command repeatedly. - To observe the status of recovered replicas, after service recovers, you can rerun the view queries from the Observe replica and leader distribution section of this topic to confirm that each log stream's
ROLEhas recovered toLEADERandIN_SYNCisYES.
Interpretation
Observation |
Expected behavior |
Description |
|---|---|---|
| Existing sessions during the failure | Executing SQL returns ERROR 2013 and the connection is interrupted. |
The service process crashed and all connections were closed. |
| New connections during the failure | The connection fails (for example, ERROR 2002 / ERROR 2003). |
The only node is unavailable and no replica can take over. |
| Service after recovery | obclient reconnects automatically and the query returns normally. | After the process is restarted, the log stream resumes service. |
| Data after recovery | The number of rows is consistent with the baseline before the failure, with zero data loss. | The redo logs of the committed transactions have been persisted. Data will be fully restored after a restart. |
Failover in a multi-replica cluster
In the single-node environment described in this topic, services are interrupted when a node fails and require manual recovery. However, in a typical three-replica cluster in a production environment (where one OBServer node is deployed in each of three zones), the behavior is completely different when a node fails:
Comparison |
Single-replica cluster (this example) |
Three-replica cluster (multi-node deployment) |
|---|---|---|
| Service on node failure | Interrupted | Continues without interruption, with automatic lossless switchover |
| Recovery method | Run obd cluster restart manually. |
A new leader is elected automatically to continue serving requests. |
| Recovery metrics | Depends on how quickly you intervene manually | RPO=0 (zero data loss), RTO<8 seconds |
| Data loss | Committed data is not lost. | Committed data is not lost (majority persistence). |
In a three-replica cluster, the three replicas of each log stream are distributed across different nodes in three zones, forming a Paxos group. At any given time, only one leader provides read and write services. When the node hosting the leader fails:
- The remaining two replicas form a majority, ensuring no data loss and that majority logs can still be committed.
- The election service quickly elects a new leader from the remaining replicas (triggered after a lease expires, typically completed within seconds).
- Subsequent business requests are routed to the new leader, and services automatically recover without manual intervention.
- After the failed node recovers and rejoins the cluster, Root Service automatically replenishes the missing replicas, restoring the three-replica state.
Note
To experience automatic failover in a multi-replica cluster, you can deploy a three-node cluster by following Deploy OceanBase Database in a production environment using the command line. Then, shut down any one node and observe the migration of leaders in the CDB_OB_LS_LOCATIONS view and the automatic recovery of business connections.
Next steps
After you complete the experiences in this topic, you can explore the following:
- Experience horizontal scaling and elastic scaling: Explore the scaling capabilities at the compute, storage, and tenant resource levels. Observe resource changes and business capacity impacts before and after scaling. For more information, see Experience horizontal scaling and elastic scaling.
- Experience parallel import and high compression: Use the parallel import capability to complete large-scale data ingestion and compare storage usage before and after compression. For more information, see Experience parallel import and high compression.
- Deepen understanding of multi-tenancy and resource isolation: Create mutually isolated tenants for different businesses within a cluster. For more information, see Experience multi-tenancy and resource isolation.
References
- For detailed information on the high availability architecture, Multi-Paxos protocol, and election service, see Overview of high availability architecture.
- For detailed information on replica concepts and replica types (full-featured/read-only), see Replica overview.
- For the relationship between partitions, shards, log streams, and replicas, see Log stream and replica overview.
- For descriptions of the views for viewing log stream replica distribution, see DBA_OB_LS_LOCATIONS and CDB_OB_LS_LOCATIONS.
- For descriptions of the views for viewing log stream roles and synchronization status, see V$OB_LOG_STAT.
- For deployment methods of multi-node clusters, see Deploy OceanBase Database in a production environment using the command line.