As a typical high-availability distributed relational database, OceanBase Database uses the Paxos protocol for log synchronization. OceanBase Database natively supports multi-region and multi-center deployment to ensure high disaster tolerance and reliability. However, every database deployed across multiple regions and data centers has a latency problem caused by routing.
Logical Data Center (LDC) routing is designed to address this problem. To use LDC routing, you must set a region attribute and an IDC attribute for each zone in a cluster and configure the IDC parameters for OBProxy. After a data request reaches OBProxy, OBProxy routes and forwards the request based on the following order of priority:
Select a replica that is in the same data center and is not undergoing a major compaction.
Select a replica that is in the same region and is not undergoing a major compaction.
Select a replica that is in the same data center and is undergoing a major compaction.
Select a replica that is in the same region and is undergoing a major compaction.
Randomly select a replica that is in a different region and is not undergoing a major compaction.
Randomly select a replica that is in a different region and is undergoing a major compaction.
To configure LDC routing, perform the three following steps:
Complete LDC settings for the OceanBase cluster.
Complete LDC settings for OBProxy.
Configure weak consistency read for applications.
Note
If you do not set the LDC, weak consistency read requests sent to a database deployed across different regions and data centers are distributed evenly to all the replicas, including the leader and the followers. When a request accesses a replica in a remote data center, the system response time increases significantly.
Complete LDC settings for the OceanBase cluster.
Log on to the sys tenant as the root user from OceanBase Client (OBClient).
You can execute the following statements to configure LDC:
obclient> ALTER SYSTEM MODIFY zone "z1" SET region = "SHANGHAI"; obclient> ALTER SYSTEM MODIFY zone "z1" SET idc = "zue";Information about the parameters:
As a general rule, set
regionto the city name. This parameter is case-sensitive.The
idcparameter represents the information about the data center in the zone. As a general rule, set this parameter to the lower-case data center name.The
zoneparameter represents the zone name.An OceanBase cluster has several regions. A region has several zones. A zone has a zone type attribute and an IDC attribute.
You can execute the following statement to verify whether the LDC settings have taken effect for the OBServer.
Verify whether the value of region zone type and IDC in the returned result are correct.
obclient> SELECT* FROM __all_zone;
Configure LDC settings for OBProxy
You can configure LDC settings for OBProxy in one of the two following ways. In the example, "zue" is the data center name.
Set the LDC parameters when the OBProxy process is started. Sample statement:
cd /opt/taobao/install/obproxy-1.5.5 ./bin/obproxy -o proxy_idc_name=zueExecute the
ALTERstatement in OBClient. Sample statement:obclient> ALTER PROXYCONFIG SET proxy_idc_name='zue';In this example, after you configure LDC settings for OBProxy, if an application is deployed in the zue data center in Shanghai, after an application sends a weak consistency read request, the request is primarily sent to the data center in Shanghai.
You can execute the following statement to verify whether the LDC settings have taken effect for the OBProxy.
obclient> SHOW PROXYINFO IDC;Sample response:

Configure weak consistency read for applications
LDC routing only applies to weak consistency read scenarios. You can configure weak consistency read for applications in one of the following three ways:
Use hints in the SQL statement to configure it. Sample statement:
obclient> SELECT /*+read_consistency(weak)*/ * FROM t1;Specify a session variable to configure it. A session variable only applies to the current session. Sample statement:
obclient> SET @@ob_read_consistency='weak';Specify a global variable to configure it. A global variable applies to all the connections to the tenant. Sample statement:
obclient> SET @@global.ob_read_consistency='weak';