Академический Документы
Профессиональный Документы
Культура Документы
The failover is configured at the initial setup stage of the server connection by the connection
URL (see explanations for its format here):
jdbc:mysql://[primary host]
[:port],[secondary host 1]
[:port][,[secondary host 2]
[:port]]...[/[database]]»
[?
propertyName1=propertyValue1[&
propertyName2=propertyValue2].
..]
The host list in the connection URL comprises of two types of hosts, the primary and the
secondary. When starting a new connection, the driver always tries to connect to the primary
host first and, if required, fails over to the secondary hosts on the list sequentially when
communication problems are experienced. Even if the initial connection to the primary host fails
and the driver gets connected to a secondary host, the primary host never loses its special
status: for example, it can be configured with an access mode distinct from those of the
secondary hosts, and it can be put on a higher priority when a host is to be picked during a
failover process.
The failover support is configured by the following connection properties (their functions are
explained in the paragraphs below):
failOverReadOnly
secondsBeforeRetryMaster
queriesBeforeRetryMaster
retriesAllDown
autoReconnect
autoReconnectForPools
Configuring Connection Access Mode
As with any standard connection, the initial connection to the primary host is in read/write mode.
However, if the driver fails to establish the initial connection to the primary host and it
automatically switches to the next host on the list, the access mode now depends on the value of
the property failOverReadOnly, which is “true” by default. The same happens if the driver is
initially connected to the primary host and, because of some connection failure, it fails over to a
secondary host. Every time the connection falls back to the primary host, its access mode will be
read/write, irrespective of whether or not the primary host has been connected to before. The
connection access mode can be changed any time at runtime by calling the
method Connection.setReadOnly(boolean), which partially overrides the
property failOverReadOnly. When failOverReadOnly=false and the access mode is
explicitly set to either true or false, it becomes the mode for every connection after a host switch,
no matter what host type are being connected to; but, if failOverReadOnly=true, changing the
access mode to read/write is only possible if the driver is connecting to the primary host;
however, even if the access mode cannot be changed for the current connection, the driver
remembers the client's last intention and, when falling back to the primary host, that is the mode
that will be used. For an illustration, see the following successions of events with a two-host
connection.
Sequence A,
with failOverReadOnly=true:
1. Connects to primary host in
read/write mode
2. Sets Connection.setReadO
nly(true); primary host now
in read-only mode
3. Failover event; connects to
secondary host in read-only
mode
4. Sets Connection.setReadO
nly(false); secondary host
remains in read-only mode
5. Falls back to primary host;
connection now in read/write
mode
Sequence B,
with failOverReadOnly=false
1. Connects to primary host in
read/write mode
2. Sets Connection.setReadO
nly(true); primary host now
in read-only mode
3. Failover event; connects to
secondary host in read-only
mode
4. Set Connection.setReadOn
ly(false); connection to
secondary host switches to
read/write mode
5. Falls back to primary host;
connection now in read/write
mode
The difference between the two scenarios is in step 4: the access mode for the secondary host in
sequence A does not change at that step, but the driver remembers and uses the set mode when
falling back to the primary host, which would be read-only otherwise; but in sequence B, the
access mode for the secondary host changes immediately.
PREV HOME UP NEXT
© 2020, Oracle Corporation and/or its affiliates