Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zookeeper: silence warning and log lifecycle state events.
Motivation: Starting with ZooKeeper v3.4.10, the stand-alone server will log the following error message for each state change: ZKShutdownHandler is not registered, so ZooKeeper server won't take any action on ERROR or SHUTDOWN server state changes Although the message is logged at ERROR severity, this lack of action has no bad effect for our embedded zookeeper cell. It certainly sounds scary, though. Modification: Unfortunately there is no easy way to silence this error message, as ZK currently provides no (easy) mechanism to register a ZKShutdownHandler. This problem is reported as: https://issues.apache.org/jira/browse/ZOOKEEPER-2991 Therefore, this patch introduces a simple public class that extends the package-private class. This class also logs the ZK life-cycle state transitions as they few and potentially of interest. This patch also moves the PatchedZooKeeperServer into the org.apache.zookeper.server Java package, to allow it to upgrade the registerServerShutdownHandler method to public. Finally, the intended countdown latch employed as intended. Given dCache closes the ZooKeeper instance "manually", the countdown latch should have already fired by the time the shutdown(true) call returns. Result: No "ZKShutdownHandler is not registered" error is logged. Potentially interesting ZK life-cycle state transitions are logged. Target: master Require-notes: no Require-book: no Patch: https://rb.dcache.org/r/10793/ Acked-by: Tigran Mkrtchyan
- Loading branch information
1 parent
f913bcf
commit 7679b60
Showing
3 changed files
with
110 additions
and
21 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
modules/dcache/src/main/java/org/apache/zookeeper/server/LoggingShutdownHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* dCache - http://www.dcache.org/ | ||
* | ||
* Copyright (C) 2018 Deutsches Elektronen-Synchrotron | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.apache.zookeeper.server; | ||
|
||
import org.apache.zookeeper.server.ZooKeeperServer.State; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
|
||
/** | ||
* This class wraps ZooKeeperServerShutdownHandler primarily to provide a | ||
* public class as a work-around for issue ZOOKEEPER-2991. See: | ||
* | ||
* https://issues.apache.org/jira/browse/ZOOKEEPER-2991 | ||
*/ | ||
public class LoggingShutdownHandler extends ZooKeeperServerShutdownHandler | ||
{ | ||
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingShutdownHandler.class); | ||
|
||
public LoggingShutdownHandler(CountDownLatch shutdownLatch) | ||
{ | ||
super(shutdownLatch); | ||
} | ||
|
||
@Override | ||
void handle(State state) | ||
{ | ||
LOGGER.warn("Zookeeper server now {}", state); | ||
super.handle(state); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
modules/dcache/src/main/java/org/apache/zookeeper/server/PatchedZooKeeperServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* dCache - http://www.dcache.org/ | ||
* | ||
* Copyright (C) 2018 Deutsches Elektronen-Synchrotron | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.apache.zookeeper.server; | ||
|
||
/** | ||
* This class contains various work-arounds for bugs in ZooKeeper. | ||
*/ | ||
public class PatchedZooKeeperServer extends ZooKeeperServer | ||
{ | ||
// Work around https://issues.apache.org/jira/browse/ZOOKEEPER-2515 | ||
// and https://issues.apache.org/jira/browse/ZOOKEEPER-2812 | ||
@Override | ||
public void createSessionTracker() { | ||
sessionTracker = new SessionTrackerImpl(this, getZKDatabase().getSessionWithTimeOuts(), | ||
tickTime, 1, getZooKeeperServerListener()) | ||
{ | ||
@Override | ||
public void shutdown() { | ||
super.shutdown(); | ||
synchronized (this) { | ||
notifyAll(); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
// Work-around for https://issues.apache.org/jira/browse/ZOOKEEPER-2991 | ||
@Override | ||
public void registerServerShutdownHandler(ZooKeeperServerShutdownHandler handler) | ||
{ | ||
super.registerServerShutdownHandler(handler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters