You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by an...@apache.org on 2018/07/04 15:11:46 UTC

zookeeper git commit: ZOOKEEPER-2873: abort startup on invalid ports

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 <nk...@yahoo.com>

Reviewers: Andor Molnar <an...@apache.org>

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 <nk...@yahoo.com>
Authored: Wed Jul 4 17:11:39 2018 +0200
Committer: Andor Molnar <an...@apache.org>
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");