HBASE-7616 NPE in ZKProcedure.nodeCreated

git-svn-id: https://svn.apache.org/repos/asf/hbase/branches/hbase-7290@1445855 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Hsieh 2013-02-13 19:01:21 +00:00
parent bc37ac1553
commit 6a25400409
3 changed files with 57 additions and 32 deletions

View File

@ -39,7 +39,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class ZKProcedureCoordinatorRpcs implements ProcedureCoordinatorRpcs {
public static final Log LOG = LogFactory.getLog(ZKProcedureUtil.class);
public static final Log LOG = LogFactory.getLog(ZKProcedureCoordinatorRpcs.class);
private ZKProcedureUtil zkProc = null;
protected ProcedureCoordinator coordinator = null; // if started this should be non-null
@ -165,20 +165,20 @@ public class ZKProcedureCoordinatorRpcs implements ProcedureCoordinatorRpcs {
this.zkProc = new ZKProcedureUtil(watcher, procedureType, coordName) {
@Override
public void nodeCreated(String path) {
if (!zkProc.isInProcedurePath(path)) return;
if (!isInProcedurePath(path)) return;
LOG.debug("Node created: " + path);
logZKTree(this.baseZNode);
if (zkProc.isAcquiredPathNode(path)) {
if (isAcquiredPathNode(path)) {
// node wasn't present when we created the watch so zk event triggers acquire
listener.memberAcquiredBarrier(ZKUtil.getNodeName(ZKUtil.getParent(path)), ZKUtil.getNodeName(path));
}
if (zkProc.isReachedPathNode(path)) {
if (isReachedPathNode(path)) {
// node wasn't present when we created the watch so zk event triggers the finished barrier.
// TODO Nothing enforces that acquire and reached znodes from showing up in the wrong order.
listener.memberFinishedBarrier(ZKUtil.getNodeName(ZKUtil.getParent(path)), ZKUtil.getNodeName(path));
}
if (zkProc.isAbortPathNode(path)) {
if (isAbortPathNode(path)) {
abort(path);
}
}

View File

@ -74,29 +74,31 @@ public class ZKProcedureMemberRpcs implements ProcedureMemberRpcs {
this.zkController = new ZKProcedureUtil(watcher, procType, memberName) {
@Override
public void nodeCreated(String path) {
if (path.startsWith(this.baseZNode)) {
LOG.info("Received created event:" + path);
// if it is a simple start/end/abort then we just rewatch the node
if (path.equals(this.acquiredZnode)) {
waitForNewProcedures();
return;
} else if (path.equals(this.abortZnode)) {
watchForAbortedProcedures();
return;
}
String parent = ZKUtil.getParent(path);
// if its the end barrier, the procedure can be completed
if (parent.equals(this.reachedZnode)) {
receivedReachedGlobalBarrier(path);
return;
} else if (parent.equals(this.abortZnode)) {
abort(path);
return;
} else if (parent.equals(this.acquiredZnode)) {
startNewSubprocedure(path);
} else {
LOG.debug("Ignoring created notification for node:" + path);
}
if (!isInProcedurePath(path)) {
return;
}
LOG.info("Received created event:" + path);
// if it is a simple start/end/abort then we just rewatch the node
if (isAcquiredNode(path)) {
waitForNewProcedures();
return;
} else if (isAbortNode(path)) {
watchForAbortedProcedures();
return;
}
String parent = ZKUtil.getParent(path);
// if its the end barrier, the procedure can be completed
if (isReachedNode(parent)) {
receivedReachedGlobalBarrier(path);
return;
} else if (isAbortNode(parent)) {
abort(path);
return;
} else if (isAcquiredNode(parent)) {
startNewSubprocedure(path);
} else {
LOG.debug("Ignoring created notification for node:" + path);
}
}

View File

@ -179,28 +179,51 @@ public abstract class ZKProcedureUtil
*
* @return true if starts with baseZnode
*/
public boolean isInProcedurePath(String path) {
boolean isInProcedurePath(String path) {
return path.startsWith(baseZNode);
}
/**
* Is this the exact procedure barrier acquired znode
*/
boolean isAcquiredNode(String path) {
return path.equals(acquiredZnode);
}
/**
* Is this in the procedure barrier acquired znode path
*/
public boolean isAcquiredPathNode(String path) {
boolean isAcquiredPathNode(String path) {
return path.startsWith(this.acquiredZnode) && !path.equals(acquiredZnode);
}
/**
* Is this the exact procedure barrier reached znode
*/
boolean isReachedNode(String path) {
return path.equals(reachedZnode);
}
/**
* Is this in the procedure barrier reached znode path
*/
public boolean isReachedPathNode(String path) {
boolean isReachedPathNode(String path) {
return path.startsWith(this.reachedZnode) && !path.equals(reachedZnode);
}
/**
* Is this in the procedure barrier abort znode path
*/
boolean isAbortNode(String path) {
return path.equals(abortZnode);
}
/**
* Is this in the procedure barrier abort znode path
*/
public boolean isAbortPathNode(String path) {
public boolean isAbortPathNode(String path) {
return path.startsWith(this.abortZnode) && !path.equals(abortZnode);
}