Repository: zookeeper Updated Branches: refs/heads/branch-3.5 91c400829 -> 0ba7eda90
ZOOKEEPER-2642: ZooKeeper reconfig API backward compatibility fix. New PR that applies ZOOKEEPER-2642 to `branch-3.5` Author: randgalt <[email protected]> Reviewers: Michael Han <[email protected]> Closes #151 from Randgalt/ZOOKEEPER-2642-3.5 Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/0ba7eda9 Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/0ba7eda9 Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/0ba7eda9 Branch: refs/heads/branch-3.5 Commit: 0ba7eda90199edb4a3d3a06b236020608660f48e Parents: 91c4008 Author: randgalt <[email protected]> Authored: Sat Feb 11 15:31:29 2017 -0800 Committer: Michael Han <[email protected]> Committed: Sat Feb 11 15:31:29 2017 -0800 ---------------------------------------------------------------------- .../content/xdocs/zookeeperReconfig.xml | 5 ++ .../main/org/apache/zookeeper/ZooKeeper.java | 80 +++++++++++++++++++- .../apache/zookeeper/admin/ZooKeeperAdmin.java | 63 +++++---------- .../apache/zookeeper/cli/ReconfigCommand.java | 2 +- .../quorum/ReconfigDuringLeaderSyncTest.java | 2 +- .../server/quorum/ReconfigFailureCasesTest.java | 10 +-- .../server/quorum/StandaloneDisabledTest.java | 2 +- .../zookeeper/test/ReconfigExceptionTest.java | 2 +- .../zookeeper/test/ReconfigMisconfigTest.java | 2 +- .../org/apache/zookeeper/test/ReconfigTest.java | 4 +- .../apache/zookeeper/test/StandaloneTest.java | 2 +- 11 files changed, 114 insertions(+), 60 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/docs/src/documentation/content/xdocs/zookeeperReconfig.xml ---------------------------------------------------------------------- diff --git a/src/docs/src/documentation/content/xdocs/zookeeperReconfig.xml b/src/docs/src/documentation/content/xdocs/zookeeperReconfig.xml index c1c9ad7..5dd6c9e 100644 --- a/src/docs/src/documentation/content/xdocs/zookeeperReconfig.xml +++ b/src/docs/src/documentation/content/xdocs/zookeeperReconfig.xml @@ -300,6 +300,11 @@ server.3=125.23.63.25:2782:2785:participant</programlisting> from ZooKeeper class, and use of this API requires ACL setup and user authentication (see <xref linkend="sc_reconfig_access_control"/> for more information.). </para> + + <para>Note: for temporary backward compatibility, the reconfig() APIs will remain in ZooKeeper.java + where they were for a few alpha versions of 3.5.x. However, these APIs are deprecated and users + should move to the reconfigure() APIs in ZooKeeperAdmin.java. + </para> </listitem> </varlistentry> http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/java/main/org/apache/zookeeper/ZooKeeper.java ---------------------------------------------------------------------- diff --git a/src/java/main/org/apache/zookeeper/ZooKeeper.java b/src/java/main/org/apache/zookeeper/ZooKeeper.java index 23c4e40..b8c8008 100644 --- a/src/java/main/org/apache/zookeeper/ZooKeeper.java +++ b/src/java/main/org/apache/zookeeper/ZooKeeper.java @@ -51,6 +51,7 @@ import org.apache.zookeeper.client.HostProvider; import org.apache.zookeeper.client.StaticHostProvider; import org.apache.zookeeper.client.ZooKeeperSaslClient; import org.apache.zookeeper.common.PathUtils; +import org.apache.zookeeper.common.StringUtils; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; import org.apache.zookeeper.proto.CheckWatchesRequest; @@ -67,6 +68,7 @@ import org.apache.zookeeper.proto.GetChildrenRequest; import org.apache.zookeeper.proto.GetChildrenResponse; import org.apache.zookeeper.proto.GetDataRequest; import org.apache.zookeeper.proto.GetDataResponse; +import org.apache.zookeeper.proto.ReconfigRequest; import org.apache.zookeeper.proto.RemoveWatchesRequest; import org.apache.zookeeper.proto.ReplyHeader; import org.apache.zookeeper.proto.RequestHeader; @@ -2134,7 +2136,42 @@ public class ZooKeeper implements AutoCloseable { public void getConfig(boolean watch, DataCallback cb, Object ctx) { getConfig(watch ? watchManager.defaultWatcher : null, cb, ctx); } - + + /** + * @deprecated instead use the reconfigure() methods instead in {@link org.apache.zookeeper.admin.ZooKeeperAdmin} + */ + @Deprecated + public byte[] reconfig(String joiningServers, String leavingServers, String newMembers, long fromConfig, Stat stat) throws KeeperException, InterruptedException { + return internalReconfig(joiningServers, leavingServers, newMembers, fromConfig, stat); + } + + /** + * @deprecated instead use the reconfigure() methods instead in {@link org.apache.zookeeper.admin.ZooKeeperAdmin} + */ + @Deprecated + public byte[] reconfig(List<String> joiningServers, List<String> leavingServers, List<String> newMembers, long fromConfig, Stat stat) throws KeeperException, InterruptedException { + return internalReconfig(joiningServers, leavingServers, newMembers, fromConfig, stat); + } + + /** + * @deprecated instead use the reconfigure() methods instead in {@link org.apache.zookeeper.admin.ZooKeeperAdmin} + */ + @Deprecated + public void reconfig(String joiningServers, String leavingServers, + String newMembers, long fromConfig, DataCallback cb, Object ctx) { + internalReconfig(joiningServers, leavingServers, newMembers, fromConfig, cb, ctx); + } + + /** + * @deprecated instead use the reconfigure() methods instead in {@link org.apache.zookeeper.admin.ZooKeeperAdmin} + */ + @Deprecated + public void reconfig(List<String> joiningServers, + List<String> leavingServers, List<String> newMembers, long fromConfig, + DataCallback cb, Object ctx) { + internalReconfig(joiningServers, leavingServers, newMembers, fromConfig, cb, ctx); + } + /** * Set the data for the node of the given path if such a node exists and the * given version matches the version of the node (if the given version is @@ -2869,4 +2906,45 @@ public class ZooKeeper implements AutoCloseable { throw ioe; } } + + protected byte[] internalReconfig(String joiningServers, String leavingServers, String newMembers, long fromConfig, Stat stat) throws KeeperException, InterruptedException { + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.reconfig); + ReconfigRequest request = new ReconfigRequest(joiningServers, leavingServers, newMembers, fromConfig); + GetDataResponse response = new GetDataResponse(); + ReplyHeader r = cnxn.submitRequest(h, request, response, null); + if (r.getErr() != 0) { + throw KeeperException.create(KeeperException.Code.get(r.getErr()), ""); + } + if (stat != null) { + DataTree.copyStat(response.getStat(), stat); + } + return response.getData(); + } + + protected byte[] internalReconfig(List<String> joiningServers, List<String> leavingServers, List<String> newMembers, long fromConfig, Stat stat) throws KeeperException, InterruptedException { + return internalReconfig(StringUtils.joinStrings(joiningServers, ","), + StringUtils.joinStrings(leavingServers, ","), + StringUtils.joinStrings(newMembers, ","), + fromConfig, stat); + } + + protected void internalReconfig(String joiningServers, String leavingServers, + String newMembers, long fromConfig, DataCallback cb, Object ctx) { + RequestHeader h = new RequestHeader(); + h.setType(ZooDefs.OpCode.reconfig); + ReconfigRequest request = new ReconfigRequest(joiningServers, leavingServers, newMembers, fromConfig); + GetDataResponse response = new GetDataResponse(); + cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, + ZooDefs.CONFIG_NODE, ZooDefs.CONFIG_NODE, ctx, null); + } + + protected void internalReconfig(List<String> joiningServers, + List<String> leavingServers, List<String> newMembers, long fromConfig, + DataCallback cb, Object ctx) { + internalReconfig(StringUtils.joinStrings(joiningServers, ","), + StringUtils.joinStrings(leavingServers, ","), + StringUtils.joinStrings(newMembers, ","), + fromConfig, cb, ctx); + } } http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/java/main/org/apache/zookeeper/admin/ZooKeeperAdmin.java ---------------------------------------------------------------------- diff --git a/src/java/main/org/apache/zookeeper/admin/ZooKeeperAdmin.java b/src/java/main/org/apache/zookeeper/admin/ZooKeeperAdmin.java index f60e8d5..a584132 100644 --- a/src/java/main/org/apache/zookeeper/admin/ZooKeeperAdmin.java +++ b/src/java/main/org/apache/zookeeper/admin/ZooKeeperAdmin.java @@ -22,18 +22,11 @@ import java.io.IOException; import java.util.List; import org.apache.zookeeper.ZooKeeper; -import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.AsyncCallback.DataCallback; import org.apache.zookeeper.client.ZKClientConfig; -import org.apache.zookeeper.common.StringUtils; import org.apache.zookeeper.data.Stat; -import org.apache.zookeeper.proto.GetDataResponse; -import org.apache.zookeeper.proto.ReconfigRequest; -import org.apache.zookeeper.proto.ReplyHeader; -import org.apache.zookeeper.proto.RequestHeader; -import org.apache.zookeeper.server.DataTree; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -172,66 +165,44 @@ public class ZooKeeperAdmin extends ZooKeeper { * @throws InterruptedException If the server transaction is interrupted. * @throws KeeperException If the server signals an error with a non-zero error code. */ - public byte[] reconfig(String joiningServers, String leavingServers, - String newMembers, long fromConfig, Stat stat) throws KeeperException, InterruptedException { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.reconfig); - ReconfigRequest request = new ReconfigRequest(joiningServers, leavingServers, newMembers, fromConfig); - GetDataResponse response = new GetDataResponse(); - ReplyHeader r = cnxn.submitRequest(h, request, response, null); - if (r.getErr() != 0) { - throw KeeperException.create(KeeperException.Code.get(r.getErr()), ""); - } - if (stat != null) { - DataTree.copyStat(response.getStat(), stat); - } - return response.getData(); + public byte[] reconfigure(String joiningServers, String leavingServers, + String newMembers, long fromConfig, Stat stat) throws KeeperException, InterruptedException { + return internalReconfig(joiningServers, leavingServers, newMembers, fromConfig, stat); } /** * Convenience wrapper around reconfig that takes Lists of strings instead of comma-separated servers. * - * @see #reconfig + * @see #reconfigure * */ - public byte[] reconfig(List<String> joiningServers, List<String> leavingServers, - List<String> newMembers, long fromConfig, - Stat stat) throws KeeperException, InterruptedException { - return reconfig(StringUtils.joinStrings(joiningServers, ","), - StringUtils.joinStrings(leavingServers, ","), - StringUtils.joinStrings(newMembers, ","), - fromConfig, stat); + public byte[] reconfigure(List<String> joiningServers, List<String> leavingServers, + List<String> newMembers, long fromConfig, + Stat stat) throws KeeperException, InterruptedException { + return internalReconfig(joiningServers, leavingServers, newMembers, fromConfig, stat); } /** * The Asynchronous version of reconfig. * - * @see #reconfig + * @see #reconfigure * **/ - public void reconfig(String joiningServers, String leavingServers, - String newMembers, long fromConfig, DataCallback cb, Object ctx) { - RequestHeader h = new RequestHeader(); - h.setType(ZooDefs.OpCode.reconfig); - ReconfigRequest request = new ReconfigRequest(joiningServers, leavingServers, newMembers, fromConfig); - GetDataResponse response = new GetDataResponse(); - cnxn.queuePacket(h, new ReplyHeader(), request, response, cb, - ZooDefs.CONFIG_NODE, ZooDefs.CONFIG_NODE, ctx, null); + public void reconfigure(String joiningServers, String leavingServers, + String newMembers, long fromConfig, DataCallback cb, Object ctx) { + internalReconfig(joiningServers, leavingServers, newMembers, fromConfig, cb, ctx); } /** * Convenience wrapper around asynchronous reconfig that takes Lists of strings instead of comma-separated servers. * - * @see #reconfig + * @see #reconfigure * */ - public void reconfig(List<String> joiningServers, - List<String> leavingServers, List<String> newMembers, long fromConfig, - DataCallback cb, Object ctx) { - reconfig(StringUtils.joinStrings(joiningServers, ","), - StringUtils.joinStrings(leavingServers, ","), - StringUtils.joinStrings(newMembers, ","), - fromConfig, cb, ctx); + public void reconfigure(List<String> joiningServers, + List<String> leavingServers, List<String> newMembers, long fromConfig, + DataCallback cb, Object ctx) { + internalReconfig(joiningServers, leavingServers, newMembers, fromConfig, cb, ctx); } /** http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/java/main/org/apache/zookeeper/cli/ReconfigCommand.java ---------------------------------------------------------------------- diff --git a/src/java/main/org/apache/zookeeper/cli/ReconfigCommand.java b/src/java/main/org/apache/zookeeper/cli/ReconfigCommand.java index a0709f3..342f5d2 100644 --- a/src/java/main/org/apache/zookeeper/cli/ReconfigCommand.java +++ b/src/java/main/org/apache/zookeeper/cli/ReconfigCommand.java @@ -154,7 +154,7 @@ public class ReconfigCommand extends CliCommand { return false; } - byte[] curConfig = ((ZooKeeperAdmin)zk).reconfig(joining, + byte[] curConfig = ((ZooKeeperAdmin)zk).reconfigure(joining, leaving, members, version, stat); out.println("Committed new configuration:\n" + new String(curConfig)); http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/java/test/org/apache/zookeeper/server/quorum/ReconfigDuringLeaderSyncTest.java ---------------------------------------------------------------------- diff --git a/src/java/test/org/apache/zookeeper/server/quorum/ReconfigDuringLeaderSyncTest.java b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigDuringLeaderSyncTest.java index 6da5181..f7f0c7c 100644 --- a/src/java/test/org/apache/zookeeper/server/quorum/ReconfigDuringLeaderSyncTest.java +++ b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigDuringLeaderSyncTest.java @@ -149,7 +149,7 @@ public class ReconfigDuringLeaderSyncTest extends QuorumPeerTestBase { // Leader.NEWLEADER while (true) { if (qp.isNewLeaderMessage()) { - preReconfigClient.reconfig(serverConfig[joinerId], null, null, -1, null, null); + preReconfigClient.reconfigure(serverConfig[joinerId], null, null, -1, null, null); break; } else { // sleep for 10 millisecond and then again check http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/java/test/org/apache/zookeeper/server/quorum/ReconfigFailureCasesTest.java ---------------------------------------------------------------------- diff --git a/src/java/test/org/apache/zookeeper/server/quorum/ReconfigFailureCasesTest.java b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigFailureCasesTest.java index e9263bc..8120d0f 100644 --- a/src/java/test/org/apache/zookeeper/server/quorum/ReconfigFailureCasesTest.java +++ b/src/java/test/org/apache/zookeeper/server/quorum/ReconfigFailureCasesTest.java @@ -91,7 +91,7 @@ public class ReconfigFailureCasesTest extends QuorumPeerTestBase { List<String> leavingServers = new ArrayList<String>(); leavingServers.add("3"); try { - zkAdminArr[1].reconfig(null, leavingServers, null, -1, null); + zkAdminArr[1].reconfigure(null, leavingServers, null, -1, null); Assert.fail("Reconfig should have failed since the current config isn't Majority QS"); } catch (KeeperException.BadArgumentsException e) { // We expect this to happen. @@ -121,7 +121,7 @@ public class ReconfigFailureCasesTest extends QuorumPeerTestBase { leavingServers.add("2"); leavingServers.add("3"); try { - zkAdminArr[1].reconfig(null, leavingServers, null, -1, null); + zkAdminArr[1].reconfigure(null, leavingServers, null, -1, null); Assert.fail("Reconfig should have failed since the current config version is not 8"); } catch (KeeperException.BadArgumentsException e) { // We expect this to happen. @@ -147,7 +147,7 @@ public class ReconfigFailureCasesTest extends QuorumPeerTestBase { List<String> leavingServers = new ArrayList<String>(); leavingServers.add("3"); try { - zkAdminArr[1].reconfig(null, leavingServers, null, 8, null); + zkAdminArr[1].reconfigure(null, leavingServers, null, 8, null); Assert.fail("Reconfig should have failed since the current config version is not 8"); } catch (KeeperException.BadVersionException e) { // We expect this to happen. @@ -182,7 +182,7 @@ public class ReconfigFailureCasesTest extends QuorumPeerTestBase { // We try to remove server 3, which requires a quorum of {1,2,3} // (we have that) and of {1,2}, but 2 is down so we won't get a // quorum of new config ACKs. - zkAdminArr[1].reconfig(null, leavingServers, null, -1, null); + zkAdminArr[1].reconfigure(null, leavingServers, null, -1, null); Assert.fail("Reconfig should have failed since we don't have quorum of new config"); } catch (KeeperException.ConnectionLossException e) { // We expect leader to lose quorum of proposed config and time out @@ -255,7 +255,7 @@ public class ReconfigFailureCasesTest extends QuorumPeerTestBase { } try { - zkAdmin[1].reconfig("", "", nextQuorumCfgSection, -1, new Stat()); + zkAdmin[1].reconfigure("", "", nextQuorumCfgSection, -1, new Stat()); Assert.fail("Reconfig should have failed with NewConfigNoQuorum"); } catch (NewConfigNoQuorum e) { // This is expected case since server 0 is down and 3 can't vote http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java ---------------------------------------------------------------------- diff --git a/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java b/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java index 9a85d77..34206cd 100644 --- a/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java +++ b/src/java/test/org/apache/zookeeper/server/quorum/StandaloneDisabledTest.java @@ -94,7 +94,7 @@ public class StandaloneDisabledTest extends QuorumPeerTestBase { reconfigServers.clear(); reconfigServers.add(Integer.toString(follower2)); try { - zkAdminHandles[follower2].reconfig(null, reconfigServers, null, -1, new Stat()); + zkAdminHandles[follower2].reconfigure(null, reconfigServers, null, -1, new Stat()); Assert.fail("reconfig completed successfully even though there is no quorum up in new config!"); } catch (KeeperException.BadArgumentsException e) { // This is expected. http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/java/test/org/apache/zookeeper/test/ReconfigExceptionTest.java ---------------------------------------------------------------------- diff --git a/src/java/test/org/apache/zookeeper/test/ReconfigExceptionTest.java b/src/java/test/org/apache/zookeeper/test/ReconfigExceptionTest.java index e56ae6f..c5b936d 100644 --- a/src/java/test/org/apache/zookeeper/test/ReconfigExceptionTest.java +++ b/src/java/test/org/apache/zookeeper/test/ReconfigExceptionTest.java @@ -214,7 +214,7 @@ public class ReconfigExceptionTest extends ZKTestCase { + qu.getPeer(followerId).peer.getQuorumAddress().getPort() /*quorum port*/ + ":" + qu.getPeer(followerId).peer.getElectionAddress().getPort() /*election port*/ + ":participant;localhost:" + PortAssignment.unique()/* new client port */); - zkAdmin.reconfig(joiningServers, null, null, -1, new Stat()); + zkAdmin.reconfigure(joiningServers, null, null, -1, new Stat()); return true; } } http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/java/test/org/apache/zookeeper/test/ReconfigMisconfigTest.java ---------------------------------------------------------------------- diff --git a/src/java/test/org/apache/zookeeper/test/ReconfigMisconfigTest.java b/src/java/test/org/apache/zookeeper/test/ReconfigMisconfigTest.java index 7aaa419..f5cf476 100644 --- a/src/java/test/org/apache/zookeeper/test/ReconfigMisconfigTest.java +++ b/src/java/test/org/apache/zookeeper/test/ReconfigMisconfigTest.java @@ -123,7 +123,7 @@ public class ReconfigMisconfigTest extends ZKTestCase { + qu.getPeer(followerId).peer.getQuorumAddress().getPort() /*quorum port*/ + ":" + qu.getPeer(followerId).peer.getElectionAddress().getPort() /*election port*/ + ":participant;localhost:" + PortAssignment.unique()/* new client port */); - zkAdmin.reconfig(joiningServers, null, null, -1, new Stat()); + zkAdmin.reconfigure(joiningServers, null, null, -1, new Stat()); return true; } } http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/java/test/org/apache/zookeeper/test/ReconfigTest.java ---------------------------------------------------------------------- diff --git a/src/java/test/org/apache/zookeeper/test/ReconfigTest.java b/src/java/test/org/apache/zookeeper/test/ReconfigTest.java index 6ca415c..c4658ca 100644 --- a/src/java/test/org/apache/zookeeper/test/ReconfigTest.java +++ b/src/java/test/org/apache/zookeeper/test/ReconfigTest.java @@ -81,7 +81,7 @@ public class ReconfigTest extends ZKTestCase implements DataCallback{ byte[] config = null; for (int j = 0; j < 30; j++) { try { - config = zkAdmin.reconfig(joiningServers, leavingServers, + config = zkAdmin.reconfigure(joiningServers, leavingServers, newMembers, fromConfig, new Stat()); break; } catch (KeeperException.ConnectionLossException e) { @@ -481,7 +481,7 @@ public class ReconfigTest extends ZKTestCase implements DataCallback{ LinkedList<Integer> results = new LinkedList<Integer>(); - zkAdminArr[1].reconfig(null, leavingServers, null, -1, this, results); + zkAdminArr[1].reconfigure(null, leavingServers, null, -1, this, results); synchronized (results) { while (results.size() < 1) { http://git-wip-us.apache.org/repos/asf/zookeeper/blob/0ba7eda9/src/java/test/org/apache/zookeeper/test/StandaloneTest.java ---------------------------------------------------------------------- diff --git a/src/java/test/org/apache/zookeeper/test/StandaloneTest.java b/src/java/test/org/apache/zookeeper/test/StandaloneTest.java index db1a362..3d57b6c 100644 --- a/src/java/test/org/apache/zookeeper/test/StandaloneTest.java +++ b/src/java/test/org/apache/zookeeper/test/StandaloneTest.java @@ -151,7 +151,7 @@ public class StandaloneTest extends QuorumPeerTestBase implements Watcher{ // generate some transactions that will get logged try { zkAdmin.addAuthInfo("digest", "super:test".getBytes()); - zkAdmin.reconfig(joiners, null, null, -1, new Stat()); + zkAdmin.reconfigure(joiners, null, null, -1, new Stat()); Assert.fail("Reconfiguration in standalone should trigger " + "UnimplementedException"); } catch (KeeperException.UnimplementedException ex) {
