PolarDB supports automatic distribution based on the loads of nodes. Read requests are automatically
forwarded to read-only nodes based on the number of active connections. This ensures
load balancing across read-only nodes. This topic describes how to offload reads from
the primary node and spit transactions for load balancing.
Offload reads from the primary node
After you enable the feature to offload reads from the primary node, common read requests
are no longer forwarded to the primary node. Within a transaction, read requests that
have strict consistency requirements are still forwarded to the primary node to meet
the business requirements. If all read-only nodes are faulty, read requests are forwarded
to the primary node. If your workloads do not require high consistency, you can set
the consistency level to eventual consistency to reduce the read requests that are
forwarded to the primary node. You can also use the transaction splitting feature
to reduce the read requests that are forwarded to the primary node before a transaction
is started. However, broadcast requests such as SET and PREPARE requests are forwarded
to the primary node. For more information about how to modify the
Primary Node Accepts Read Requests configuration, see
Manage a cluster endpoint.
Note
- The Primary Node Accepts Read Requests parameter is available only if the Read/write Mode parameter is set to Read and Write (Automatic Read-write Splitting).
- The modification of the Primary Node Accepts Read Requests configuration immediately takes effect.
Split transactions
If the cluster endpoint that is used to connect to the
PolarDB cluster is in read/write mode, PolarProxy forwards read and write requests to the
primary node and read-only nodes. To ensure data consistency among transactions within
a session, PolarProxy sends all requests in transactions of the session to the primary
node. For example, database client drivers such as the Java Database Connectivity
(JDBC) encapsulate requests in a transaction. In this case, all requests from applications
are sent to the primary node. This results in heavy loads on the primary node. However,
no requests are sent to read-only nodes. The following figure shows the process.

To fix this issue,
PolarDB provides the transaction splitting feature. This feature ensures data consistency
in a session and allows PolarDB to send read requests to read-only nodes to reduce
the loads on the primary node. You can reduce the read loads on the primary node without
the need to modify the code or configuration of your application. This way, the stability
of the primary node is improved.
Note Only transactions in the sessions that are at the Read Committed isolation level can
be split.
To reduce the load of the primary node, PolarProxy sends read requests that are received
before the first write request in a transaction is sent to read-only nodes. Uncommitted
data in transactions cannot be queried from read-only nodes. To ensure data consistency
in transactions, all read and write requests that are received after the first write
request are still forwarded to the primary node. For more information about how to
enable transaction splitting, see Manage a cluster endpoint.