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 set a region attribute and an IDC attribute for each zone in a cluster and configure the IDC parameters for OceanBase Database Proxy (ODP). After a data request reaches ODP, ODP routes and forwards the request based on the following order of priority:
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.
Step 1: Configure LDC settings for your OceanBase cluster
Log on to the
systenant 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";Notes:
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 for ODP.
To be specific, check whether the region, zone type, and IDC displayed in the returned result are correct.
obclient> SELECT * FROM oceanbase.__all_zone;
Step 2: Configure LDC settings for ODP
You can configure LDC settings for ODP in one of the following ways. In this example, the sample IDC named zue is used.
Set the LDC parameters when you start the obproxy process. This is the recommended method. Sample code:
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. Sample statement:obclient> ALTER PROXYCONFIG SET proxy_idc_name= 'zue';
Assume that an application is deployed in the zue IDC in Shanghai. After the application sends a weak consistency read request, the request is sent to the zue IDC in Shanghai.
You can execute the following statement to check whether the LDC settings have taken effect for ODP:
obclient> SHOW PROXYINFO IDC;
Sample response:

Step 3: 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. Sample statement:
obclient> SELECT /*+read_consistency(weak)*/ * FROM t1;Specify a session variable. A session variable applies only to the current session. Sample statement:
obclient> SET @@ob_read_consistency='weak';Specify a global variable. A global variable applies to all the connections to the tenant. Sample statement:
obclient> SET @@global.ob_read_consistency='weak';