From 742367e6e88a97782744514365f7c77746e511c0 Mon Sep 17 00:00:00 2001 From: "Robert (Bobby) Evans" Date: Tue, 31 Jan 2017 14:47:09 -0600 Subject: [PATCH] Addressed review comments --- .../apache/zookeeper/server/ZooKeeperServer.java | 15 +++++++++++++-- .../zookeeper/server/ZooKeeperServerMain.java | 2 +- .../apache/zookeeper/server/quorum/Learner.java | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java index 88e69324ef6..92d3c1366db 100644 --- a/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java @@ -526,7 +526,15 @@ public boolean isRunning() { return state == State.RUNNING; } - public synchronized void shutdown() { + public void shutdown() { + shutdown(false); + } + + /** + * Shut down the server instance + * @param fullyShutDown true if another server using the same database will not replace this one in the same process + */ + public synchronized void shutdown(boolean fullyShutDown) { if (!canShutdown()) { LOG.debug("ZooKeeper server is not running, so not proceeding to shutdown!"); return; @@ -545,7 +553,10 @@ public synchronized void shutdown() { firstProcessor.shutdown(); } - // There is no need to clear the database + if (fullyShutDown && zkDb != null) { + zkDb.clear(); + } + // else there is no need to clear the database // * When a new quorum is established we can still apply the diff // on top of the same zkDb data // * If we fetch a new snapshot from leader, the zkDb will be diff --git a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java index 5bfeed3e647..372c78a0a06 100644 --- a/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java +++ b/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java @@ -167,7 +167,7 @@ public void runFromConfig(ServerConfig config) secureCnxnFactory.join(); } if (zkServer.canShutdown()) { - zkServer.shutdown(); + zkServer.shutdown(true); } } catch (InterruptedException e) { // warn, but generally this is ok diff --git a/src/java/main/org/apache/zookeeper/server/quorum/Learner.java b/src/java/main/org/apache/zookeeper/server/quorum/Learner.java index 021e56eb4ce..bddccaa7e19 100644 --- a/src/java/main/org/apache/zookeeper/server/quorum/Learner.java +++ b/src/java/main/org/apache/zookeeper/server/quorum/Learner.java @@ -358,7 +358,7 @@ protected void syncWithLeader(long newLeaderZxid) throws Exception{ QuorumVerifier newLeaderQV = null; - //In the DIFF case we don't need to do a snapshot because the transactions will sync on top of any existing snapshot + // In the DIFF case we don't need to do a snapshot because the transactions will sync on top of any existing snapshot // For SNAP and TRUNC the snapshot is needed to save that history boolean snapshotNeeded = true; readPacket(qp);