Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWmTY-0004Yw-4n for pgsql-jdbc@arkaria.postgresql.org; Wed, 03 Jan 2018 17:05:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWmTX-0002t0-FD for pgsql-jdbc@arkaria.postgresql.org; Wed, 03 Jan 2018 17:05:11 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eWmTX-0002sN-4e for pgsql-jdbc@lists.postgresql.org; Wed, 03 Jan 2018 17:05:11 +0000 Received: from m69-169.mailgun.net ([166.78.69.169]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eWmTO-0007ag-7s for pgsql-jdbc@postgresql.org; Wed, 03 Jan 2018 17:05:09 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=github.com; q=dns/txt; s=mailo; t=1514999101; h=Content-Transfer-Encoding: Content-Type: Mime-Version: Subject: Message-ID: To: Reply-To: From: Date: Sender; bh=BfzGE44HSAHhNHbkWv4DqXubDPFjXsgNS8fKIh9aPQc=; b=mF04AACuoIK9XR2cBTwq9YS05ogGWm9NzXeS+4y4jXGK6dkzso8hU2rsMUG1u0IIOSF7Ek2p go5nD6xcQQZYeErZVBhqNmjLKKFiEcEYXwR8zHYDOxFdfspDG5FeG7vQhspFpFcdvA7WWErm FiVchKIr2tOHwO7Ou19vyQFgWRE= X-Mailgun-Sending-Ip: 166.78.69.169 X-Mailgun-Sid: WyI3ZTA2ZSIsICJwZ3NxbC1qZGJjQHBvc3RncmVzcWwub3JnIiwgIjQwZiJd Sender: chjischj=163.com@github.com Received: from github.com (Unknown [192.30.252.34]) by mxa.mailgun.org with ESMTP id 5a4d0d14.7f8920532fc0-smtp-out-n02; Wed, 03 Jan 2018 17:04:20 -0000 (UTC) Date: Wed, 03 Jan 2018 09:04:20 -0800 From: Chen Huajun Reply-To: Chen Huajun To: pgsql-jdbc@postgresql.org Message-ID: <5a4d0d14bd4dc_6a2c2ad446a77c1459932@hookshot-fe-7191cb1.cp1-iad.github.net.mail> Subject: [pgjdbc/pgjdbc] c6fec3: fix: improve multihost connection for preferSlave ... Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="--==_mimepart_5a4d0d14bd11d_6a2c2ad446a77c14598c2"; charset=UTF-8 Content-Transfer-Encoding: 7bit Approved: 58GruLoMopuc List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ----==_mimepart_5a4d0d14bd11d_6a2c2ad446a77c14598c2 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Branch: refs/heads/master Home: https://github.com/pgjdbc/pgjdbc Commit: c6fec34661b51cd9cbee157d0c334a3ab29859e8 https://github.com/pgjdbc/pgjdbc/commit/c6fec34661b51cd9cbee157d0c334a3ab29859e8 Author: Chen Huajun 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. ----==_mimepart_5a4d0d14bd11d_6a2c2ad446a77c14598c2--