From: Chen Huajun <chjischj@163.com>
To: pgsql-jdbc@postgresql.org
Subject: [pgjdbc/pgjdbc] c6fec3: fix: improve multihost connection for preferSlave ...
Date: Wed, 03 Jan 2018 09:04:20 -0800
Message-ID: <5a4d0d14bd4dc_6a2c2ad446a77c1459932@hookshot-fe-7191cb1.cp1-iad.github.net.mail> (raw)
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: chjischj@163.com
Subject: Re: [pgjdbc/pgjdbc] c6fec3: fix: improve multihost connection for preferSlave ...
In-Reply-To: <5a4d0d14bd4dc_6a2c2ad446a77c1459932@hookshot-fe-7191cb1.cp1-iad.github.net.mail>
References: <5a4d0d14bd4dc_6a2c2ad446a77c1459932@hookshot-fe-7191cb1.cp1-iad.github.net.mail>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox