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

From: Chen Huajun <chjischj(at)163(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: [pgjdbc/pgjdbc] c6fec3: fix: improve multihost connection for preferSlave ...
Date: 2018-01-03 17:04:20
Message-ID: 5a4d0d14bd4dc_6a2c2ad446a77c1459932@hookshot-fe-7191cb1.cp1-iad.github.net.mail
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)163(dot)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.

Browse pgsql-jdbc by date

  From Date Subject
Next Message Peter Eisentraut 2018-01-04 20:41:39 Re: [JDBC] [HACKERS] Channel binding support for SCRAM-SHA-256
Previous Message Vladimir Sitnikov 2018-01-02 20:11:50 [pgjdbc/pgjdbc] 1361c5: fix: add type parameter so code is Java 6/7 compat...