You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2011/07/29 15:46:13 UTC
svn commit: r1152220 - in /hbase/trunk: ./
src/main/java/org/apache/hadoop/hbase/client/
src/main/java/org/apache/hadoop/hbase/master/
src/main/java/org/apache/hadoop/hbase/regionserver/
src/main/java/org/apache/hadoop/hbase/zookeeper/ src/test/java/or...
Author: tedyu
Date: Fri Jul 29 13:46:11 2011
New Revision: 1152220
URL: http://svn.apache.org/viewvc?rev=1152220&view=rev
Log:
HBASE-4138 If zookeeper.znode.parent is not specifed explicitly in Client
code then HTable object loops continuously waiting for the root region
by using /hbase as the base node.(ramkrishna.s.vasudevan)
Modified:
hbase/trunk/CHANGES.txt
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestOpenRegionHandler.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java
hbase/trunk/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKTable.java
Modified: hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Fri Jul 29 13:46:11 2011
@@ -178,6 +178,9 @@ Release 0.91.0 - Unreleased
HBASE-4083 If Enable table is not completed and is partial, then scanning of
the table is not working (ramkrishna.s.vasudevan)
HBASE-4144 RS does not abort if the initialization of RS fails (ramkrishna.s.vasudevan)
+ HBASE-4138 If zookeeper.znode.parent is not specifed explicitly in Client
+ code then HTable object loops continuously waiting for the root region
+ by using /hbase as the base node.(ramkrishna.s.vasudevan)
IMPROVEMENTS
HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack)
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java Fri Jul 29 13:46:11 2011
@@ -570,7 +570,7 @@ public class HConnectionManager {
return master;
}
}
-
+ checkIfBaseNodeAvailable();
ServerName sn = null;
synchronized (this.masterLock) {
for (int tries = 0;
@@ -632,6 +632,15 @@ public class HConnectionManager {
return this.master;
}
+ private void checkIfBaseNodeAvailable() throws MasterNotRunningException {
+ if (false == masterAddressTracker.checkIfBaseNodeAvailable()) {
+ String errorMsg = "Check the value configured in 'zookeeper.znode.parent'. "
+ + "There could be a mismatch with the one configured in the master.";
+ LOG.error(errorMsg);
+ throw new MasterNotRunningException(errorMsg);
+ }
+ }
+
public boolean isMasterRunning()
throws MasterNotRunningException, ZooKeeperConnectionException {
if (this.master == null) {
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Fri Jul 29 13:46:11 2011
@@ -238,7 +238,7 @@ implements HMasterInterface, HMasterRegi
if (this.conf.get("mapred.task.id") == null) {
this.conf.set("mapred.task.id", "hb_m_" + this.serverName.toString());
}
- this.zooKeeper = new ZooKeeperWatcher(conf, MASTER + ":" + isa.getPort(), this);
+ this.zooKeeper = new ZooKeeperWatcher(conf, MASTER + ":" + isa.getPort(), this, true);
this.metrics = new MasterMetrics(getServerName().toString());
}
@@ -1218,7 +1218,7 @@ implements HMasterInterface, HMasterRegi
private boolean tryRecoveringExpiredZKSession() throws InterruptedException,
IOException, KeeperException {
this.zooKeeper = new ZooKeeperWatcher(conf, MASTER + ":"
- + this.serverName.getPort(), this);
+ + this.serverName.getPort(), this, true);
MonitoredTask status =
TaskMonitor.get().createStatus("Recovering expired ZK session");
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java Fri Jul 29 13:46:11 2011
@@ -555,6 +555,12 @@ public class HRegionServer implements HR
*/
private void blockAndCheckIfStopped(ZooKeeperNodeTracker tracker)
throws IOException, InterruptedException {
+ if (false == tracker.checkIfBaseNodeAvailable()) {
+ String errorMsg = "Check the value configured in 'zookeeper.znode.parent'. "
+ + "There could be a mismatch with the one configured in the master.";
+ LOG.error(errorMsg);
+ abort(errorMsg);
+ }
while (tracker.blockUntilAvailable(this.msgInterval) == null) {
if (this.stopped) {
throw new IOException("Received the shutdown message while waiting.");
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java Fri Jul 29 13:46:11 2011
@@ -71,6 +71,12 @@ public class RootRegionTracker extends Z
*/
public ServerName waitRootRegionLocation(long timeout)
throws InterruptedException {
+ if (false == checkIfBaseNodeAvailable()) {
+ String errorMsg = "Check the value configured in 'zookeeper.znode.parent'. "
+ + "There could be a mismatch with the one configured in the master.";
+ LOG.error(errorMsg);
+ throw new IllegalArgumentException(errorMsg);
+ }
return dataToServerName(super.blockUntilAvailable(timeout));
}
@@ -95,4 +101,4 @@ public class RootRegionTracker extends Z
int port = Addressing.parsePort(str);
return new ServerName(hostname, port, -1L);
}
-}
\ No newline at end of file
+}
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java Fri Jul 29 13:46:11 2011
@@ -19,6 +19,8 @@
*/
package org.apache.hadoop.hbase.zookeeper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.Abortable;
import org.apache.zookeeper.KeeperException;
@@ -32,6 +34,8 @@ import org.apache.zookeeper.KeeperExcept
* RegionServers.
*/
public abstract class ZooKeeperNodeTracker extends ZooKeeperListener {
+
+ static final Log LOG = LogFactory.getLog(ZooKeeperNodeTracker.class);
/** Path of node being tracked */
protected final String node;
@@ -179,4 +183,24 @@ public abstract class ZooKeeperNodeTrack
nodeCreated(path);
}
}
+
+ /**
+ * Checks if the baseznode set as per the property 'zookeeper.znode.parent'
+ * exists.
+ * @return true if baseznode exists.
+ * false if doesnot exists.
+ */
+ public boolean checkIfBaseNodeAvailable() {
+ try {
+ if (ZKUtil.checkExists(watcher, watcher.baseZNode) == -1) {
+ return false;
+ }
+ } catch (KeeperException e) {
+ abortable
+ .abort(
+ "Exception while checking if basenode exists.",
+ e);
+ }
+ return true;
+ }
}
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java Fri Jul 29 13:46:11 2011
@@ -90,6 +90,18 @@ public class ZooKeeperWatcher implements
private final Exception constructorCaller;
+
+ /**
+ * Instantiate a ZooKeeper connection and watcher.
+ * @param descriptor Descriptive string that is added to zookeeper sessionid
+ * and used as identifier for this instance.
+ * @throws IOException
+ * @throws ZooKeeperConnectionException
+ */
+ public ZooKeeperWatcher(Configuration conf, String descriptor,
+ Abortable abortable) throws ZooKeeperConnectionException, IOException {
+ this(conf, descriptor, abortable, false);
+ }
/**
* Instantiate a ZooKeeper connection and watcher.
* @param descriptor Descriptive string that is added to zookeeper sessionid
@@ -98,7 +110,7 @@ public class ZooKeeperWatcher implements
* @throws ZooKeeperConnectionException
*/
public ZooKeeperWatcher(Configuration conf, String descriptor,
- Abortable abortable)
+ Abortable abortable, boolean canCreateBaseZNode)
throws IOException, ZooKeeperConnectionException {
this.conf = conf;
// Capture a stack trace now. Will print it out later if problem so we can
@@ -115,9 +127,14 @@ public class ZooKeeperWatcher implements
this.abortable = abortable;
setNodeNames(conf);
this.recoverableZooKeeper = ZKUtil.connect(conf, quorum, this, descriptor);
+ if (canCreateBaseZNode) {
+ createBaseZNodes();
+ }
+ }
+
+ private void createBaseZNodes() throws ZooKeeperConnectionException {
try {
// Create all the necessary "directories" of znodes
- // TODO: Move this to an init method somewhere so not everyone calls it?
ZKUtil.createAndFailSilent(this, baseZNode);
ZKUtil.createAndFailSilent(this, assignmentZNode);
ZKUtil.createAndFailSilent(this, rsZNode);
Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java Fri Jul 29 13:46:11 2011
@@ -84,7 +84,7 @@ public class TestCatalogTracker {
}
};
this.watcher = new ZooKeeperWatcher(UTIL.getConfiguration(),
- this.getClass().getSimpleName(), this.abortable);
+ this.getClass().getSimpleName(), this.abortable, true);
}
@After public void after() {
@@ -356,4 +356,4 @@ public class TestCatalogTracker {
this.ct.waitForRoot();
}
}
-}
\ No newline at end of file
+}
Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestRestartCluster.java Fri Jul 29 13:46:11 2011
@@ -67,7 +67,7 @@ public class TestRestartCluster {
@Test (timeout=300000) public void testRestartClusterAfterKill()
throws Exception {
UTIL.startMiniZKCluster();
- zooKeeper = new ZooKeeperWatcher(UTIL.getConfiguration(), "cluster1", null);
+ zooKeeper = new ZooKeeperWatcher(UTIL.getConfiguration(), "cluster1", null, true);
// create the unassigned region, throw up a region opened state for META
String unassignedZNode = zooKeeper.assignmentZNode;
@@ -133,4 +133,4 @@ public class TestRestartCluster {
UTIL.waitTableAvailable(TABLE, 30000);
}
}
-}
\ No newline at end of file
+}
Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestOpenRegionHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestOpenRegionHandler.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestOpenRegionHandler.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/handler/TestOpenRegionHandler.java Fri Jul 29 13:46:11 2011
@@ -76,7 +76,7 @@ public class TestOpenRegionHandler {
final ZooKeeperWatcher zk;
MockServer() throws ZooKeeperConnectionException, IOException {
- this.zk = new ZooKeeperWatcher(HTU.getConfiguration(), NAME.toString(), this);
+ this.zk = new ZooKeeperWatcher(HTU.getConfiguration(), NAME.toString(), this, true);
}
@Override
Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java Fri Jul 29 13:46:11 2011
@@ -104,7 +104,7 @@ public class TestReplication {
utility1 = new HBaseTestingUtility(conf1);
utility1.startMiniZKCluster();
MiniZooKeeperCluster miniZK = utility1.getZkCluster();
- zkw1 = new ZooKeeperWatcher(conf1, "cluster1", null);
+ zkw1 = new ZooKeeperWatcher(conf1, "cluster1", null, true);
admin = new ReplicationAdmin(conf1);
LOG.info("Setup first Zk");
@@ -116,7 +116,7 @@ public class TestReplication {
utility2 = new HBaseTestingUtility(conf2);
utility2.setZkCluster(miniZK);
- zkw2 = new ZooKeeperWatcher(conf2, "cluster2", null);
+ zkw2 = new ZooKeeperWatcher(conf2, "cluster2", null, true);
slaveClusterKey = conf2.get(HConstants.ZOOKEEPER_QUORUM)+":" +
conf2.get("hbase.zookeeper.property.clientPort")+":/2";
Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKTable.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKTable.java?rev=1152220&r1=1152219&r2=1152220&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKTable.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKTable.java Fri Jul 29 13:46:11 2011
@@ -60,7 +60,7 @@ public class TestZKTable {
}
};
ZooKeeperWatcher zkw = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
- name, abortable);
+ name, abortable, true);
ZKTable zkt = new ZKTable(zkw);
assertTrue(zkt.isEnabledTable(name));
assertFalse(zkt.isDisablingTable(name));