Index: src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (revision 1215210) +++ src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (working copy) @@ -613,8 +613,14 @@ // Check if we already have a good master connection if (master != null) { - if (master.isMasterRunning()) { - return master; + try { + if (master.isMasterRunning()) { + return master; + } + } catch (UndeclaredThrowableException ute) { + // RPC connection to the master is dead, try again + master = null; + masterChecked = false; } } checkIfBaseNodeAvailable(); @@ -668,7 +674,9 @@ throw new RuntimeException("Thread was interrupted while trying to connect to master."); } } - this.masterChecked = true; + // If the connection is managed, give up. + // Otherwise try again in a subsequent call. + this.masterChecked = this.managed; } if (this.master == null) { if (sn == null) { Index: src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (revision 1215210) +++ src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (working copy) @@ -84,7 +84,7 @@ // want to wait a long time. private final int retryLongerMultiplier; private boolean aborted; - + /** * Constructor * @@ -95,7 +95,7 @@ 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( @@ -104,16 +104,10 @@ int tries = 0; while ( true ){ try { - this.connection.getMaster(); return; - } catch (MasterNotRunningException mnre) { - HConnectionManager.deleteStaleConnection(this.connection); - this.connection = HConnectionManager.getConnection(this.conf); - } catch (UndeclaredThrowableException ute) { - HConnectionManager.deleteStaleConnection(this.connection); - this.connection = HConnectionManager.getConnection(this.conf); + // ignore and try again } tries++; @@ -136,6 +130,28 @@ } /** + * Constructor for externally managed HConnections. + * This constructor fails fast if the HMaster is not running. + * The HConnection can be re-used again another attempt. + * + * @param connection The HConnection instance to use + * @throws MasterNotRunningException if the master is not running + * @throws ZooKeeperConnectionException if unable to connect to zookeeper + */ + public HBaseAdmin(HConnection connection) + throws MasterNotRunningException, ZooKeeperConnectionException { + this.conf = connection.getConfiguration(); + this.connection = connection; + + 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(); + } + + /** * @return A new CatalogTracker instance; call {@link #cleanupCatalogTracker(CatalogTracker)} * to cleanup the returned catalog tracker. * @throws ZooKeeperConnectionException