When IBM® Data Server Driver for JDBC and SQLJ client
reroute support is enabled, a Java™ application
that is connected to a DB2® for Linux, UNIX, and Windows database
can continue to run when the primary server has a failure.
Automatic client reroute for a Java application
that is connected to a DB2 for Linux, UNIX, and Windows database
operates in the following way when support for client affinities is
disabled:
- 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 a DB2 for Linux, UNIX, and Windows database:
- If the clientRerouteAlternateServerName and clientRerouteAlternatePortNumber
properties are set, the IBM Data Server Driver for JDBC and SQLJ loads
those values into memory as the alternate server values, along with
the primary server values serverName and portNumber.
- 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 loads
the primary and alternate server information from the JNDI store into
memory.
- If no DataSource properties are set for the
alternate servers, and JNDI is not configured, the IBM Data Server Driver for JDBC and SQLJ checks
DNS tables for primary and alternate server information. If DNS information
exists, the IBM Data Server Driver for JDBC and SQLJ loads
those values into memory.
In a
DB2 pureScale® environment,
regardless of the outcome of the DNS lookup:
- If configuration property db2.jcc.outputDirectory is set, the IBM Data Server Driver for JDBC and SQLJ searches
the directory that is specified by db2.jcc.outputDirectory for a file
named jccServerListCache.bin.
- If db2.jcc.outputDirectory is not set, and the java.io.tmpdir
system property is set, the IBM Data Server Driver for JDBC and SQLJ searches
the directory that is specified by java.io.tmpdir for a file named
jccServerListCache.bin.
- If jccServerListCache.bin can be accessed, the IBM Data Server Driver for JDBC and SQLJ loads
the cache into memory, and obtains the alternate server information
from jccServerListCache.bin for the serverName value that is defined
for the DataSource object.
- 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.
- The IBM Data Server Driver for JDBC and SQLJ attempts
to connect to the data source using the primary server name and port
number.
In a non-DB2 pureScale environment,
the primary server is a stand-alone server. In a DB2 pureScale environment,
the primary server is a member of a DB2 pureScale instance.
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 a server using information that is provided by driver
properties such as clientRerouteAlternateServerName and clientRerouteAlternatePortNumber.
- If this is not the first connection, the IBM Data Server Driver for JDBC and SQLJ attempts
to make a connection using the information from the latest server
list that is returned from the 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 current connection, the connection is retried 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:
You
can determine whether alternate server information was used in establishing
the initial connection by calling the DB2Connection.alternateWasUsedOnConnect method.
- After failover, driver memory is updated with new primary and
alternate server information that is returned from the new primary
server.
Examples
Example: Automatic client reroute
to a DB2 for Linux, UNIX, and Windows 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 following steps demonstrate an automatic client reroute
scenario for a connection to a
DB2 for Linux, UNIX, and Windows server:
- The IBM Data Server Driver for JDBC and SQLJ loads
host1:port1 into its memory as the primary server address, and host2:port2
into its memory as the alternate server address.
- On the initial connection, the driver tries to connect to host1:port1.
- The connection to host1:port1 fails, so the driver tries another
connection to host1:port1.
- The reconnection to host1:port1 fails, so the driver tries to
connect to 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.
- A communication failure occurs during the connection to host2:port2.
- 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 a DB2 for Linux, UNIX, and Windows server
in a DB2 pureScale environment,
when maxRetriesForClientReroute and retryIntervalForClientReroute
are not set, and configuration property db2.jcc.outputDirectory is
set: Suppose that the following properties are set for a connection
that is established from DataSource A:
Property |
Value |
enableClientAffinitiesList |
DB2BaseDataSource.NO (2) |
serverName |
host1 |
portNumber |
port1 |
db2.jcc.outputDirectory (configuration property) |
/home/tmp |
The following
steps demonstrate an automatic client reroute scenario for a connection
to a
DB2 for Linux, UNIX, and Windows server:
- Using the information in DataSource A, the IBM Data Server Driver for JDBC and SQLJ loads
host1:port1 into its memory as the primary server address. The driver
searches for cache file jccServerListCache.bin in /home/tmp, but the
cache file does not exist.
- The connection to host1:port1 succeeds. Suppose that the server
returns a server list that contains host1:port1 and host2:port2.
- The driver creates a cache in memory, with an entry that specifies
host2:port2 as the alternate server list for host1:port1. The driver
then creates the cache file /home/tmp/jccServerListCache.bin, and
writes the cache from memory to this file.
- The connection of Application A to host1:port1 fails, so the driver
tries to connect to host2:port2.
- The connection of Application A to host2:port2 succeeds. Suppose
that the server returns a server list that contains host2:port2 and
host2a:port2a. host2:port2 is the new primary server, and host2a:port2a
is the new alternate server.
- The driver looks for alternate server information for host2:port2
in the in-memory cache, but does not find any. It creates a new entry
in the in-memory cache for host2:port2, with host2a:port2a as the
alternate server list. The driver updates cache file /home/tmp/jccServerListCache.bin
with the new entry that was added to the in-memory cache.
- Application A completes, and the JVM exits.
- Application B, which also uses DataSource A,
starts.
- The driver loads the server list from cache file /home/tmp/jccServerListCache.bin
into memory, and finds the entry for host1:port1, which specifies
host2:port2 as the alternate server list. The driver sets host2:port2
as the alternate server list for host1:port1.
- A communication failure occurs when Application B tries to connect
to host1:port1.
- Application B attempts to connect to alternate server host2:port2.
- The connection to host2:port2 succeeds. Application B continues.
Example: Automatic client reroute to a DB2 for Linux, UNIX, and Windows 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 following steps demonstrate an automatic client reroute
scenario for a connection to a
DB2 for Linux, UNIX, and Windows server:
- The IBM Data Server Driver for JDBC and SQLJ loads
host1:port1 into its memory as the primary server address, and host2:port2
into its memory as the alternate server address.
- On the initial connection, the driver tries to connect to host1:port1.
- The connection to host1:port1 fails, so the driver tries another
connection to host1:port1.
- The connection to host1:port1 fails again, so the driver tries
to connect to host2:port2.
- The connection to host2:port2 fails.
- The driver waits two seconds.
- The driver tries to connect to host1:port1 and fails.
- The driver tries to connect to host2:port2 and fails.
- The driver waits two seconds.
- The driver tries to connect to host1:port1 and fails.
- The driver tries to connect to host2:port2 and fails.
- The driver waits two seconds.
- The driver throws an SQLException with error
code -4499.