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