[pgjdbc/pgjdbc] c6fec3: fix: improve multihost connection forpreferSlave ... - Mailing list pgsql-jdbc

From Chen Huajun
Subject [pgjdbc/pgjdbc] c6fec3: fix: improve multihost connection forpreferSlave ...
Date
Msg-id 5a4d0d14bd4dc_6a2c2ad446a77c1459932@hookshot-fe-7191cb1.cp1-iad.github.net.mail
Whole thread Raw
List pgsql-jdbc
Branch: refs/heads/master
  Home:   https://github.com/pgjdbc/pgjdbc
  Commit: c6fec34661b51cd9cbee157d0c334a3ab29859e8
      https://github.com/pgjdbc/pgjdbc/commit/c6fec34661b51cd9cbee157d0c334a3ab29859e8
  Author: Chen Huajun <chjischj@163.com>
  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.



pgsql-jdbc by date:

Previous
From: Vladimir Sitnikov
Date:
Subject: [pgjdbc/pgjdbc] 1361c5: fix: add type parameter so code is Java 6/7compat...
Next
From: Vladimir Sitnikov
Date:
Subject: Release environment