[pgjdbc/pgjdbc] c6fec3: fix: improve multihost connection for preferSlave ...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[pgjdbc/pgjdbc] c6fec3: fix: improve multihost connection for preferSlave ...

chenhj
  Branch: refs/heads/master
  Home:   https://github.com/pgjdbc/pgjdbc
  Commit: c6fec34661b51cd9cbee157d0c334a3ab29859e8
      https://github.com/pgjdbc/pgjdbc/commit/c6fec34661b51cd9cbee157d0c334a3ab29859e8
  Author: Chen Huajun <[hidden email]>
  Date:   2018-01-03 (Wed, 03 Jan 2018)

  Changed paths:
    M .travis.yml
    A .travis/travis_create_slaves.sh
    M README.md
    M build.properties
    M pgjdbc/src/main/java/org/postgresql/PGProperty.java
    M pgjdbc/src/main/java/org/postgresql/core/v3/ConnectionFactoryImpl.java
    A pgjdbc/src/main/java/org/postgresql/hostchooser/CandidateHost.java
    M pgjdbc/src/main/java/org/postgresql/hostchooser/GlobalHostStatusTracker.java
    M pgjdbc/src/main/java/org/postgresql/hostchooser/HostChooser.java
    M pgjdbc/src/main/java/org/postgresql/hostchooser/HostChooserFactory.java
    M pgjdbc/src/main/java/org/postgresql/hostchooser/MultiHostChooser.java
    M pgjdbc/src/main/java/org/postgresql/hostchooser/SingleHostChooser.java
    M pgjdbc/src/test/java/org/postgresql/test/hostchooser/MultiHostTestSuite.java
    M pgjdbc/src/test/java/org/postgresql/test/hostchooser/MultiHostsConnectionTest.java

  Log Message:
  -----------
  fix: improve multihost connection for preferSlave case (verify expired hosts before connecting to cached master) (#844)

The notable behavior change is related with targetServerType=preferSlave.
In that case, it requires to check all the possible slaves first to find the right server.
The state of some servers might be expired due to hostRecheckSeconds,
so pgjdbc should try connecting to all the "known slaves"
and "expired" servers in attempt to find a slave among them, and only then
it should try connecting to master.

That logic was not there, and preferSlave could easily connect to master even
at times when a slave was available.

Note: hostRecheckSeconds is still in place (default 10 seconds), and pgdjbc
trusts that status.

However, there's an exception: in case no servers match the criteria (e.g.
all the servers are marked with "can't connect" in cache), then pgjdbc
would still try connecting to all the hosts in the connection URL in order.