Index: src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (revision 1220306) +++ src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java (working copy) @@ -624,8 +624,13 @@ // Check if we already have a good master connection if (master != null) { - if (master.isMasterRunning()) { - return master; + try { + if (master.isMasterRunning()) { + return master; + } + } catch (RuntimeException x) { + // avoid throwing RPC runtime exceptions to clients + throw new MasterNotRunningException(x); } } checkIfBaseNodeAvailable(); @@ -679,7 +684,9 @@ throw new RuntimeException("Thread was interrupted while trying to connect to master."); } } - this.masterChecked = true; + // If didn't get the master and this is a managed connection, give up. + // Otherwise give subsequent calls a chance to try again. + this.masterChecked = managed || master != null; } 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 1220306) +++ src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (working copy) @@ -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( @@ -111,9 +111,6 @@ } 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); } tries++; @@ -136,6 +133,29 @@ } /** + * Constructor for externally managed HConnections. + * This constructor fails fast if the HMaster is not running. + * The HConnection can be re-used again in another attempt. + * This constructor fails fast. + * + * @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