The logical data center (LDC) routing mechanism can resolve the problem of remote routing latency in the deployment mode of multiple IDCs across multiple regions for a distributed relational database.
As a typical high-availability distributed relational database system, OceanBase Database uses the Paxos protocol for log synchronization. OceanBase Database natively supports multi-region and multi-IDC deployment to ensure high disaster tolerance and reliability. However, every database deployed across multiple regions and IDCs has a latency issue caused by routing.
LDC routing is designed to resolve this problem. To use LDC routing, you must specify the region and IDC for each zone in an OceanBase cluster and specify the IDC name for OceanBase Database Proxy (ODP, also known as OBProxy). When ODP receives a data access request, it routes and forwards the request based on the following priority order:
Select a replica that is in the same IDC and that is not undergoing a major compaction.
Select a replica that is in an IDC in the same region and that is not undergoing a major compaction.
Select a replica that is in the same IDC and that is undergoing a major compaction.
Select a replica that is in an IDC in the same region and that is undergoing a major compaction.
Randomly select a replica that is in an IDC in a different region and that is not undergoing a major compaction.
Randomly select a replica that is in an IDC in a different region and that is undergoing a major compaction.
To enable LDC routing, perform the three following steps:
Configure LDC settings for your OceanBase cluster.
Configure LDC settings for ODP.
Configure weak consistency read for the application.
Note
If you do not configure LDC settings, weak consistency read requests sent to a database deployed across different regions and IDCs are evenly distributed to all the replicas, including the leader and the followers. When a request accesses a replica in a remote IDC, the system response time significantly increases.
Configure LDC settings for your OceanBase cluster
Log on to the SYS tenant as the root user from a client tool supported by OceanBase Database.
Execute the following statements to configure LDC settings:
obclient> ALTER SYSTEM MODIFY zone "z1" SET region = "SHANGHAI"; obclient> ALTER SYSTEM MODIFY zone "z1" SET idc = "zue";The parameters in the syntax are described as follows:
region: the region in which the zone is located. Generally, you need to set the value to a city name. This parameter is case-sensitive.idc: the physical IDC in the zone. Generally, you need to set the value to the IDC name in lowercase.zone: 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.
Execute the following statement to check whether the LDC settings have taken effect on the OBServer node.
To be specific, check whether the region, zone type, and IDC displayed in the returned result are correct.
obclient> SELECT * FROM oceanbase.DBA_OB_ZONES;
Configure LDC settings for ODP
You can configure an LDC for ODP in one of the two following ways. In this example, "zue" is the IDC name.
You can specify the parameters when you start an obproxy process. We recommend that you use this method. Here is an example:
cd /opt/taobao/install/obproxy-1.5.5 ./bin/obproxy -o proxy_idc_name=zueExecute the
ALTERstatement on a supported client tool to modify the ODP settings. Here is an example:obclient> ALTER PROXYCONFIG SET proxy_idc_name= 'zue';
In this example, after you configure LDC for ODP, if an application is deployed in the zue IDC in Shanghai, after an application sends a weak consistency read request, the request is sent to the IDC in Shanghai.
You can execute the following statement to check whether the LDC settings have taken effect for ODP:
obclient> SHOW PROXYINFO IDC;
The return result is as follows:

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