HBASE-11923 Potential race condition in RecoverableZookeeper.checkZk() (Lars Hofhansl)

This commit is contained in:
Enis Soztutar 2014-09-09 18:35:53 -07:00
parent a20c237676
commit 686b860f35
1 changed files with 3 additions and 3 deletions

View File

@ -75,7 +75,7 @@ import org.htrace.TraceScope;
public class RecoverableZooKeeper {
private static final Log LOG = LogFactory.getLog(RecoverableZooKeeper.class);
// the actual ZooKeeper client instance
volatile private ZooKeeper zk;
private ZooKeeper zk;
private final RetryCounterFactory retryCounterFactory;
// An identifier of this process in the cluster
private final String identifier;
@ -134,7 +134,7 @@ public class RecoverableZooKeeper {
* @return The created Zookeeper connection object
* @throws KeeperException
*/
protected ZooKeeper checkZk() throws KeeperException {
protected synchronized ZooKeeper checkZk() throws KeeperException {
if (this.zk == null) {
try {
this.zk = new ZooKeeper(quorumServers, sessionTimeout, watcher);
@ -146,7 +146,7 @@ public class RecoverableZooKeeper {
return zk;
}
public void reconnectAfterExpiration()
public synchronized void reconnectAfterExpiration()
throws IOException, KeeperException, InterruptedException {
if (zk != null) {
LOG.info("Closing dead ZooKeeper connection, session" +