This topic describes the concept and use of the standby cluster read service.
Overview
The full-featured replica or read-only replica of each partition in a standby cluster replays REDO logs in real time and hosts the read service. OceanBase Database provides intra-partition and inter-partition consistency reads and ensures that the read result is a snapshot, to ensure transaction consistency.
The replay progress varies by partition or replica. Therefore, the data read later can be older than the previously read data in default configurations. To resolve this problem, OceanBase Database allows you to specify whether to enable monotonic read. After monotonic read is enabled, tenant-specific monotonically increasing versions of readable data are maintained. In each read operation, the globally latest readable data is obtained as a snapshot, ensuring that the data read later is newer than the previously read data.
OceanBase Database supports bounded staleness consistency reads to ensure that the read data is out-of-sync with the latest data of the primary cluster by less than a specific period of time, for example, 5s by default. If data in a standby cluster is out-of-sync with the latest data of the primary cluster by a period of time exceeding the specified threshold, the read operation will retry and wait until timeout or until the data in the standby cluster is updated to the latest data of the primary cluster.
Configure weak-consistency reads for a user of a standby cluster
A common tenant of a standby cluster supports only weak-consistency reads. If a strong consistency read, write, or DDL operation is initiated for a common tenant, an error will be reported.
You can enable weak-consistency reads for a common tenant of a standby cluster in two ways:
Log on to the common tenant of the standby cluster and set
ob_read_consistencytoWEAKfor the current session.obclient> SET ob_read_consistency = WEAK;Notice
As a global system variable,
ob_read_consistencycan be set only in the primary cluster.This setting applies only to the current session. By default, after the setting takes effect, subsequent reads in the session are weak-consistency reads.
Specify a hint in an SQL statement
Run the following command to set the read consistency to
WEAK. This setting takes precedence overob_read_consistency:obclient> SELECT /*+READ_CONSISTENCY(WEAK) */ * FROM t1;
Configure the standby cluster read service for a tenant
You can control the weak-consistency read service by using two tenant-specific configuration items:
enable_monotonic_weak_read: The monotonic read switch. Default value: False.max_stale_time_for_weak_consistency: The maximum period of time by which the data obtained through a weak consistency read is out-of-sync with the latest data. It is a configuration item for bounded staleness consistency reads. Default value: 5s.
To configure the standby cluster read service, perform the following operations:
Log on to the system tenant of the standby cluster and modify the configuration items of a specific tenant or all tenants.
Enable monotonic read for all tenants or a specific tenant
obclient> ALTER SYSTEM SET enable_monotonic_weak_read = true TENANT = [ALL|name];Configure bounded staleness consistency read for all tenants or a specific tenant
obclient> ALTER SYSTEM SET max_stale_time_for_weak_consistency = '10s' TENANT = [ALL|name];