zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject zookeeper git commit: ZOOKEEPER-2873: abort startup on invalid ports
Date Wed, 04 Jul 2018 15:12:05 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/branch-3.5 b024a3e29 -> cdbf03a8f


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

Reviewers: Andor Molnar <andor@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

(cherry picked from commit 25fd549dcd4e01de073a2e25ef07c170389b28ea)
Signed-off-by: Andor Molnar <andor@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/cdbf03a8
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/cdbf03a8
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/cdbf03a8

Branch: refs/heads/branch-3.5
Commit: cdbf03a8f6411594ad38b7b12c5e0c1dd42d2842
Parents: b024a3e
Author: Norbert Kalmar <nkalmar@yahoo.com>
Authored: Wed Jul 4 17:11:39 2018 +0200
Committer: Andor Molnar <andor@apache.org>
Committed: Wed Jul 4 17:11:59 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/cdbf03a8/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 7aa68e8..c0c8a87 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
@@ -260,6 +260,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/cdbf03a8/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/cdbf03a8/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 49de3f7..a050f7a 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");


Mime
View raw message