All Products
Search
Document Center

PolarDB:Configure read/write splitting

Last Updated:Dec 11, 2023

This topic describes the endpoints of PolarDB-X instances and how to configure an endpoint. After you configure an endpoint, you can use the read/writing splitting feature.

Background information

If you do not create a read-only instance for a primary instance, you can use only one endpoint to connect to the primary instance. This endpoint is known as a cluster endpoint. A cluster endpoint is used in general scenarios for online business. If read-only instances are created, the read-only instances appear on the Instance List page. On the instance details page of a read-only instance, one read-only routing endpoint is provided to connect to the read-only instance. A read-only routing endpoint ensures that you have exclusive resources in scenarios in which access to resources is isolated, such as batch processing and the export of offline data. If you purchase a primary instance and a read-only instance in scenarios in which hybrid transaction/analytical processing (HTAP) is performed, you can use the cluster endpoint and the read-only routing endpoint. After you configure the cluster endpoint, you can use the read/write splitting feature.

Configure a cluster endpoint and read/write splitting

  1. Log on to the PolarDB for Xscale console.

  2. In the top navigation bar, select the region where your instance is deployed.

  3. On the Instance List page, click the PolarDB-X 2.0 tab.

  4. Click the name of a primary instance. On the page that appears, click Basic Information in the left-side navigation pane.

  5. In the Connection Information section, click Configuration Management to configure the parameters of the cluster endpoint.

    The following table describes the parameters.

    Parameter

    Description

    Resource allocation

    If you have purchased read-only instances, you can add the read-only instances to the resource pool of the primary instance to offload read requests sent to the primary instance. Read-only instances that are not added to the resource pool cannot be used to offload read requests sent to the primary instance.

    Read-only instances are automatically added

    Specifies whether newly purchased read-only instances are added to the resource pool of the primary instance. By default, this feature is enabled.

    Intelligent read-write separation

    By default, this feature is enabled. PolarDB-X automatically routes the traffic generated by analytical processing (AP) to the read-only instances and performs massively parallel processing (MPP). This helps accelerate queries. For more information, see Read/write splitting.

    Read-Only Traffic (%)

    The read queries that need to be routed to the storage nodes of the primary instance are routed to the storage nodes of read-only instances based on the specified percentage. This way, the query data can be stored in the read-only instances.

    Data read consistency

    • Strong consistency: If requests are routed to the read-only instances, the data that is updated on the primary instance before the read requests are performed can be queried. This provides strong external consistency.

    • Weak consistency: If requests are routed to the read-only instances, only the latest data can be read from the read-only instances. Data reads are delayed due to asynchronous replication between your primary and read-only instances.

    Note

    Due to the read latency, data that requires strong consistency can be read only after the data is updated. By default, 3 seconds are consumed to read the data.

    Latency Threshold for Read-Only Instances (s)

    If this threshold is exceeded, read-only requests are sent to other read-only instances in which the read latency does not exceed the threshold. You can also determine whether to send the requests back to the primary instance based on the availability of the read-only instances.

    Read-only Traffic Switched Back to the Primary Instance

    If the read latency in each read-only instance exceeds the threshold or each read-only instance is in the high availability (HA) status, all read-only instances are considered to be unavailable and the system determines whether to send read-only requests back to the primary instance. We recommend that two or more read-only instances be used to improve the availability of read-only instances.

Note
  • After a read-only instance is purchased, the read-only instance is automatically added to the resource pool of the primary instance, and intelligent read/write splitting is automatically enabled. However, read-only traffic generated by transaction processing (TP) is not routed to the read-only instance unless you configure the Read-Only Traffic (%) parameter.

  • A maximum of 3 seconds are required to read data that requires strong consistency. You can change the value of the loose_replica_read_timeout parameter on the Parameter settings page to specify the timeout period that is required to read the data.

  • To use the read/write splitting feature, make sure that the PolarDB-X version is 5.4.13-16415631 or later.

Configure a read-only routing endpoint

  1. Log on to the PolarDB for Xscale console.

  2. In the top navigation bar, select the region where your instance is deployed.

  3. On the Instance List page, click the PolarDB-X 2.0 tab.

  4. Click the name of a read-only instance. On the page that appears, click Basic Information in the left-side navigation pane.

  5. In the Connection Information section, click Configuration Management to configure the parameters of the read-only routing endpoint.

    The following list describes the parameters:

    • Strong consistency: You can use the read-only routing endpoint to query the latest data that is submitted by the primary instance. This ensures the consistency of global data queries. If the replication latency between your primary and read-only instances is large, the queried data cannot be immediately returned.

    • Weak consistency: You can use the read-only routing endpoint to query the latest data of the read-only instance. The queried data can be immediately returned even if replication latency between your primary and read-only instances exists.

FAQ

  • Q: I purchased a read-only instance, but no traffic was routed to the data nodes of the instance. What do I do?

    A: The read-only traffic may be generated by TP. After you purchase the read-only instance, configure the Read-Only Traffic (%) parameter when you configure the cluster endpoint.

  • Q: The Read-Only Traffic (%) parameter was set to 0 for the read-only instance that I purchased, but traffic was still routed to the instance. What do I do?

    A: The routed traffic may be generated by AP. After a read-only instance is purchased, intelligent read/write splitting is automatically enabled, so the traffic generated by AP is routed to the instance. To resolve this issue, disable intelligent read/write splitting.

  • Q: I configured the Read-Only Traffic (%) parameter for the read-only instance that I purchased, but no traffic was routed to the data nodes of the instance. Why?

    A: Traffic is routed by the specified proportion to read-only instances that are added to the resource pool of the primary instance. Your read-only instance may have been removed from the resource pool.

  • Q: Can I perform read/write splitting for my application by configuring various connection strings rather than using the read/write splitting feature provided by PolarDB-X?

    A: Yes, you can. If you do not want to use the read/write splitting feature provided by PolarDB-X, remove your read-only instance from the resource pool of the primary instance.

  • Q: Do I have to enable the strongly consistent read feature?

    A: If your business does not require strongly consistent reads, we recommend that you disable this feature to deliver high query performance. If you enable this feature as required by your business, queries may time out because the replication latency between your primary and read-only instances may be large, especially when a DDL statement is executed.

  • Q: How do I disable the strongly consistent read feature?

    A: If your application is connected to the primary instance, select Weak consistency for Data read consistency when you configure the cluster endpoint. If your application is connected to the read-only instances, select Weak consistency for Data read consistency when you configure the read-only routing endpoints.

  • Q: Queries frequently time out after I enable read/write splitting of PolarDB-X. What do I do?

    A: The timeout error may occur because the replication latency between your primary and read-only instances is large after the strongly consistent read feature is enabled. The latency may be caused by the following circumstances:

    • A DDL statement is executed in the primary instance or a large amount of data is imported to the primary instance.

    • The specifications of the read-only instances are significantly smaller than those of the primary instance.