Primary/Replica Selection
Depending on the chosen routing and authentication method, the selection of the Primary or Replica node can be controlled by the use of the
qos (Quality Of Service) syntax as outlined below:
RO_RELAXED: This setting enables the connector to redirect the query as if it were read-only, and therefore prefer a Replica over a Primary, but will choose a Primary if no Replica is available.RW_STRICT: This setting indicates that the query is a write and should be directed to a Primary. In Active-Active setups, where multiple Primaries exist, affinity determines in which site the primary should be selected.
Configuring the use of these properties can be controlled in a number of ways, as follows:
- SQL Based Routing (See "connector-routing-sql")
- Host based Routing (See "connector-routing-host")
- Embedded as part of Schema Name when specifying the database to connect to. For example, the following connect string would prefer a Replica for its connection:
jdbc:mysql://connector1:3306/mydb@qos=RO_RELAXED?autoreconnect=true
Further, connectivity can be influenced by setting a suitable latency (See "connector-routing-latency") value, or an explicit affinity (See "connector-routing-affinity".
The rules for selection of whether a connection is made to a Primary or a Replica is therefore controlled by comparing all of these settings and the selected routing mechanism together.
| QoS | Primary Selected | Replica Selected |
|---|---|---|
RW_STRICT | Yes, always | No |
RO_RELAXED | Only if no Replica available | Yes, if below max applied latency |
For further reading on how nodes are chosen, see "connector-routing-loadbalancers"