Author: tedyu
Date: Sat Jul 16 01:18:36 2011
New Revision: 1147352
URL: http://svn.apache.org/viewvc?rev=1147352&view=rev
Log:
HBASE-4087 HBaseAdmin should perform validation of connection it holds
Modified:
hbase/trunk/CHANGES.txt
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
Modified: hbase/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hbase/trunk/CHANGES.txt?rev=1147352&r1=1147351&r2=1147352&view=diff
==============================================================================
--- hbase/trunk/CHANGES.txt (original)
+++ hbase/trunk/CHANGES.txt Sat Jul 16 01:18:36 2011
@@ -160,6 +160,7 @@ Release 0.91.0 - Unreleased
HRegion.delete (Adam Warrington via Ted Yu)
HBASE-3893 HRegion.internalObtainRowLock shouldn't wait forever
HBASE-4075 A bug in TestZKBasedOpenCloseRegion (Jieshan Bean via Ted Yu)
+ HBASE-4087 HBaseAdmin should perform validation of connection it holds
IMPROVEMENTS
HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack)
Modified:
hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL:
http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=1147352&r1=1147351&r2=1147352&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
Sat Jul 16 01:18:36 2011
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 The Apache Software Foundation
+ * Copyright 2011 The Apache Software Foundation
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -22,12 +22,11 @@ package org.apache.hadoop.hbase.client;
import java.io.Closeable;
import java.io.IOException;
import java.io.InterruptedIOException;
+import java.lang.reflect.UndeclaredThrowableException;
import java.net.SocketTimeoutException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
@@ -76,7 +75,7 @@ import org.apache.hadoop.util.StringUtil
public class HBaseAdmin implements Abortable, Closeable {
private final Log LOG = LogFactory.getLog(this.getClass().getName());
// private final HConnection connection;
- private final HConnection connection;
+ private HConnection connection;
private volatile Configuration conf;
private final long pause;
private final int numRetries;
@@ -84,7 +83,7 @@ public class HBaseAdmin implements Abort
// numRetries is for 'normal' stuff... Mutliply by this factor when
// want to wait a long time.
private final int retryLongerMultiplier;
-
+
/**
* Constructor
*
@@ -95,11 +94,30 @@ public class HBaseAdmin implements Abort
public HBaseAdmin(Configuration c)
throws MasterNotRunningException, ZooKeeperConnectionException {
this.conf = HBaseConfiguration.create(c);
- this.connection = HConnectionManager.getConnection(this.conf);
+ this.connection = HConnectionManager.getConnection(this.conf);
this.pause = this.conf.getLong("hbase.client.pause", 1000);
this.numRetries = this.conf.getInt("hbase.client.retries.number", 10);
- this.retryLongerMultiplier =
this.conf.getInt("hbase.client.retries.longer.multiplier", 10);
- this.connection.getMaster();
+ this.retryLongerMultiplier = this.conf.getInt(
+ "hbase.client.retries.longer.multiplier", 10);
+ int tries = 0;
+ for (; tries < numRetries; ++tries) {
+ try {
+ this.connection.getMaster();
+ break;
+ } catch (UndeclaredThrowableException ute) {
+ HConnectionManager.deleteStaleConnection(this.connection);
+ this.connection = HConnectionManager.getConnection(this.conf);
+ }
+ try { // Sleep
+ Thread.sleep(getPauseTime(tries));
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new MasterNotRunningException("Interrupted");
+ }
+ }
+ if (tries >= numRetries) {
+ throw new MasterNotRunningException("Retried " + numRetries + " times");
+ }
}
/**
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=1147352&r1=1147351&r2=1147352&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
Sat Jul 16 01:18:36 2011
@@ -199,7 +199,21 @@ public class HConnectionManager {
* .
*/
public static void deleteConnection(Configuration conf, boolean stopProxy) {
- deleteConnection(new HConnectionKey(conf), stopProxy);
+ deleteConnection(new HConnectionKey(conf), stopProxy, false);
+ }
+
+ /**
+ * Delete stale connection information for the instance specified by
configuration.
+ * This will then close connection to
+ * the zookeeper ensemble and let go of all resources.
+ *
+ * @param conf
+ * configuration whose identity is used to find {@link HConnection}
+ * instance.
+ * .
+ */
+ public static void deleteStaleConnection(HConnection connection) {
+ deleteConnection(connection, true, true);
}
/**
@@ -212,31 +226,33 @@ public class HConnectionManager {
Set<HConnectionKey> connectionKeys = new HashSet<HConnectionKey>();
connectionKeys.addAll(HBASE_INSTANCES.keySet());
for (HConnectionKey connectionKey : connectionKeys) {
- deleteConnection(connectionKey, stopProxy);
+ deleteConnection(connectionKey, stopProxy, false);
}
HBASE_INSTANCES.clear();
}
}
- private static void deleteConnection(HConnection connection, boolean
stopProxy) {
+ private static void deleteConnection(HConnection connection, boolean
stopProxy,
+ boolean staleConnection) {
synchronized (HBASE_INSTANCES) {
for (Entry<HConnectionKey, HConnectionImplementation> connectionEntry :
HBASE_INSTANCES
.entrySet()) {
if (connectionEntry.getValue() == connection) {
- deleteConnection(connectionEntry.getKey(), stopProxy);
+ deleteConnection(connectionEntry.getKey(), stopProxy,
staleConnection);
break;
}
}
}
}
- private static void deleteConnection(HConnectionKey connectionKey, boolean
stopProxy) {
+ private static void deleteConnection(HConnectionKey connectionKey,
+ boolean stopProxy, boolean staleConnection) {
synchronized (HBASE_INSTANCES) {
HConnectionImplementation connection = HBASE_INSTANCES
.get(connectionKey);
if (connection != null) {
connection.decCount();
- if (connection.isZeroReference()) {
+ if (connection.isZeroReference() || staleConnection) {
HBASE_INSTANCES.remove(connectionKey);
connection.close(stopProxy);
} else if (stopProxy) {
@@ -1699,7 +1715,7 @@ public class HConnectionManager {
}
public void close() {
- HConnectionManager.deleteConnection(this, stopProxy);
+ HConnectionManager.deleteConnection((HConnection)this, stopProxy, false);
LOG.debug("The connection to " + this.zooKeeper + " has been closed.");
}