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. This ensures 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-level 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. By default, the period is 5s. 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 is retried and waits until timeout, or until the data in the standby cluster is updated based on the latest data of the primary cluster.
Configure weak-consistency reads for a user of a standby cluster
A user tenant of a standby cluster supports only weak-consistency reads. If a strong consistency read, write, or DDL operation is initiated for a user tenant, an error is returned.
You can enable weak-consistency reads for a user 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;For more information about the session variable
ob_read_consistency, see ob_read_consistency.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.
Execute the following statement 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
After you configure weak-consistency reads for a user of a standby cluster, you must configure the standby cluster read service for a tenant to control the weak-consistency read service of a standby cluster.
In OceanBase Database, you can manage the weak-consistency read service by using the following two tenant-level parameters:
enable_monotonic_weak_read: The monotonic read switch. Default value: False.For more information about the
enable_monotonic_weak_readparameter, see enable_monotonic_weak_read.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.For more information about the
max_stale_time_for_weak_consistencyparameter, see max_stale_time_for_weak_consistency.
Methods:
Log on to the sys tenant of the standby cluster and modify the parameters 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];