|
@@ -900,7 +900,7 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
|
|
|
* @return true if the server is running or server hits an error, false
|
|
|
* otherwise.
|
|
|
*/
|
|
|
- protected boolean canShutdown() {
|
|
|
+ private boolean canShutdown() {
|
|
|
return state == State.RUNNING || state == State.ERROR;
|
|
|
}
|
|
|
|
|
@@ -911,27 +911,49 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
|
|
|
return state == State.RUNNING;
|
|
|
}
|
|
|
|
|
|
- public void shutdown() {
|
|
|
+ public final 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
|
|
|
+ * @param fullyShutDown true when no other server will use the same database to replace this one
|
|
|
*/
|
|
|
- public synchronized void shutdown(boolean fullyShutDown) {
|
|
|
- if (!canShutdown()) {
|
|
|
- if (fullyShutDown && zkDb != null) {
|
|
|
- zkDb.clear();
|
|
|
+ public final synchronized void shutdown(boolean fullyShutDown) {
|
|
|
+ if (canShutdown()) {
|
|
|
+ LOG.info("Shutting down");
|
|
|
+
|
|
|
+ shutdownComponents();
|
|
|
+
|
|
|
+ if (zkDb != null && !fullyShutDown) {
|
|
|
+ // There is no need to clear the database if we are going to reuse it:
|
|
|
+ // * 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
|
|
|
+ // cleared anyway before loading the snapshot
|
|
|
+ try {
|
|
|
+ // This will fast-forward the database to the last recorded transaction
|
|
|
+ zkDb.fastForwardDataBase();
|
|
|
+ } catch (IOException e) {
|
|
|
+ LOG.error("Error updating DB", e);
|
|
|
+ fullyShutDown = true;
|
|
|
+ }
|
|
|
}
|
|
|
+ setState(State.SHUTDOWN);
|
|
|
+ } else {
|
|
|
LOG.debug("ZooKeeper server is not running, so not proceeding to shutdown!");
|
|
|
- return;
|
|
|
}
|
|
|
- LOG.info("shutting down");
|
|
|
-
|
|
|
- // new RuntimeException("Calling shutdown").printStackTrace();
|
|
|
- setState(State.SHUTDOWN);
|
|
|
+ if (zkDb != null && fullyShutDown) {
|
|
|
+ zkDb.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * @implNote
|
|
|
+ * Shuts down components owned by this class;
|
|
|
+ * remember to call super.shutdownComponents() when overriding!
|
|
|
+ */
|
|
|
+ protected void shutdownComponents() {
|
|
|
// unregister all metrics that are keeping a strong reference to this object
|
|
|
// subclasses will do their specific clean up
|
|
|
unregisterMetrics();
|
|
@@ -940,9 +962,8 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
|
|
|
requestThrottler.shutdown();
|
|
|
}
|
|
|
|
|
|
- // Since sessionTracker and syncThreads poll we just have to
|
|
|
- // set running to false and they will detect it during the poll
|
|
|
- // interval.
|
|
|
+ // Since sessionTracker and syncThreads poll we just have to set running to false,
|
|
|
+ // and they will detect it during the poll interval.
|
|
|
if (sessionTracker != null) {
|
|
|
sessionTracker.shutdown();
|
|
|
}
|
|
@@ -953,25 +974,6 @@ public class ZooKeeperServer implements SessionExpirer, ServerStats.Provider {
|
|
|
jvmPauseMonitor.serviceStop();
|
|
|
}
|
|
|
|
|
|
- if (zkDb != null) {
|
|
|
- if (fullyShutDown) {
|
|
|
- zkDb.clear();
|
|
|
- } else {
|
|
|
- // 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
|
|
|
- // cleared anyway before loading the snapshot
|
|
|
- try {
|
|
|
- //This will fast forward the database to the latest recorded transactions
|
|
|
- zkDb.fastForwardDataBase();
|
|
|
- } catch (IOException e) {
|
|
|
- LOG.error("Error updating DB", e);
|
|
|
- zkDb.clear();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
requestPathMetricsCollector.shutdown();
|
|
|
unregisterJMX();
|
|
|
}
|