Index: hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (revision 1428504) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (working copy) @@ -210,6 +210,10 @@ if (connection == null) { connection = new HConnectionImplementation(conf, true); HBASE_INSTANCES.put(connectionKey, connection); + } else if (connection.isClosed()) { + HConnectionManager.deleteConnection(connectionKey, true, true); + connection = new HConnectionImplementation(conf, true); + HBASE_INSTANCES.put(connectionKey, connection); } connection.incCount(); return connection; @@ -2192,7 +2196,7 @@ LOG.fatal(msg); } this.aborted = true; - this.closed = true; + close(); } } @@ -2271,7 +2275,12 @@ @Override public void close() { if (managed) { - HConnectionManager.deleteConnection(this, stopProxy, false); + if (aborted) { + HConnectionManager.deleteStaleConnection(this); + } else { + HConnectionManager.deleteConnection(this, stopProxy, false); + } + closed = true; } else { close(true); } Index: hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java (revision 1428504) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java (working copy) @@ -27,7 +27,10 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Random; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -37,6 +40,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.*; +import org.apache.hadoop.hbase.client.HConnectionManager.HConnectionImplementation; +import org.apache.hadoop.hbase.client.HConnectionManager.HConnectionKey; import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Threads; @@ -118,7 +123,31 @@ private static int getHConnectionManagerCacheSize(){ return HConnectionTestingUtility.getConnectionCount(); } + + @Test + public void abortingHConnectionRemovesItselfFromHCM() throws Exception { + // Save off current HConnections + Map oldHBaseInstances = + new HashMap(); + oldHBaseInstances.putAll(HConnectionManager.HBASE_INSTANCES); + + HConnectionManager.HBASE_INSTANCES.clear(); + try { + HConnection connection = HConnectionManager.getConnection(TEST_UTIL.getConfiguration()); + connection.abort("test abortingHConnectionRemovesItselfFromHCM", new Exception( + "test abortingHConnectionRemovesItselfFromHCM")); + Assert.assertNotSame(connection, + HConnectionManager.getConnection(TEST_UTIL.getConfiguration())); + } finally { + // Put original HConnections back + HConnectionManager.HBASE_INSTANCES.clear(); + for (Entry entry : oldHBaseInstances.entrySet()) { + HConnectionManager.HBASE_INSTANCES.put(entry.getKey(), entry.getValue()); + } + } + } + /** * Test that when we delete a location using the first row of a region * that we really delete it.