Operation of automatic client reroute for connections to IBM Informix from Java clients
When IBM® Data Server Driver for JDBC and SQLJ client reroute support is enabled, a Java application that is connected to an IBM Informix® high-availability cluster can continue to run when the primary server has a failure.
Automatic client reroute for a Java application that is connected to an IBM Informix server operates in the following way when automatic client reroute is enabled:
- During each connection to the data source, the IBM Data Server Driver for JDBC and SQLJ obtains
primary and alternate server information.
- For the first connection to IBM
Informix:
- The application specifies a server and port for the initial connection. Those values identify a Connection Manager.
- The IBM Data Server Driver for JDBC and SQLJ uses the information from the Connection Manager to obtain information about the primary and alternate servers. IBM Data Server Driver for JDBC and SQLJ loads those values into memory.
- If the initial connection to the Connection Manager fails:
- If the clientRerouteAlternateServerName and clientRerouteAlternatePortNumber properties are set, the IBM Data Server Driver for JDBC and SQLJ connects to the Connection Manager that is identified by clientRerouteAlternateServerName and clientRerouteAlternatePortNumber, and obtains information about primary and alternate servers from that Connection Manager. The IBM Data Server Driver for JDBC and SQLJ loads those values into memory as the primary and alternate server values.
- If the clientRerouteAlternateServerName and clientRerouteAlternatePortNumber properties are not set, and a JNDI store is configured by setting the property clientRerouteServerListJNDIName on the DB2BaseDataSource, the IBM Data Server Driver for JDBC and SQLJ connects to the Connection Manager that is identified by DB2ClientRerouteServerList.alternateServerName and DB2ClientRerouteServerList.alternatePortNumber, and obtains information about primary and alternate servers from that Connection Manager. IBM Data Server Driver for JDBC and SQLJ loads the primary and alternate server information from the Connection Manager into memory.
- If clientRerouteAlternateServerName and clientRerouteAlternatePortNumber are not set, and JNDI is not configured, the IBM Data Server Driver for JDBC and SQLJ checks DNS tables for Connection Manager server and port information. If DNS information exists, the IBM Data Server Driver for JDBC and SQLJ connects to the Connection Manager, obtains information about primary and alternate servers, and loads those values into memory.
- If no primary or alternate server information is available, a connection cannot be established, and the IBM Data Server Driver for JDBC and SQLJ throws an exception.
- For subsequent connections, the IBM Data Server Driver for JDBC and SQLJ obtains primary and alternate server values from driver memory.
- For the first connection to IBM
Informix:
- The IBM Data Server Driver for JDBC and SQLJ attempts
to connect to the data source using the primary server name and port
number.
If the connection is through the DriverManager interface, the IBM Data Server Driver for JDBC and SQLJ creates an internal DataSource object for automatic client reroute processing.
- If the connection to the primary server fails:
- If this is the first connection, the IBM Data Server Driver for JDBC and SQLJ attempts to reconnect to the original primary server.
- If this is not the first connection, the IBM Data Server Driver for JDBC and SQLJ attempts to reconnect to the new primary server, whose server name and port number were provided by the server.
- If reconnection to the primary server fails, the IBM Data Server Driver for JDBC and SQLJ attempts
to connect to the alternate servers.
If this is not the first connection, the latest alternate server list is used to find the next alternate server.
Connection to an alternate server is called failover.
The IBM Data Server Driver for JDBC and SQLJ uses the maxRetriesForClientReroute and retryIntervalForClientReroute properties to determine how many times to retry the connection and how long to wait between retries. An attempt to connect to the primary server and alternate servers counts as one retry.
- If the connection is not established, maxRetriesForClientReroute and retryIntervalForClientReroute are not set, and the original serverName and portNumber values that are defined on the DataSource are different from the serverName and portNumber values that were used for the original connection, retry the connection with the serverName and portNumber values that are defined on the DataSource.
- If failover is successful during the initial connection, the driver
generates an SQLWarning. If a successful failover
occurs after the initial connection:
- If seamless failover is enabled, the driver retries the transaction
on the new server, without notifying the application.
The following conditions must be satisfied for seamless failover to occur:
- The enableSeamlessFailover property is set to DB2BaseDataSource.YES (1).
If Sysplex workload balancing is in effect (the value of the enableSysplexWLB is true), seamless failover is attempted, regardless of the enableSeamlessFailover setting.
- The connection is not in a transaction. That is, the failure occurs when the first SQL statement in the transaction is executed.
- There are no global temporary tables in use on the server.
- There are no open, held cursors.
- The enableSeamlessFailover property is set to DB2BaseDataSource.YES (1).
- If seamless failover is not in effect, the driver throws an SQLException to
the application with error code -4498, to indicate to the application
that the connection was automatically reestablished and the transaction
was implicitly rolled back. The application can then retry its transaction
without doing an explicit rollback first.
A reason code that is returned with error code -4498 indicates whether any database server special registers that were modified during the original connection are reestablished in the failover connection.
You can determine whether alternate server information was used in establishing the initial connection by calling the DB2Connection.alternateWasUsedOnConnect method.
- If seamless failover is enabled, the driver retries the transaction
on the new server, without notifying the application.
- After failover, driver memory is updated with new primary and alternate server information from the new primary server.
Examples
Example: Automatic client reroute to an IBM Informix server when maxRetriesForClientReroute and retryIntervalForClientReroute are not set: Suppose that the following properties are set for a connection to a database:
| Property | Value |
|---|---|
| enableClientAffinitiesList | DB2BaseDataSource.NO (2) |
| serverName | host1 |
| portNumber | port1 |
| clientRerouteAlternateServerName | host2 |
| clientRerouteAlternatePortNumber | port2 |
- The IBM Data Server Driver for JDBC and SQLJ tries to connect to the Connection Manager that is identified by host1:port1.
- The connection to host1:port1 fails, so the driver tries to connect to the Connection Manager that is identified by host2:port2.
- The connection to host2:port2 succeeds.
- The driver retrieves alternate server information that was received
from server host2:port2, and updates its memory with that information.
Assume that the driver receives a server list that contains host2:port2, host2a:port2a. host2:port2 is stored as the new primary server, and host2a:port2a is stored as the new alternate server. If another communication failure is detected on this same connection, or on another connection that is created from the same DataSource, the driver tries to connect to host2:port2 as the new primary server. If that connection fails, the driver tries to connect to the new alternate server host2a:port2a.
- The driver connects to host1a:port1a.
- A failure occurs during the connection to host1a:port1a.
- The driver tries to connect to host2a:port2a.
- The connection to host2a:port2a is successful.
- The driver retrieves alternate server information that was received from server host2a:port2a, and updates its memory with that information.
Example: Automatic client reroute to an IBM Informix server when maxRetriesForClientReroute and retryIntervalForClientReroute are set for multiple retries: Suppose that the following properties are set for a connection to a database:
| Property | Value |
|---|---|
| enableClientAffinitiesList | DB2BaseDataSource.NO (2) |
| serverName | host1 |
| portNumber | port1 |
| clientRerouteAlternateServerName | host2 |
| clientRerouteAlternatePortNumber | port2 |
| maxRetriesForClientReroute | 3 |
| retryIntervalForClientReroute | 2 |
- The IBM Data Server Driver for JDBC and SQLJ tries to connect to the Connection Manager that is identified by host1:port1.
- The connection to host1:port1 fails, so the driver tries to connect to the Connection Manager that is identified by host2:port2.
- The connection to host2:port2 succeeds.
- The driver retrieves alternate server information from the connection manager that is identified by host2:port2, and updates its memory with that information. Assume that the Connection Manager identifies host1a:port1a as the new primary server, and host2a:port2a as the new alternate server.
- The driver tries to connect to host1a:port1a.
- The connection to host1a:port1a fails.
- The driver tries to connect to host2a:port2a.
- The connection to host2a:port2a fails.
- The driver waits two seconds.
- The driver tries to connect to host1a:port1a.
- The connection to host1a:port1a fails.
- The driver tries to connect to host2a:port2a.
- The connection to host2a:port2a fails.
- The driver waits two seconds.
- The driver tries to connect to host1a:port1a.
- The connection to host1a:port1a fails.
- The driver tries to connect to host2a:port2a.
- The connection to host2a:port2a fails.
- The driver waits two seconds.
- The driver throws an SQLException with error code -4499.