From 6a254004094d53e1302b27c98de9962d978c4692 Mon Sep 17 00:00:00 2001 From: Jonathan Hsieh Date: Wed, 13 Feb 2013 19:01:21 +0000 Subject: [PATCH] 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 --- .../procedure/ZKProcedureCoordinatorRpcs.java | 10 ++-- .../procedure/ZKProcedureMemberRpcs.java | 48 ++++++++++--------- .../hbase/procedure/ZKProcedureUtil.java | 31 ++++++++++-- 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureCoordinatorRpcs.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureCoordinatorRpcs.java index 9132bbec6f9..2e9e931a3a8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureCoordinatorRpcs.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureCoordinatorRpcs.java @@ -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); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureMemberRpcs.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureMemberRpcs.java index e59b5963bd1..d4df8d01880 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureMemberRpcs.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureMemberRpcs.java @@ -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); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureUtil.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureUtil.java index 88fd1181b2b..5740b89a42b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureUtil.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/ZKProcedureUtil.java @@ -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); }