OceanBase Connector/J supports the following load-balancing modes: loadbalance and replication.
loadbalance mode
The loadbalance mode supports connection load balancing in multi-host environments. This mode does not support load-balanced reads from secondary servers. The connector performs load balancing for all queries by randomly selecting a host from each connection URL. Since connections are randomly distributed across all hosts, queries are load-balanced.
replication mode
The replication mode supports connection load balancing in primary/secondary environments. This mode is suitable for environments with one or more primary hosts. If a connection is set to read-only before reading operations, this mode supports load-balanced reads from secondary servers. The connector performs load balancing by randomly selecting a secondary server from the connection URL to execute read queries.
Related parameters
The related parameters are listed in the following table.
Parameters |
Description |
|---|---|
| autoReconnect | If this parameter is enabled and Load-Balancing mode is not used, the connector will only attempt to reconnect to the host after a connection failure. If this parameter is enabled and Load-Balancing mode is used, the connector will blacklist the failed host and attempt to connect to other hosts of the same type. Default value:false.
NoticeWhen |
| validConnectionTimeout | When multiple hosts are configured, the connector will not lose the connection verification within the set duration (in seconds). When this parameter is set to 0, no verification will be performed. Default value: 120 s. |
| loadBalanceBlacklistTimeout | When a connection fails, the host will be added to a blacklist for the duration defined by this parameter. When connecting to a host, the driver attempts to connect to hosts that are not on the blacklist. Only if no host is found will it attempt to connect to a host on the blacklist. This blacklist is shared within the class loader. Default value: 50 ms. |
| assureReadOnly | If you enable this parameter when using load balancing mode and establishing a read-only connection with the host, the session will be set to read-only to ensure this connection remains in read-only mode. Default value:false. |
| allowMasterDownConnection | Using Load-BalancingreplicationIn this mode, connections are allowed to be created when the primary server is shut down. If no primary server is available, connections are made to the secondary server by default.Connection.isReadOnly()will returntrue. Default value:false. |