You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by hanm <gi...@git.apache.org> on 2017/06/26 23:18:47 UTC

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

GitHub user hanm opened a pull request:

    https://github.com/apache/zookeeper/pull/292

    ZOOKEEPER-2819:Changing membership configuration via rolling restart …

    …does not work on 3.5.x.
    
    This patch disables the creation of dynamic config files (zoo.cfg.dynamic) and static config back up files (zoo.cfg.bak) when the dynamic reconfig feature flag (reconfigEnabled) is disabled. With this patch the membership information (such as server list) will be stored in static zoo.cfg file and such information would not go through quorum and leader / follower sync phase, which makes it possible for users to continue using the old rolling restart approach.
    
    @shralex PTAL.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/hanm/zookeeper ZOOKEEPER-2819

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/zookeeper/pull/292.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #292
    
----
commit 896ee06502d602ea5147d489a5e6f777fbaaa83e
Author: Michael Han <ha...@apache.org>
Date:   2017-06-26T22:41:26Z

    ZOOKEEPER-2819:Changing membership configuration via rolling restart does not work on 3.5.x.
    This patch disables the creation of dynamic config files (zoo.cfg.dynamic) and static config back up files (zoo.cfg.bak) when the dynamic reconfig feature flag (reconfigEnabled) is disabled. With this patch the membership information (such as server list) will be stored in static zoo.cfg file and such information would not go through quorum and leader / follower sync phase, which makes it possible for users to continue using the old rolling restart approach.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/zookeeper/pull/292


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125125684
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,275 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.WatchedEvent;
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.CreateMode;
    +import org.apache.zookeeper.ZooDefs;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.KeeperException;
    +import org.apache.zookeeper.Watcher;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String backupFileName = "zoo.cfg.bak";
    +
    +    Map<Integer, Integer> clientPorts = new HashMap<>(5);
    +    Map<Integer, String> serverAddress = new HashMap<>(5);
    +
    +    private String generateNewQuorumConfig(int serverCount) {
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +        for (int i = 0; i < serverCount; i++) {
    +            clientPorts.put(i, PortAssignment.unique());
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(i);
    +            serverAddress.put(i, server);
    +            sb.append(server + "\n");
    +        }
    +        return sb.toString();
    +    }
    +
    +    private String updateExistingQuorumConfig(List<Integer> sidsToAdd, List<Integer> sidsToRemove) {
    +        StringBuilder sb = new StringBuilder();
    +        for (Integer sid : sidsToAdd) {
    +            clientPorts.put(sid, PortAssignment.unique());
    +            serverAddress.put(sid, "server." + sid + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(sid));
    +        }
    +
    +        for (Integer sid : sidsToRemove) {
    +            clientPorts.remove(sid);
    +            serverAddress.remove(sid);
    +        }
    +
    +        for (String server : serverAddress.values()) {
    +            sb.append(server + "\n");
    +        }
    +
    +        return sb.toString();
    +    }
    +
    +    @Test(timeout = 60000)
    +    // Verify no zoo.cfg.dynamic and zoo.cfg.bak files existing locally
    +    // when reconfig feature flag is off by default.
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        String[] staticFileContent = new String[serverCount];
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(backupFileName));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverAddress.get(i),
    +                    staticFileContent[i].contains(serverAddress.get(i)));
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    // This test simulate the usual rolling restart with no membership change:
    +    // 1. A node is shutdown first (e.g. to upgrade software, or hardware, or cleanup local data.).
    +    // 2. After upgrade, start the node.
    +    // 3. Do this for every node, one at a time.
    +    public void testRollingRestartWithoutMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +            mt[i].start();
    +            verifyQuorum(i);
    --- End diff --
    
    two comments:
    1. is calling start immediately after shutdown effective ? I don't remember what shutdown is doing, but if its setting a flag and a thread periodically checks it, it may take time to take effect.
    2. nothing is changing about the config as far as I can see. Why would this ever fail ? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper issue #292: ZOOKEEPER-2819:Changing membership configuration via r...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on the issue:

    https://github.com/apache/zookeeper/pull/292
  
    >> One question - what happens with getConfig when reconfig is disabled ? Does it still work ?
    
    Yes getConfigwill continue working until the heat death of the universe regardless of reconfigEnabled flag settings :). 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper issue #292: ZOOKEEPER-2819:Changing membership configuration via r...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on the issue:

    https://github.com/apache/zookeeper/pull/292
  
    Addressed code review comments from @shralex:
    
    * Use ReconfigTest.testServerHasConfig for additional test coverage.
    * Improve fragile substring extraction.
    * Add comments around test logic.
    * Also made a fix to ensure during rolling restart, config information returned from getConfig is consistent with local config.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r124397041
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,94 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.junit.Assert;
    +import org.junit.Before;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String backupFileName = "zoo.cfg.bak";
    +
    +    final int SERVER_COUNT = 3;
    +    final int clientPorts[] = new int[SERVER_COUNT];
    +    final String serverList[] = new String[SERVER_COUNT];
    +    StringBuilder sb = new StringBuilder();
    +
    +    @Before
    +    public void setup() throws InterruptedException {
    +        String server;
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            clientPorts[i] = PortAssignment.unique();
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts[i];
    +            serverList[i] = server;
    +            sb.append(server + "\n");
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        String currentQuorumCfgSection = sb.toString();
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[SERVER_COUNT];
    +        String[] staticFileContent = new String[SERVER_COUNT];
    +
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts[i],
    +                    currentQuorumCfgSection, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(backupFileName));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverList[i],
    +                    staticFileContent[i].contains(serverList[i]));
    +        }
    +
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +}
    --- End diff --
    
    Should be fixed now.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125121157
  
    --- Diff: src/java/test/org/apache/zookeeper/test/ReconfigExceptionTest.java ---
    @@ -89,6 +89,7 @@ public void tearDown() throws Exception {
     
         @Test(timeout = 10000)
         public void testReconfigDisabledByDefault() throws InterruptedException {
    +        QuorumPeerConfig.setReconfigEnabled(false);
    --- End diff --
    
    Given that the test is called "disabled-by-default" Its strange to disable this manually here. I suggest to rename the test to reflect what its doing - checking that when the flag is false reconfig ops aren't allowed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125130820
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRecoveryTest.java ---
    @@ -28,9 +28,15 @@
     import org.apache.zookeeper.test.ClientBase;
     import org.apache.zookeeper.test.ReconfigTest;
     import org.junit.Assert;
    +import org.junit.Before;
     import org.junit.Test;
     
     public class ReconfigRecoveryTest extends QuorumPeerTestBase {
    +    @Before
    +    public void setup() {
    +        QuorumPeerConfig.setReconfigEnabled(true);
    --- End diff --
    
    Yes if those tests require reconfig feature being enabled. I think I've patched all reconfig test in ZOOKEEPER-2014, and the modifications of related tests here are all about refactoring and consolidating setting of the flag in a single place.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125120823
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRecoveryTest.java ---
    @@ -28,9 +28,15 @@
     import org.apache.zookeeper.test.ClientBase;
     import org.apache.zookeeper.test.ReconfigTest;
     import org.junit.Assert;
    +import org.junit.Before;
     import org.junit.Test;
     
     public class ReconfigRecoveryTest extends QuorumPeerTestBase {
    +    @Before
    +    public void setup() {
    +        QuorumPeerConfig.setReconfigEnabled(true);
    --- End diff --
    
    is the same needed also in all other reconfig test files ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper issue #292: ZOOKEEPER-2819:Changing membership configuration via r...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on the issue:

    https://github.com/apache/zookeeper/pull/292
  
    Thanks @shralex for review. Good catch on the "3", "4" server issue. PR updated that addresses latest comments. The failed test is a known flaky one. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125132175
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,275 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.WatchedEvent;
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.CreateMode;
    +import org.apache.zookeeper.ZooDefs;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.KeeperException;
    +import org.apache.zookeeper.Watcher;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String backupFileName = "zoo.cfg.bak";
    +
    +    Map<Integer, Integer> clientPorts = new HashMap<>(5);
    +    Map<Integer, String> serverAddress = new HashMap<>(5);
    +
    +    private String generateNewQuorumConfig(int serverCount) {
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +        for (int i = 0; i < serverCount; i++) {
    +            clientPorts.put(i, PortAssignment.unique());
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(i);
    +            serverAddress.put(i, server);
    +            sb.append(server + "\n");
    +        }
    +        return sb.toString();
    +    }
    +
    +    private String updateExistingQuorumConfig(List<Integer> sidsToAdd, List<Integer> sidsToRemove) {
    +        StringBuilder sb = new StringBuilder();
    +        for (Integer sid : sidsToAdd) {
    +            clientPorts.put(sid, PortAssignment.unique());
    +            serverAddress.put(sid, "server." + sid + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(sid));
    +        }
    +
    +        for (Integer sid : sidsToRemove) {
    +            clientPorts.remove(sid);
    +            serverAddress.remove(sid);
    +        }
    +
    +        for (String server : serverAddress.values()) {
    +            sb.append(server + "\n");
    +        }
    +
    +        return sb.toString();
    +    }
    +
    +    @Test(timeout = 60000)
    +    // Verify no zoo.cfg.dynamic and zoo.cfg.bak files existing locally
    +    // when reconfig feature flag is off by default.
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        String[] staticFileContent = new String[serverCount];
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(backupFileName));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverAddress.get(i),
    +                    staticFileContent[i].contains(serverAddress.get(i)));
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    // This test simulate the usual rolling restart with no membership change:
    +    // 1. A node is shutdown first (e.g. to upgrade software, or hardware, or cleanup local data.).
    +    // 2. After upgrade, start the node.
    +    // 3. Do this for every node, one at a time.
    +    public void testRollingRestartWithoutMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +            mt[i].start();
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 90000)
    +    // This test simulate the use case of change of membership through rolling
    +    // restart. For a 3 node ensemble we expand it to a 5 node ensemble, verify
    +    // during the process each node has the expected configuration setting pushed
    +    // via updating local zoo.cfg file.
    +    public void testRollingRestartWithMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        Map<Integer, String> oldServerAddress = new HashMap<>(serverAddress);
    +        config = updateExistingQuorumConfig(Arrays.asList(3, 4), new ArrayList<Integer>());
    +        serverCount = serverAddress.size();
    +        Assert.assertEquals("Server count should be 5 after config update.", serverCount, 5);
    +
    +        mt = Arrays.copyOf(mt, mt.length + 2);
    +        for (int i = 3; i < 5; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            verifyConfig(mt[i]);
    +            verifyQuorum(i);
    +        }
    +
    +        Set<String> expectedConfigs = new HashSet<>();
    +        for (String conf : oldServerAddress.values()) {
    +            // Remove "server.x=" prefix.
    +            expectedConfigs.add(conf.substring(9));
    +        }
    +
    +        for (int i = 0; i < 3; ++i) {
    +            verifyConfig(mt[i], expectedConfigs);
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    // A successful write operation indicates a quorum is up.
    +    private void verifyQuorum(int sid)
    +            throws IOException, InterruptedException, KeeperException {
    +        ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts.get(sid),
    +                ClientBase.CONNECTION_TIMEOUT, new Watcher() {
    +            public void process(WatchedEvent event) {
    +            }});
    +
    +        for (int j = 0; j < 30; j++) {
    +            try {
    +                zk.create("/" + Integer.toString(sid) + "." + Math.random(),
    +                        "foobar".getBytes(),
    +                        ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    +                break;
    +            } catch (KeeperException.ConnectionLossException e) {
    +                if (j < 29) {
    +                    Thread.sleep(1000);
    +                } else {
    +                    Assert.fail("client could not connect to reestablished quorum: " +
    +                            "giving up after 30+ seconds.");
    +                }
    +            }
    +        }
    +    }
    +
    +    private void verifyConfig(QuorumPeerTestBase.MainThread mt) {
    +        Set<String> expectedConfigs = new HashSet<>();
    +        for (String config : serverAddress.values()) {
    +            // Remove "server.x=" prefix.
    +            expectedConfigs.add(config.substring(9));
    --- End diff --
    
    With the ReconfigTest helpers I can remove these code, hopefully.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r124183585
  
    --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java ---
    @@ -1744,9 +1744,14 @@ public void setAcceptedEpoch(long e) throws IOException {
         public boolean processReconfig(QuorumVerifier qv, Long suggestedLeaderId, Long zxid, boolean restartLE) {
            InetSocketAddress oldClientAddr = getClientAddress();
     
    +       boolean isReconfigEnabled = QuorumPeerConfig.isReconfigEnabled();
            // update last committed quorum verifier, write the new config to disk
    -       // and restart leader election if config changed
    -       QuorumVerifier prevQV = setQuorumVerifier(qv, true);
    +       // and restart leader election if config changed. If reconfig feature is
    +       // not enabled, just set last committed quorum verifier and bail out.
    +       QuorumVerifier prevQV = setQuorumVerifier(qv, isReconfigEnabled);
    --- End diff --
    
    The server acts according to the config it has in its quorum verifier, so setting quorum verifier overwrites the config file settings with the leader's settings


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125131915
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,275 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.WatchedEvent;
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.CreateMode;
    +import org.apache.zookeeper.ZooDefs;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.KeeperException;
    +import org.apache.zookeeper.Watcher;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String backupFileName = "zoo.cfg.bak";
    +
    +    Map<Integer, Integer> clientPorts = new HashMap<>(5);
    +    Map<Integer, String> serverAddress = new HashMap<>(5);
    +
    +    private String generateNewQuorumConfig(int serverCount) {
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +        for (int i = 0; i < serverCount; i++) {
    +            clientPorts.put(i, PortAssignment.unique());
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(i);
    +            serverAddress.put(i, server);
    +            sb.append(server + "\n");
    +        }
    +        return sb.toString();
    +    }
    +
    +    private String updateExistingQuorumConfig(List<Integer> sidsToAdd, List<Integer> sidsToRemove) {
    +        StringBuilder sb = new StringBuilder();
    +        for (Integer sid : sidsToAdd) {
    +            clientPorts.put(sid, PortAssignment.unique());
    +            serverAddress.put(sid, "server." + sid + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(sid));
    +        }
    +
    +        for (Integer sid : sidsToRemove) {
    +            clientPorts.remove(sid);
    +            serverAddress.remove(sid);
    +        }
    +
    +        for (String server : serverAddress.values()) {
    +            sb.append(server + "\n");
    +        }
    +
    +        return sb.toString();
    +    }
    +
    +    @Test(timeout = 60000)
    +    // Verify no zoo.cfg.dynamic and zoo.cfg.bak files existing locally
    +    // when reconfig feature flag is off by default.
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        String[] staticFileContent = new String[serverCount];
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(backupFileName));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverAddress.get(i),
    +                    staticFileContent[i].contains(serverAddress.get(i)));
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    // This test simulate the usual rolling restart with no membership change:
    +    // 1. A node is shutdown first (e.g. to upgrade software, or hardware, or cleanup local data.).
    +    // 2. After upgrade, start the node.
    +    // 3. Do this for every node, one at a time.
    +    public void testRollingRestartWithoutMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +            mt[i].start();
    +            verifyQuorum(i);
    --- End diff --
    
    for 1 - for this specific case this is fine, because this test case does not change setting of the reconfig flag (from false to true or vice versa) so there is no concern on that end. shutdown is synchronous so once shutdown finishes, it's safe to call start. 
    
    I think your concern was around the visibility of a shared variable among multiple threads (in this case, reconfigEnabled). Adding volatile should address the concern (also a new test case specifically to test the visibility of the variable is required.). I will do this as part of sub-task ZOOKEEPER-2828.
    
    For 2, yes as the test name implies, no config changes here. I guess I can remove the config verify part here though leave it there for insurance seems ok too.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r124396899
  
    --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java ---
    @@ -1744,9 +1744,14 @@ public void setAcceptedEpoch(long e) throws IOException {
         public boolean processReconfig(QuorumVerifier qv, Long suggestedLeaderId, Long zxid, boolean restartLE) {
            InetSocketAddress oldClientAddr = getClientAddress();
     
    +       boolean isReconfigEnabled = QuorumPeerConfig.isReconfigEnabled();
            // update last committed quorum verifier, write the new config to disk
    -       // and restart leader election if config changed
    -       QuorumVerifier prevQV = setQuorumVerifier(qv, true);
    +       // and restart leader election if config changed. If reconfig feature is
    +       // not enabled, just set last committed quorum verifier and bail out.
    +       QuorumVerifier prevQV = setQuorumVerifier(qv, isReconfigEnabled);
    --- End diff --
    
    Updated. Now I am returning immediately at the start of processReconfig if the feature flag is not set. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125126799
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,275 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.WatchedEvent;
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.CreateMode;
    +import org.apache.zookeeper.ZooDefs;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.KeeperException;
    +import org.apache.zookeeper.Watcher;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String backupFileName = "zoo.cfg.bak";
    +
    +    Map<Integer, Integer> clientPorts = new HashMap<>(5);
    +    Map<Integer, String> serverAddress = new HashMap<>(5);
    +
    +    private String generateNewQuorumConfig(int serverCount) {
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +        for (int i = 0; i < serverCount; i++) {
    +            clientPorts.put(i, PortAssignment.unique());
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(i);
    +            serverAddress.put(i, server);
    +            sb.append(server + "\n");
    +        }
    +        return sb.toString();
    +    }
    +
    +    private String updateExistingQuorumConfig(List<Integer> sidsToAdd, List<Integer> sidsToRemove) {
    +        StringBuilder sb = new StringBuilder();
    +        for (Integer sid : sidsToAdd) {
    +            clientPorts.put(sid, PortAssignment.unique());
    +            serverAddress.put(sid, "server." + sid + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(sid));
    +        }
    +
    +        for (Integer sid : sidsToRemove) {
    +            clientPorts.remove(sid);
    +            serverAddress.remove(sid);
    +        }
    +
    +        for (String server : serverAddress.values()) {
    +            sb.append(server + "\n");
    +        }
    +
    +        return sb.toString();
    +    }
    +
    +    @Test(timeout = 60000)
    +    // Verify no zoo.cfg.dynamic and zoo.cfg.bak files existing locally
    +    // when reconfig feature flag is off by default.
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        String[] staticFileContent = new String[serverCount];
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(backupFileName));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverAddress.get(i),
    +                    staticFileContent[i].contains(serverAddress.get(i)));
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    // This test simulate the usual rolling restart with no membership change:
    +    // 1. A node is shutdown first (e.g. to upgrade software, or hardware, or cleanup local data.).
    +    // 2. After upgrade, start the node.
    +    // 3. Do this for every node, one at a time.
    +    public void testRollingRestartWithoutMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +            mt[i].start();
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 90000)
    +    // This test simulate the use case of change of membership through rolling
    +    // restart. For a 3 node ensemble we expand it to a 5 node ensemble, verify
    +    // during the process each node has the expected configuration setting pushed
    +    // via updating local zoo.cfg file.
    +    public void testRollingRestartWithMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        Map<Integer, String> oldServerAddress = new HashMap<>(serverAddress);
    +        config = updateExistingQuorumConfig(Arrays.asList(3, 4), new ArrayList<Integer>());
    +        serverCount = serverAddress.size();
    +        Assert.assertEquals("Server count should be 5 after config update.", serverCount, 5);
    +
    +        mt = Arrays.copyOf(mt, mt.length + 2);
    +        for (int i = 3; i < 5; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            verifyConfig(mt[i]);
    +            verifyQuorum(i);
    +        }
    +
    +        Set<String> expectedConfigs = new HashSet<>();
    +        for (String conf : oldServerAddress.values()) {
    +            // Remove "server.x=" prefix.
    +            expectedConfigs.add(conf.substring(9));
    --- End diff --
    
    same comment - using 9 seems fragile. Also perhaps create a method for this since this code appears twice


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125127752
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,275 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.WatchedEvent;
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.CreateMode;
    +import org.apache.zookeeper.ZooDefs;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.KeeperException;
    +import org.apache.zookeeper.Watcher;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String backupFileName = "zoo.cfg.bak";
    +
    +    Map<Integer, Integer> clientPorts = new HashMap<>(5);
    +    Map<Integer, String> serverAddress = new HashMap<>(5);
    +
    +    private String generateNewQuorumConfig(int serverCount) {
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +        for (int i = 0; i < serverCount; i++) {
    +            clientPorts.put(i, PortAssignment.unique());
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(i);
    +            serverAddress.put(i, server);
    +            sb.append(server + "\n");
    +        }
    +        return sb.toString();
    +    }
    +
    +    private String updateExistingQuorumConfig(List<Integer> sidsToAdd, List<Integer> sidsToRemove) {
    +        StringBuilder sb = new StringBuilder();
    +        for (Integer sid : sidsToAdd) {
    +            clientPorts.put(sid, PortAssignment.unique());
    +            serverAddress.put(sid, "server." + sid + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(sid));
    +        }
    +
    +        for (Integer sid : sidsToRemove) {
    +            clientPorts.remove(sid);
    +            serverAddress.remove(sid);
    +        }
    +
    +        for (String server : serverAddress.values()) {
    +            sb.append(server + "\n");
    +        }
    +
    +        return sb.toString();
    +    }
    +
    +    @Test(timeout = 60000)
    +    // Verify no zoo.cfg.dynamic and zoo.cfg.bak files existing locally
    +    // when reconfig feature flag is off by default.
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        String[] staticFileContent = new String[serverCount];
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(backupFileName));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverAddress.get(i),
    +                    staticFileContent[i].contains(serverAddress.get(i)));
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    // This test simulate the usual rolling restart with no membership change:
    +    // 1. A node is shutdown first (e.g. to upgrade software, or hardware, or cleanup local data.).
    +    // 2. After upgrade, start the node.
    +    // 3. Do this for every node, one at a time.
    +    public void testRollingRestartWithoutMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +            mt[i].start();
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 90000)
    +    // This test simulate the use case of change of membership through rolling
    +    // restart. For a 3 node ensemble we expand it to a 5 node ensemble, verify
    +    // during the process each node has the expected configuration setting pushed
    +    // via updating local zoo.cfg file.
    +    public void testRollingRestartWithMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        Map<Integer, String> oldServerAddress = new HashMap<>(serverAddress);
    +        config = updateExistingQuorumConfig(Arrays.asList(3, 4), new ArrayList<Integer>());
    +        serverCount = serverAddress.size();
    +        Assert.assertEquals("Server count should be 5 after config update.", serverCount, 5);
    +
    +        mt = Arrays.copyOf(mt, mt.length + 2);
    --- End diff --
    
    Please add a comment here to say that the new servers should have a config with all five servers, and the old servers a config with 3 servers.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125124612
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,275 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.WatchedEvent;
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.CreateMode;
    +import org.apache.zookeeper.ZooDefs;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.KeeperException;
    +import org.apache.zookeeper.Watcher;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String backupFileName = "zoo.cfg.bak";
    +
    +    Map<Integer, Integer> clientPorts = new HashMap<>(5);
    +    Map<Integer, String> serverAddress = new HashMap<>(5);
    +
    +    private String generateNewQuorumConfig(int serverCount) {
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +        for (int i = 0; i < serverCount; i++) {
    +            clientPorts.put(i, PortAssignment.unique());
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(i);
    +            serverAddress.put(i, server);
    +            sb.append(server + "\n");
    +        }
    +        return sb.toString();
    +    }
    +
    +    private String updateExistingQuorumConfig(List<Integer> sidsToAdd, List<Integer> sidsToRemove) {
    +        StringBuilder sb = new StringBuilder();
    +        for (Integer sid : sidsToAdd) {
    +            clientPorts.put(sid, PortAssignment.unique());
    +            serverAddress.put(sid, "server." + sid + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(sid));
    +        }
    +
    +        for (Integer sid : sidsToRemove) {
    +            clientPorts.remove(sid);
    +            serverAddress.remove(sid);
    +        }
    +
    +        for (String server : serverAddress.values()) {
    +            sb.append(server + "\n");
    +        }
    +
    +        return sb.toString();
    +    }
    +
    +    @Test(timeout = 60000)
    +    // Verify no zoo.cfg.dynamic and zoo.cfg.bak files existing locally
    +    // when reconfig feature flag is off by default.
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        String[] staticFileContent = new String[serverCount];
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(backupFileName));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverAddress.get(i),
    +                    staticFileContent[i].contains(serverAddress.get(i)));
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    // This test simulate the usual rolling restart with no membership change:
    +    // 1. A node is shutdown first (e.g. to upgrade software, or hardware, or cleanup local data.).
    +    // 2. After upgrade, start the node.
    +    // 3. Do this for every node, one at a time.
    +    public void testRollingRestartWithoutMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +            mt[i].start();
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 90000)
    +    // This test simulate the use case of change of membership through rolling
    +    // restart. For a 3 node ensemble we expand it to a 5 node ensemble, verify
    +    // during the process each node has the expected configuration setting pushed
    +    // via updating local zoo.cfg file.
    +    public void testRollingRestartWithMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        Map<Integer, String> oldServerAddress = new HashMap<>(serverAddress);
    +        config = updateExistingQuorumConfig(Arrays.asList(3, 4), new ArrayList<Integer>());
    +        serverCount = serverAddress.size();
    +        Assert.assertEquals("Server count should be 5 after config update.", serverCount, 5);
    +
    +        mt = Arrays.copyOf(mt, mt.length + 2);
    +        for (int i = 3; i < 5; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            verifyConfig(mt[i]);
    +            verifyQuorum(i);
    +        }
    +
    +        Set<String> expectedConfigs = new HashSet<>();
    +        for (String conf : oldServerAddress.values()) {
    +            // Remove "server.x=" prefix.
    +            expectedConfigs.add(conf.substring(9));
    +        }
    +
    +        for (int i = 0; i < 3; ++i) {
    +            verifyConfig(mt[i], expectedConfigs);
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    // A successful write operation indicates a quorum is up.
    +    private void verifyQuorum(int sid)
    --- End diff --
    
    Can you reuse some helper methods from ReconfigTest.java ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125173093
  
    --- Diff: src/java/main/org/apache/zookeeper/server/quorum/Learner.java ---
    @@ -374,6 +374,13 @@ else if (qp.getType() == Leader.SNAP) {
                     // The leader is going to dump the database
                     // db is clear as part of deserializeSnapshot()
                     zk.getZKDatabase().deserializeSnapshot(leaderIs);
    +                // ZOOKEEPER-2819: overwrite config node content extracted
    +                // from leader snapshot with local config, to avoid potential
    +                // inconsistency of config node content during rolling restart.
    +                if (!QuorumPeerConfig.isReconfigEnabled()) {
    --- End diff --
    
    @shralex instead of avoiding deserializing the config zNode we could overwrite the deserialized zNode content with local quorum config. Test will be covered in the test improvement JIRA ZOOKEEPER-2828.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper issue #292: ZOOKEEPER-2819:Changing membership configuration via r...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on the issue:

    https://github.com/apache/zookeeper/pull/292
  
    LGTM


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125805265
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,263 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.apache.zookeeper.test.ReconfigTest;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String ZOO_CFG_BAK_FILE = "zoo.cfg.bak";
    +
    +    Map<Integer, Integer> clientPorts = new HashMap<>(5);
    +    Map<Integer, String> serverAddress = new HashMap<>(5);
    +
    +    private String generateNewQuorumConfig(int serverCount) {
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +        for (int i = 0; i < serverCount; i++) {
    +            clientPorts.put(i, PortAssignment.unique());
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(i);
    +            serverAddress.put(i, server);
    +            sb.append(server + "\n");
    +        }
    +        return sb.toString();
    +    }
    +
    +    private String updateExistingQuorumConfig(List<Integer> sidsToAdd, List<Integer> sidsToRemove) {
    +        StringBuilder sb = new StringBuilder();
    +        for (Integer sid : sidsToAdd) {
    +            clientPorts.put(sid, PortAssignment.unique());
    +            serverAddress.put(sid, "server." + sid + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(sid));
    +        }
    +
    +        for (Integer sid : sidsToRemove) {
    +            clientPorts.remove(sid);
    +            serverAddress.remove(sid);
    +        }
    +
    +        for (String server : serverAddress.values()) {
    +            sb.append(server + "\n");
    +        }
    +
    +        return sb.toString();
    +    }
    +
    +    @Test(timeout = 60000)
    +    // Verify no zoo.cfg.dynamic and zoo.cfg.bak files existing locally
    +    // when reconfig feature flag is off by default.
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        String[] staticFileContent = new String[serverCount];
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(ZOO_CFG_BAK_FILE));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverAddress.get(i),
    +                    staticFileContent[i].contains(serverAddress.get(i)));
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    // This test simulate the usual rolling restart with no membership change:
    +    // 1. A node is shutdown first (e.g. to upgrade software, or hardware, or cleanup local data.).
    +    // 2. After upgrade, start the node.
    +    // 3. Do this for every node, one at a time.
    +    public void testRollingRestartWithoutMembershipChange() throws Exception {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        List<String> joiningServers = new ArrayList<>();
    +        List<String> leavingServers = new ArrayList<>();
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +            joiningServers.add(serverAddress.get(i));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +            mt[i].start();
    +            verifyQuorumConfig(i, joiningServers, leavingServers);
    --- End diff --
    
    you can remove the leavingServers variable and pass null here. Same in the other test


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper issue #292: ZOOKEEPER-2819:Changing membership configuration via r...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on the issue:

    https://github.com/apache/zookeeper/pull/292
  
    Added test cases to cover rolling restart. The pre-commit Jenkins failure is a known flaky test.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper issue #292: ZOOKEEPER-2819:Changing membership configuration via r...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on the issue:

    https://github.com/apache/zookeeper/pull/292
  
    @shralex The snapshot and sync tests will be covered in ZOOKEEPER-2828. I will update the PR shortly to address other comments.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125806082
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,263 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.apache.zookeeper.test.ReconfigTest;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String ZOO_CFG_BAK_FILE = "zoo.cfg.bak";
    +
    +    Map<Integer, Integer> clientPorts = new HashMap<>(5);
    +    Map<Integer, String> serverAddress = new HashMap<>(5);
    +
    +    private String generateNewQuorumConfig(int serverCount) {
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +        for (int i = 0; i < serverCount; i++) {
    +            clientPorts.put(i, PortAssignment.unique());
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(i);
    +            serverAddress.put(i, server);
    +            sb.append(server + "\n");
    +        }
    +        return sb.toString();
    +    }
    +
    +    private String updateExistingQuorumConfig(List<Integer> sidsToAdd, List<Integer> sidsToRemove) {
    +        StringBuilder sb = new StringBuilder();
    +        for (Integer sid : sidsToAdd) {
    +            clientPorts.put(sid, PortAssignment.unique());
    +            serverAddress.put(sid, "server." + sid + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(sid));
    +        }
    +
    +        for (Integer sid : sidsToRemove) {
    +            clientPorts.remove(sid);
    +            serverAddress.remove(sid);
    +        }
    +
    +        for (String server : serverAddress.values()) {
    +            sb.append(server + "\n");
    +        }
    +
    +        return sb.toString();
    +    }
    +
    +    @Test(timeout = 60000)
    +    // Verify no zoo.cfg.dynamic and zoo.cfg.bak files existing locally
    +    // when reconfig feature flag is off by default.
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        String[] staticFileContent = new String[serverCount];
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(ZOO_CFG_BAK_FILE));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverAddress.get(i),
    +                    staticFileContent[i].contains(serverAddress.get(i)));
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    // This test simulate the usual rolling restart with no membership change:
    +    // 1. A node is shutdown first (e.g. to upgrade software, or hardware, or cleanup local data.).
    +    // 2. After upgrade, start the node.
    +    // 3. Do this for every node, one at a time.
    +    public void testRollingRestartWithoutMembershipChange() throws Exception {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        List<String> joiningServers = new ArrayList<>();
    +        List<String> leavingServers = new ArrayList<>();
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +            joiningServers.add(serverAddress.get(i));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +            mt[i].start();
    +            verifyQuorumConfig(i, joiningServers, leavingServers);
    +            verifyQuorumMembers(mt[i]);
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 90000)
    +    // This test simulate the use case of change of membership through rolling
    +    // restart. For a 3 node ensemble we expand it to a 5 node ensemble, verify
    +    // during the process each node has the expected configuration setting pushed
    +    // via updating local zoo.cfg file.
    +    public void testRollingRestartWithMembershipChange() throws Exception {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        List<String> joiningServers = new ArrayList<>();
    +        List<String> leavingServers = new ArrayList<>();
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +            joiningServers.add(serverAddress.get(i));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            verifyQuorumConfig(i, joiningServers, leavingServers);
    +            verifyQuorumMembers(mt[i]);
    +        }
    +
    +        Map<Integer, String> oldServerAddress = new HashMap<>(serverAddress);
    +        List<String> newServers = new ArrayList<>(joiningServers);
    +        newServers.add("3"); newServers.add("4");
    --- End diff --
    
    move this one line down until after you have the actual addresses, then put the actual config lines of 3 and 4 into newServers


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper issue #292: ZOOKEEPER-2819:Changing membership configuration via r...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on the issue:

    https://github.com/apache/zookeeper/pull/292
  
    Thanks for review, @shralex @asdf2014 . Code updated. 
    
    I also refactored a couple of reconfig tests to consolidate the setting of the feature flag, which makes the test both easier to read and also fix potential race conditions I found out while working on this patch: because the flag was set in a different thread while the peers are running, it is possible the peer thread still cache old value. Such case would not happen for real use case (aside from artificial tests we created here) because the feature flag will not change after ensemble is started. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by hanm <gi...@git.apache.org>.
Github user hanm commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125132133
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,275 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.WatchedEvent;
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.CreateMode;
    +import org.apache.zookeeper.ZooDefs;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.KeeperException;
    +import org.apache.zookeeper.Watcher;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String backupFileName = "zoo.cfg.bak";
    +
    +    Map<Integer, Integer> clientPorts = new HashMap<>(5);
    +    Map<Integer, String> serverAddress = new HashMap<>(5);
    +
    +    private String generateNewQuorumConfig(int serverCount) {
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +        for (int i = 0; i < serverCount; i++) {
    +            clientPorts.put(i, PortAssignment.unique());
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(i);
    +            serverAddress.put(i, server);
    +            sb.append(server + "\n");
    +        }
    +        return sb.toString();
    +    }
    +
    +    private String updateExistingQuorumConfig(List<Integer> sidsToAdd, List<Integer> sidsToRemove) {
    +        StringBuilder sb = new StringBuilder();
    +        for (Integer sid : sidsToAdd) {
    +            clientPorts.put(sid, PortAssignment.unique());
    +            serverAddress.put(sid, "server." + sid + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(sid));
    +        }
    +
    +        for (Integer sid : sidsToRemove) {
    +            clientPorts.remove(sid);
    +            serverAddress.remove(sid);
    +        }
    +
    +        for (String server : serverAddress.values()) {
    +            sb.append(server + "\n");
    +        }
    +
    +        return sb.toString();
    +    }
    +
    +    @Test(timeout = 60000)
    +    // Verify no zoo.cfg.dynamic and zoo.cfg.bak files existing locally
    +    // when reconfig feature flag is off by default.
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        String[] staticFileContent = new String[serverCount];
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(backupFileName));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverAddress.get(i),
    +                    staticFileContent[i].contains(serverAddress.get(i)));
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    // This test simulate the usual rolling restart with no membership change:
    +    // 1. A node is shutdown first (e.g. to upgrade software, or hardware, or cleanup local data.).
    +    // 2. After upgrade, start the node.
    +    // 3. Do this for every node, one at a time.
    +    public void testRollingRestartWithoutMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +            mt[i].start();
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 90000)
    +    // This test simulate the use case of change of membership through rolling
    +    // restart. For a 3 node ensemble we expand it to a 5 node ensemble, verify
    +    // during the process each node has the expected configuration setting pushed
    +    // via updating local zoo.cfg file.
    +    public void testRollingRestartWithMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        Map<Integer, String> oldServerAddress = new HashMap<>(serverAddress);
    +        config = updateExistingQuorumConfig(Arrays.asList(3, 4), new ArrayList<Integer>());
    +        serverCount = serverAddress.size();
    +        Assert.assertEquals("Server count should be 5 after config update.", serverCount, 5);
    +
    +        mt = Arrays.copyOf(mt, mt.length + 2);
    +        for (int i = 3; i < 5; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            verifyConfig(mt[i]);
    +            verifyQuorum(i);
    +        }
    +
    +        Set<String> expectedConfigs = new HashSet<>();
    +        for (String conf : oldServerAddress.values()) {
    +            // Remove "server.x=" prefix.
    +            expectedConfigs.add(conf.substring(9));
    +        }
    +
    +        for (int i = 0; i < 3; ++i) {
    +            verifyConfig(mt[i], expectedConfigs);
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    // A successful write operation indicates a quorum is up.
    +    private void verifyQuorum(int sid)
    --- End diff --
    
    I missed testServerHasConfig - I think that should do it. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125126374
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,275 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.WatchedEvent;
    +import org.apache.zookeeper.ZooKeeper;
    +import org.apache.zookeeper.CreateMode;
    +import org.apache.zookeeper.ZooDefs;
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.KeeperException;
    +import org.apache.zookeeper.Watcher;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String backupFileName = "zoo.cfg.bak";
    +
    +    Map<Integer, Integer> clientPorts = new HashMap<>(5);
    +    Map<Integer, String> serverAddress = new HashMap<>(5);
    +
    +    private String generateNewQuorumConfig(int serverCount) {
    +        StringBuilder sb = new StringBuilder();
    +        String server;
    +        for (int i = 0; i < serverCount; i++) {
    +            clientPorts.put(i, PortAssignment.unique());
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(i);
    +            serverAddress.put(i, server);
    +            sb.append(server + "\n");
    +        }
    +        return sb.toString();
    +    }
    +
    +    private String updateExistingQuorumConfig(List<Integer> sidsToAdd, List<Integer> sidsToRemove) {
    +        StringBuilder sb = new StringBuilder();
    +        for (Integer sid : sidsToAdd) {
    +            clientPorts.put(sid, PortAssignment.unique());
    +            serverAddress.put(sid, "server." + sid + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts.get(sid));
    +        }
    +
    +        for (Integer sid : sidsToRemove) {
    +            clientPorts.remove(sid);
    +            serverAddress.remove(sid);
    +        }
    +
    +        for (String server : serverAddress.values()) {
    +            sb.append(server + "\n");
    +        }
    +
    +        return sb.toString();
    +    }
    +
    +    @Test(timeout = 60000)
    +    // Verify no zoo.cfg.dynamic and zoo.cfg.bak files existing locally
    +    // when reconfig feature flag is off by default.
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        String[] staticFileContent = new String[serverCount];
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(backupFileName));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverAddress.get(i),
    +                    staticFileContent[i].contains(serverAddress.get(i)));
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    // This test simulate the usual rolling restart with no membership change:
    +    // 1. A node is shutdown first (e.g. to upgrade software, or hardware, or cleanup local data.).
    +    // 2. After upgrade, start the node.
    +    // 3. Do this for every node, one at a time.
    +    public void testRollingRestartWithoutMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +            mt[i].start();
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        for (int i = 0; i < serverCount; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    @Test(timeout = 90000)
    +    // This test simulate the use case of change of membership through rolling
    +    // restart. For a 3 node ensemble we expand it to a 5 node ensemble, verify
    +    // during the process each node has the expected configuration setting pushed
    +    // via updating local zoo.cfg file.
    +    public void testRollingRestartWithMembershipChange()
    +            throws IOException, InterruptedException, KeeperException {
    +        int serverCount = 3;
    +        String config = generateNewQuorumConfig(serverCount);
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[serverCount];
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            verifyQuorum(i);
    +            verifyConfig(mt[i]);
    +        }
    +
    +        Map<Integer, String> oldServerAddress = new HashMap<>(serverAddress);
    +        config = updateExistingQuorumConfig(Arrays.asList(3, 4), new ArrayList<Integer>());
    +        serverCount = serverAddress.size();
    +        Assert.assertEquals("Server count should be 5 after config update.", serverCount, 5);
    +
    +        mt = Arrays.copyOf(mt, mt.length + 2);
    +        for (int i = 3; i < 5; ++i) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts.get(i),
    +                    config, false);
    +            mt[i].start();
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts.get(i),
    +                            CONNECTION_TIMEOUT));
    +            verifyConfig(mt[i]);
    +            verifyQuorum(i);
    +        }
    +
    +        Set<String> expectedConfigs = new HashSet<>();
    +        for (String conf : oldServerAddress.values()) {
    +            // Remove "server.x=" prefix.
    +            expectedConfigs.add(conf.substring(9));
    +        }
    +
    +        for (int i = 0; i < 3; ++i) {
    +            verifyConfig(mt[i], expectedConfigs);
    +        }
    +
    +        for (int i = 0; i < serverCount; ++i) {
    +            mt[i].shutdown();
    +        }
    +    }
    +
    +    // A successful write operation indicates a quorum is up.
    +    private void verifyQuorum(int sid)
    +            throws IOException, InterruptedException, KeeperException {
    +        ZooKeeper zk = new ZooKeeper("127.0.0.1:" + clientPorts.get(sid),
    +                ClientBase.CONNECTION_TIMEOUT, new Watcher() {
    +            public void process(WatchedEvent event) {
    +            }});
    +
    +        for (int j = 0; j < 30; j++) {
    +            try {
    +                zk.create("/" + Integer.toString(sid) + "." + Math.random(),
    +                        "foobar".getBytes(),
    +                        ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    +                break;
    +            } catch (KeeperException.ConnectionLossException e) {
    +                if (j < 29) {
    +                    Thread.sleep(1000);
    +                } else {
    +                    Assert.fail("client could not connect to reestablished quorum: " +
    +                            "giving up after 30+ seconds.");
    +                }
    +            }
    +        }
    +    }
    +
    +    private void verifyConfig(QuorumPeerTestBase.MainThread mt) {
    +        Set<String> expectedConfigs = new HashSet<>();
    +        for (String config : serverAddress.values()) {
    +            // Remove "server.x=" prefix.
    +            expectedConfigs.add(config.substring(9));
    --- End diff --
    
    this seems fragile (works only for single digit ids, perhaps use the index of "="


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper issue #292: ZOOKEEPER-2819:Changing membership configuration via r...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on the issue:

    https://github.com/apache/zookeeper/pull/292
  
    Michael, thanks for the changes. Do we need some tests that can catch the issue I pointed out - one server is getting rebooted with a new config file, but other servers push old config to that server, need to make sure that it actually acts upon or has the config its supposed to have. Two scenarios - config pushed durning leader sync, and config pushed during leader election (in FastLeaderElection.java). Perhaps you're already doing this, I haven't looked.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by asdf2014 <gi...@git.apache.org>.
Github user asdf2014 commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r124185161
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,94 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +
    +import org.apache.zookeeper.PortAssignment;
    +import org.apache.zookeeper.test.ClientBase;
    +import org.junit.Assert;
    +import org.junit.Before;
    +import org.junit.Test;
    +
    +import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
    +
    +/**
    + * ReconfigRollingRestartCompatibilityTest - we want to make sure that users
    + * can continue using the rolling restart approach when reconfig feature is disabled.
    + * It is important to stay compatible with rolling restart because dynamic reconfig
    + * has its limitation: it requires a quorum of server to work. When no quorum can be formed,
    + * rolling restart is the only approach to reconfigure the ensemble (e.g. removing bad nodes
    + * such that a new quorum with smaller number of nodes can be formed.).
    + *
    + * See ZOOKEEPER-2819 for more details.
    + */
    +public class ReconfigRollingRestartCompatibilityTest extends QuorumPeerTestBase {
    +    private static final String backupFileName = "zoo.cfg.bak";
    +
    +    final int SERVER_COUNT = 3;
    +    final int clientPorts[] = new int[SERVER_COUNT];
    +    final String serverList[] = new String[SERVER_COUNT];
    +    StringBuilder sb = new StringBuilder();
    +
    +    @Before
    +    public void setup() throws InterruptedException {
    +        String server;
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            clientPorts[i] = PortAssignment.unique();
    +            server = "server." + i + "=localhost:" + PortAssignment.unique()
    +                    + ":" + PortAssignment.unique() + ":participant;localhost:"
    +                    + clientPorts[i];
    +            serverList[i] = server;
    +            sb.append(server + "\n");
    +        }
    +    }
    +
    +    @Test(timeout = 60000)
    +    public void testNoLocalDynamicConfigAndBackupFiles()
    +            throws InterruptedException, IOException {
    +        String currentQuorumCfgSection = sb.toString();
    +        QuorumPeerTestBase.MainThread mt[] = new QuorumPeerTestBase.MainThread[SERVER_COUNT];
    +        String[] staticFileContent = new String[SERVER_COUNT];
    +
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            mt[i] = new QuorumPeerTestBase.MainThread(i, clientPorts[i],
    +                    currentQuorumCfgSection, false);
    +            mt[i].start();
    +        }
    +
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            Assert.assertTrue("waiting for server " + i + " being up",
    +                    ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i],
    +                            CONNECTION_TIMEOUT));
    +            Assert.assertNull("static file backup (zoo.cfg.bak) shouldn't exist!",
    +                    mt[i].getFileByName(backupFileName));
    +            Assert.assertNull("dynamic configuration file (zoo.cfg.dynamic.*) shouldn't exist!",
    +                    mt[i].getFileByName(mt[i].getQuorumPeer().getNextDynamicConfigFilename()));
    +            staticFileContent[i] = Files.readAllLines(mt[i].confFile.toPath(), StandardCharsets.UTF_8).toString();
    +            Assert.assertTrue("static config file should contain server entry " + serverList[i],
    +                    staticFileContent[i].contains(serverList[i]));
    +        }
    +
    +        for (int i = 0; i < SERVER_COUNT; i++) {
    +            mt[i].shutdown();
    +        }
    +    }
    +}
    --- End diff --
    
    Should add a new line for the end of file.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] zookeeper pull request #292: ZOOKEEPER-2819:Changing membership configuratio...

Posted by shralex <gi...@git.apache.org>.
Github user shralex commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/292#discussion_r125806125
  
    --- Diff: src/java/test/org/apache/zookeeper/server/quorum/ReconfigRollingRestartCompatibilityTest.java ---
    @@ -0,0 +1,263 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.zookeeper.server.quorum;
    +
    +import java.io.IOException;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.List;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.ArrayList;
    +
    +import org.apache.zookeeper.ZooKeeper;
    --- End diff --
    
    you don't really need leavingServers - you can pass null instead of it in all the tests since no one is leaving


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---