From commits-return-6502-archive-asf-public=cust-asf.ponee.io@zookeeper.apache.org Wed Jul 4 17:11:48 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7B95E180608 for ; Wed, 4 Jul 2018 17:11:47 +0200 (CEST) Received: (qmail 3929 invoked by uid 500); 4 Jul 2018 15:11:46 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zookeeper.apache.org Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 3909 invoked by uid 99); 4 Jul 2018 15:11:46 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jul 2018 15:11:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7010ADFCBA; Wed, 4 Jul 2018 15:11:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: andor@apache.org To: commits@zookeeper.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: zookeeper git commit: ZOOKEEPER-2873: abort startup on invalid ports Date: Wed, 4 Jul 2018 15:11:46 +0000 (UTC) Repository: zookeeper Updated Branches: refs/heads/master 4607a3e15 -> 25fd549dc ZOOKEEPER-2873: abort startup on invalid ports This change will check each server.x config if the client and election port are the same. Currently, ZK will startup and a race for the ports will take place. There will be an error, but ZK will keep running (without the ability to elect a leader). Now, ZK will fail on startup. Author: Norbert Kalmar Reviewers: Andor Molnar Closes #549 from nkalmar/ZOOKEEPER-2873 and squashes the following commits: 022c8b70 [Norbert Kalmar] ZOOKEEPER-2873 modify test case to expect exception 60b8128d [Norbert Kalmar] ZOOKEEPER-2873 fix old test - ReconfigTest.testUnspecifiedClientAddress 3d747c08 [Norbert Kalmar] ZOOKEEPER-2873 abort startup on invalid ports Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/25fd549d Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/25fd549d Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/25fd549d Branch: refs/heads/master Commit: 25fd549dcd4e01de073a2e25ef07c170389b28ea Parents: 4607a3e Author: Norbert Kalmar Authored: Wed Jul 4 17:11:39 2018 +0200 Committer: Andor Molnar Committed: Wed Jul 4 17:11:39 2018 +0200 ---------------------------------------------------------------------- .../org/apache/zookeeper/server/quorum/QuorumPeer.java | 5 +++++ .../zookeeper/server/quorum/QuorumPeerConfigTest.java | 11 +++++++++++ .../test/org/apache/zookeeper/test/ReconfigTest.java | 10 ++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zookeeper/blob/25fd549d/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java ---------------------------------------------------------------------- diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java index a8b44e6..61ed573 100644 --- a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java +++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java @@ -259,6 +259,11 @@ public class QuorumPeer extends ZooKeeperThread implements QuorumStats.Provider throw new ConfigException("Address unresolved: " + serverParts[0] + ":" + serverParts[2]); } + if(addr.getPort() == electionAddr.getPort()) { + throw new ConfigException( + "Client and election port must be different! Please update the configuration file on server." + sid); + } + if (serverParts.length == 4) { setType(serverParts[3]); } http://git-wip-us.apache.org/repos/asf/zookeeper/blob/25fd549d/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerConfigTest.java ---------------------------------------------------------------------- diff --git a/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerConfigTest.java b/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerConfigTest.java index b9cdce8..3f5a2b2 100644 --- a/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerConfigTest.java +++ b/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerConfigTest.java @@ -103,6 +103,17 @@ public class QuorumPeerConfigTest { } } + /** + * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2873 + */ + @Test(expected = ConfigException.class) + public void testSamePortConfiguredForClientAndElection() throws IOException, ConfigException { + QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); + Properties zkProp = getDefaultZKProperties(); + zkProp.setProperty("server.1", "localhost:2888:2888"); + quorumPeerConfig.parseProperties(zkProp); + } + private Properties getDefaultZKProperties() { Properties zkProp = new Properties(); zkProp.setProperty("dataDir", new File("myDataDir").getAbsolutePath()); http://git-wip-us.apache.org/repos/asf/zookeeper/blob/25fd549d/src/java/test/org/apache/zookeeper/test/ReconfigTest.java ---------------------------------------------------------------------- diff --git a/src/java/test/org/apache/zookeeper/test/ReconfigTest.java b/src/java/test/org/apache/zookeeper/test/ReconfigTest.java index 427766c..8d10dc9 100644 --- a/src/java/test/org/apache/zookeeper/test/ReconfigTest.java +++ b/src/java/test/org/apache/zookeeper/test/ReconfigTest.java @@ -801,10 +801,12 @@ public class ReconfigTest extends ZKTestCase implements DataCallback{ @Test public void testUnspecifiedClientAddress() throws Exception { - int[] ports = new int[3]; - for (int port : ports) { - port = PortAssignment.unique(); - } + int[] ports = { + PortAssignment.unique(), + PortAssignment.unique(), + PortAssignment.unique() + }; + String server = "server.0=localhost:" + ports[0] + ":" + ports[1] + ";" + ports[2]; QuorumServer qs = new QuorumServer(0, server); Assert.assertEquals(qs.clientAddr.getHostString(), "0.0.0.0");