OceanBase Connector/J supports failover and load balancing modes: loadbalance.
Loadbalance mode
The loadbalance mode supports connection load balancing in a multi-host environment. This mode does not allow secondary servers to perform load-balanced reads. OceanBase Connector/J randomly selects a host from each connection URL to implement load balancing for all queries. The connections are randomly distributed across all hosts, achieving load balancing for queries.
Related parameters
The following table describes the parameters.
| Parameter | Description |
|---|---|
| autoReconnect | If this parameter is enabled and no failover or load balancing mode is in use, OceanBase Connector/J only attempts to reconnect to the host after the connection fails, which is called basic failover. If this parameter is enabled and a failover and load balancing mode is in use, OceanBase Connector/J blacklists the failed host and attempts to connect to other hosts of the same type, which is called standard failover. Default value: false. |
| retriesAllDown | If all hosts are down during a failover, this parameter is used to define the maximum number of connection retries allowed for OceanBase Connector/J. Default value: 120. |
| failoverLoopRetries | When OceanBase Connector/J silently searches for available hosts, this parameter specifies the maximum number of connection retries allowed for OceanBase Connector/J. This parameter is different from retriesAllDown. The silent search is used for temporary solutions of OceanBase Connector/J. For example, the primary connection is used to handle read queries when a secondary connection fails. Default value: 120. |
| validConnectionTimeout | When multiple hosts are configured, OceanBase Connector/J holds the verification connection within the specified duration (in seconds). When this parameter is set to 0, no verification is performed. Default value: 120. |
| loadBalanceBlacklistTimeout | When a connection fails, the host is added to the blacklist and blocked for the duration defined by this parameter (in seconds). OceanBase Connector/J preferentially attempts to connect to a host that is not in the blacklist. It attempts to connect to a host that is in the blacklist only when no host is found. The blacklist is shared within the class loader. Default value: 50. |
| assureReadOnly | If this parameter is enabled when a failover and load balancing mode is in use and a read-only connection is established to the host, the session is set to read-only to ensure that the connection is in read-only mode. Default value: false. |