hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndimi...@apache.org
Subject hbase git commit: HBASE-12652 Allow unmanaged connections in MetaTableAccessor (Solomon Duskis)
Date Tue, 09 Dec 2014 19:54:54 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 84bf8bcd8 -> 1c99261f5


HBASE-12652 Allow unmanaged connections in MetaTableAccessor (Solomon Duskis)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1c99261f
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1c99261f
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1c99261f

Branch: refs/heads/branch-1
Commit: 1c99261f5367bc4221152212068c6dc4fe4bc6f7
Parents: 84bf8bc
Author: Nick Dimiduk <ndimiduk@apache.org>
Authored: Tue Dec 9 11:27:28 2014 -0800
Committer: Nick Dimiduk <ndimiduk@apache.org>
Committed: Tue Dec 9 11:50:47 2014 -0800

----------------------------------------------------------------------
 .../apache/hadoop/hbase/MetaTableAccessor.java  | 45 +++++++++----------
 .../hadoop/hbase/client/ClusterConnection.java  |  6 +++
 .../hadoop/hbase/client/ConnectionAdapter.java  |  5 +++
 .../hadoop/hbase/client/ConnectionManager.java  |  5 +++
 .../org/apache/hadoop/hbase/util/HBaseFsck.java | 12 ++---
 .../hadoop/hbase/util/HBaseFsckRepair.java      | 34 ++++++++-------
 .../hadoop/hbase/TestMetaTableAccessor.java     |  4 +-
 .../hadoop/hbase/TestRegionRebalancing.java     | 18 +++++---
 .../hbase/client/HConnectionTestingUtility.java |  2 +
 .../replication/TestReplicationWithTags.java    | 22 ++++------
 .../apache/hadoop/hbase/util/TestHBaseFsck.java | 46 ++++++++++----------
 11 files changed, 108 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java
index 187856e..04d6a54 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java
@@ -22,8 +22,9 @@ import com.google.protobuf.ServiceException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.client.ClusterConnection;
 import org.apache.hadoop.hbase.client.Connection;
 import org.apache.hadoop.hbase.client.ConnectionFactory;
 import org.apache.hadoop.hbase.client.Delete;
@@ -170,37 +171,31 @@ public class MetaTableAccessor {
   }
 
   /**
-   * Callers should call close on the returned {@link HTable} instance.
-   * @param connection connection we're using to access table
-   * @param tableName Table to get an {@link org.apache.hadoop.hbase.client.HTable} against.
-   * @return An {@link org.apache.hadoop.hbase.client.HTable} for <code>tableName</code>
+   * Callers should call close on the returned {@link Table} instance.
+   * @param connection connection we're using to access Meta
+   * @return An {@link Table} for <code>hbase:meta</code>
    * @throws IOException
-   * @SuppressWarnings("deprecation")
    */
-  private static Table getHTable(final Connection connection, final TableName tableName)
+  static Table getMetaHTable(final Connection connection)
   throws IOException {
     // We used to pass whole CatalogTracker in here, now we just pass in Connection
     if (connection == null || connection.isClosed()) {
       throw new NullPointerException("No connection");
     }
     // If the passed in 'connection' is 'managed' -- i.e. every second test uses
-    // an HTable or an HBaseAdmin with managed connections -- then doing
+    // a Table or an HBaseAdmin with managed connections -- then doing
     // connection.getTable will throw an exception saying you are NOT to use
     // managed connections getting tables.  Leaving this as it is for now. Will
     // revisit when inclined to change all tests.  User code probaby makes use of
     // managed connections too so don't change it till post hbase 1.0.
-    return new HTable(tableName, connection);
-  }
-
-  /**
-   * Callers should call close on the returned {@link HTable} instance.
-   * @param connection connection we're using to access Meta
-   * @return An {@link HTable} for <code>hbase:meta</code>
-   * @throws IOException
-   */
-  static Table getMetaHTable(final Connection connection)
-  throws IOException {
-    return getHTable(connection, TableName.META_TABLE_NAME);
+    //
+    // There should still be a way to use this method with an unmanaged connection.
+    if (connection instanceof ClusterConnection) {
+      if (((ClusterConnection) connection).isManaged()) {
+        return new HTable(TableName.META_TABLE_NAME, (ClusterConnection) connection);
+      }
+    }
+    return connection.getTable(TableName.META_TABLE_NAME);
   }
 
   /**
@@ -808,7 +803,7 @@ public class MetaTableAccessor {
    * @return a pair of HRegionInfo or PairOfSameType(null, null) if the region is not a split
    * parent
    */
-  public static PairOfSameType<HRegionInfo> getDaughterRegions(Result data) throws
IOException {
+  public static PairOfSameType<HRegionInfo> getDaughterRegions(Result data) {
     HRegionInfo splitA = getHRegionInfo(data, HConstants.SPLITA_QUALIFIER);
     HRegionInfo splitB = getHRegionInfo(data, HConstants.SPLITB_QUALIFIER);
 
@@ -822,7 +817,7 @@ public class MetaTableAccessor {
    * @return a pair of HRegionInfo or PairOfSameType(null, null) if the region is not a split
    * parent
    */
-  public static PairOfSameType<HRegionInfo> getMergeRegions(Result data) throws IOException
{
+  public static PairOfSameType<HRegionInfo> getMergeRegions(Result data) {
     HRegionInfo mergeA = getHRegionInfo(data, HConstants.MERGEA_QUALIFIER);
     HRegionInfo mergeB = getHRegionInfo(data, HConstants.MERGEB_QUALIFIER);
 
@@ -1089,8 +1084,8 @@ public class MetaTableAccessor {
 
   /**
    * Adds a hbase:meta row for the specified new region to the given catalog table. The
-   * HTable is not flushed or closed.
-   * @param meta the HTable for META
+   * Table is not flushed or closed.
+   * @param meta the Table for META
    * @param regionInfo region information
    * @throws IOException if problem connecting or updating meta
    */
@@ -1105,7 +1100,7 @@ public class MetaTableAccessor {
    * {@link #splitRegion(org.apache.hadoop.hbase.client.Connection,
    *   HRegionInfo, HRegionInfo, HRegionInfo, ServerName)}
    * if you want to do that.
-   * @param meta the HTable for META
+   * @param meta the Table for META
    * @param regionInfo region information
    * @param splitA first split daughter of the parent regionInfo
    * @param splitB second split daughter of the parent regionInfo

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
index f72d6fa..62570b9 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
@@ -282,5 +282,11 @@ public interface ClusterConnection extends HConnection {
    * @return RpcRetryingCallerFactory
    */
   RpcRetryingCallerFactory getNewRpcRetryingCallerFactory(Configuration conf);
+  
+  /**
+   * 
+   * @return true if this is a managed connection.
+   */
+  boolean isManaged();
 }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java
index 394618a..7c8f8d8 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java
@@ -437,4 +437,9 @@ abstract class ConnectionAdapter implements ClusterConnection {
   public RpcRetryingCallerFactory getNewRpcRetryingCallerFactory(Configuration conf) {
     return wrappedConnection.getNewRpcRetryingCallerFactory(conf);
   }
+  
+  @Override
+  public boolean isManaged() {
+    return wrappedConnection.isManaged();
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
index df96274..895e486 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
@@ -2476,6 +2476,11 @@ class ConnectionManager {
     public RpcRetryingCallerFactory getNewRpcRetryingCallerFactory(Configuration conf) {
       return RpcRetryingCallerFactory.instantiate(conf, this.interceptor);
     }
+
+    @Override
+    public boolean isManaged() {
+      return managed;
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
index a0fbda9..56d10e0 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
@@ -1752,7 +1752,7 @@ public class HBaseFsck extends Configured {
     for (OnlineEntry rse : hi.deployedEntries) {
       LOG.debug("Undeploy region "  + rse.hri + " from " + rse.hsa);
       try {
-        HBaseFsckRepair.closeRegionSilentlyAndWait(admin, rse.hsa, rse.hri);
+        HBaseFsckRepair.closeRegionSilentlyAndWait(connection, rse.hsa, rse.hri);
         offline(rse.hri.getRegionName());
       } catch (IOException ioe) {
         LOG.warn("Got exception when attempting to offline region "
@@ -1804,7 +1804,7 @@ public class HBaseFsck extends Configured {
     }
 
     // close the region -- close files and remove assignment
-    HBaseFsckRepair.closeRegionSilentlyAndWait(admin, serverName, hri);
+    HBaseFsckRepair.closeRegionSilentlyAndWait(connection, serverName, hri);
   }
 
   private void tryAssignmentRepair(HbckInfo hbi, String msg) throws IOException,
@@ -1969,7 +1969,7 @@ public class HBaseFsck extends Configured {
       if (shouldFixAssignments()) {
         errors.print("Trying to close the region " + descriptiveName);
         setShouldRerun();
-        HBaseFsckRepair.fixMultiAssignment(admin, hbi.metaEntry, hbi.deployedOn);
+        HBaseFsckRepair.fixMultiAssignment(connection, hbi.metaEntry, hbi.deployedOn);
       }
     } else if (inMeta && inHdfs && isMultiplyDeployed) {
       errors.reportError(ERROR_CODE.MULTI_DEPLOYED, "Region " + descriptiveName
@@ -1980,7 +1980,7 @@ public class HBaseFsck extends Configured {
       if (shouldFixAssignments()) {
         errors.print("Trying to fix assignment error...");
         setShouldRerun();
-        HBaseFsckRepair.fixMultiAssignment(admin, hbi.metaEntry, hbi.deployedOn);
+        HBaseFsckRepair.fixMultiAssignment(connection, hbi.metaEntry, hbi.deployedOn);
       }
     } else if (inMeta && inHdfs && isDeployed && !deploymentMatchesMeta)
{
       errors.reportError(ERROR_CODE.SERVER_DOES_NOT_MATCH_META, "Region "
@@ -1991,7 +1991,7 @@ public class HBaseFsck extends Configured {
       if (shouldFixAssignments()) {
         errors.print("Trying to fix assignment error...");
         setShouldRerun();
-        HBaseFsckRepair.fixMultiAssignment(admin, hbi.metaEntry, hbi.deployedOn);
+        HBaseFsckRepair.fixMultiAssignment(connection, hbi.metaEntry, hbi.deployedOn);
         HBaseFsckRepair.waitUntilAssigned(admin, hbi.getHdfsHRI());
       }
     } else {
@@ -2896,7 +2896,7 @@ public class HBaseFsck extends Configured {
           errors.print("Trying to fix a problem with hbase:meta..");
           setShouldRerun();
           // try fix it (treat is a dupe assignment)
-          HBaseFsckRepair.fixMultiAssignment(admin, metaHbckInfo.metaEntry, servers);
+          HBaseFsckRepair.fixMultiAssignment(connection, metaHbckInfo.metaEntry, servers);
         }
       }
       // rerun hbck with hopefully fixed META

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java
index bef990c..bf774d3 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java
@@ -18,23 +18,20 @@
  */
 package org.apache.hadoop.hbase.util;
 
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.MetaTableAccessor;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
-import org.apache.hadoop.hbase.MetaTableAccessor;
+import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.client.Admin;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
 import org.apache.hadoop.hbase.client.HConnection;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Table;
@@ -44,6 +41,12 @@ import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService;
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.zookeeper.KeeperException;
 
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
 /**
  * This class contains helper methods that repair parts of hbase's filesystem
  * contents.
@@ -57,22 +60,22 @@ public class HBaseFsckRepair {
    * and then force ZK unassigned node to OFFLINE to trigger assignment by
    * master.
    *
-   * @param admin HBase admin used to undeploy
+   * @param connection HBase connection to the cluster
    * @param region Region to undeploy
    * @param servers list of Servers to undeploy from
    */
-  public static void fixMultiAssignment(HBaseAdmin admin, HRegionInfo region,
+  public static void fixMultiAssignment(HConnection connection, HRegionInfo region,
       List<ServerName> servers)
   throws IOException, KeeperException, InterruptedException {
     HRegionInfo actualRegion = new HRegionInfo(region);
 
     // Close region on the servers silently
     for(ServerName server : servers) {
-      closeRegionSilentlyAndWait(admin, server, actualRegion);
+      closeRegionSilentlyAndWait(connection, server, actualRegion);
     }
 
     // Force ZK node to OFFLINE so master assigns
-    forceOfflineInZK(admin, actualRegion);
+    forceOfflineInZK(connection.getAdmin(), actualRegion);
   }
 
   /**
@@ -146,16 +149,15 @@ public class HBaseFsckRepair {
    * (default 120s) to close the region.  This bypasses the active hmaster.
    */
   @SuppressWarnings("deprecation")
-  public static void closeRegionSilentlyAndWait(HBaseAdmin admin,
+  public static void closeRegionSilentlyAndWait(HConnection connection, 
       ServerName server, HRegionInfo region) throws IOException, InterruptedException {
-    HConnection connection = admin.getConnection();
     AdminService.BlockingInterface rs = connection.getAdmin(server);
     try {
       ProtobufUtil.closeRegion(rs, server, region.getRegionName(), false);
     } catch (IOException e) {
       LOG.warn("Exception when closing region: " + region.getRegionNameAsString(), e);
     }
-    long timeout = admin.getConfiguration()
+    long timeout = connection.getConfiguration()
       .getLong("hbase.hbck.close.timeout", 120000);
     long expiration = timeout + System.currentTimeMillis();
     while (System.currentTimeMillis() < expiration) {
@@ -177,9 +179,11 @@ public class HBaseFsckRepair {
    */
   public static void fixMetaHoleOnline(Configuration conf,
       HRegionInfo hri) throws IOException {
-    Table meta = new HTable(conf, TableName.META_TABLE_NAME);
+    Connection conn = ConnectionFactory.createConnection(conf);
+    Table meta = conn.getTable(TableName.META_TABLE_NAME);
     MetaTableAccessor.addRegionToMeta(meta, hri);
     meta.close();
+    conn.close();
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
index 517316f..69d4823 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestMetaTableAccessor.java
@@ -32,6 +32,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.client.Admin;
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
 import org.apache.hadoop.hbase.client.HConnectionManager;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Result;
@@ -62,10 +63,11 @@ public class TestMetaTableAccessor {
     // responsive.  1 second is default as is ten retries.
     c.setLong("hbase.client.pause", 1000);
     c.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 10);
-    connection = HConnectionManager.getConnection(c);
+    connection = ConnectionFactory.createConnection(c);
   }
 
   @AfterClass public static void afterClass() throws Exception {
+    connection.close();
     UTIL.shutdownMiniCluster();
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java
index 1b94a06..1f83201 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestRegionRebalancing.java
@@ -21,14 +21,11 @@ package org.apache.hadoop.hbase;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.RegionLocator;
@@ -47,6 +44,12 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
 /**
  * Test whether region re-balancing works. (HBASE-71)
  */
@@ -97,7 +100,8 @@ public class TestRegionRebalancing {
   @SuppressWarnings("deprecation")
   public void testRebalanceOnRegionServerNumberChange()
   throws IOException, InterruptedException {
-    HBaseAdmin admin = new HBaseAdmin(UTIL.getConfiguration());
+    Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
+    Admin admin = connection.getAdmin();
     admin.createTable(this.desc, Arrays.copyOfRange(HBaseTestingUtility.KEYS,
         1, HBaseTestingUtility.KEYS.length));
     this.table = new HTable(UTIL.getConfiguration(), this.desc.getTableName());

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-server/src/test/java/org/apache/hadoop/hbase/client/HConnectionTestingUtility.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/HConnectionTestingUtility.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/HConnectionTestingUtility.java
index 86c8e7a..a99b047 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/HConnectionTestingUtility.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/HConnectionTestingUtility.java
@@ -137,6 +137,8 @@ public class HConnectionTestingUtility {
             RetryingCallerInterceptorFactory.NO_OP_INTERCEPTOR));
     HTableInterface t = Mockito.mock(HTableInterface.class);
     Mockito.when(c.getTable((TableName)Mockito.any())).thenReturn(t);
+    ResultScanner rs = Mockito.mock(ResultScanner.class);
+    Mockito.when(t.getScanner((Scan)Mockito.any())).thenReturn(rs);
     return c;
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationWithTags.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationWithTags.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationWithTags.java
index 2cca99c..6a39c8a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationWithTags.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationWithTags.java
@@ -40,6 +40,8 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.Tag;
 import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
 import org.apache.hadoop.hbase.client.Durability;
 import org.apache.hadoop.hbase.client.Get;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
@@ -72,6 +74,9 @@ public class TestReplicationWithTags {
 
   private static ReplicationAdmin replicationAdmin;
 
+  private static Connection connection1;
+  private static Connection connection2;
+
   private static Table htable1;
   private static Table htable2;
 
@@ -136,22 +141,13 @@ public class TestReplicationWithTags {
     fam.setMaxVersions(3);
     fam.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
     table.addFamily(fam);
-    Admin admin = null;
-    try {
-      admin = new HBaseAdmin(conf1);
+    try (Connection conn = ConnectionFactory.createConnection(conf1);
+        Admin admin = conn.getAdmin()) {
       admin.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
-    } finally {
-      if (admin != null) {
-        admin.close();
-      }
     }
-    try {
-      admin = new HBaseAdmin(conf2);
+    try (Connection conn = ConnectionFactory.createConnection(conf2);
+        Admin admin = conn.getAdmin()) {
       admin.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
-    } finally {
-      if(admin != null){
-        admin.close();
-      }
     }
     htable1 = new HTable(conf1, TABLE_NAME);
     htable1.setWriteBufferSize(1024);

http://git-wip-us.apache.org/repos/asf/hbase/blob/1c99261f/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java
index 2c71cf9..817a309 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java
@@ -265,12 +265,12 @@ public class TestHBaseFsck {
    * This method is used to undeploy a region -- close it and attempt to
    * remove its state from the Master.
    */
-  private void undeployRegion(HBaseAdmin admin, ServerName sn,
+  private void undeployRegion(HConnection conn, ServerName sn,
       HRegionInfo hri) throws IOException, InterruptedException {
     try {
-      HBaseFsckRepair.closeRegionSilentlyAndWait(admin, sn, hri);
+      HBaseFsckRepair.closeRegionSilentlyAndWait(conn, sn, hri);
       if (!hri.isMetaTable()) {
-        admin.offline(hri.getRegionName());
+        conn.getAdmin().offline(hri.getRegionName());
       }
     } catch (IOException ioe) {
       LOG.warn("Got exception when attempting to offline region "
@@ -303,6 +303,7 @@ public class TestHBaseFsck {
     dumpMeta(htd.getTableName());
 
     Map<HRegionInfo, ServerName> hris = tbl.getRegionLocations();
+    HConnection conn = (HConnection) ConnectionFactory.createConnection(conf);
     for (Entry<HRegionInfo, ServerName> e: hris.entrySet()) {
       HRegionInfo hri = e.getKey();
       ServerName hsa = e.getValue();
@@ -314,7 +315,7 @@ public class TestHBaseFsck {
 
         if (unassign) {
           LOG.info("Undeploying region " + hri + " from server " + hsa);
-          undeployRegion(new HBaseAdmin(conf), hsa, hri);
+          undeployRegion(conn, hsa, hri);
         }
 
         if (regionInfoOnly) {
@@ -351,6 +352,7 @@ public class TestHBaseFsck {
     TEST_UTIL.getMetaTableRows(htd.getTableName());
     LOG.info("*** After delete:");
     dumpMeta(htd.getTableName());
+    conn.close();
   }
 
   /**
@@ -409,8 +411,9 @@ public class TestHBaseFsck {
    * @throws IOException
    */
   void deleteTable(TableName tablename) throws IOException {
-    HBaseAdmin admin = new HBaseAdmin(conf);
-    admin.getConnection().clearRegionCache();
+    HConnection conn = (HConnection) ConnectionFactory.createConnection(conf);
+    Admin admin = conn.getAdmin();
+    conn.clearRegionCache();
     if (admin.isTableEnabled(tablename)) {
       admin.disableTableAsync(tablename);
     }
@@ -430,6 +433,8 @@ public class TestHBaseFsck {
       }
     }
     admin.deleteTable(tablename);
+    admin.close();
+    conn.close();
   }
 
   /**
@@ -807,7 +812,7 @@ public class TestHBaseFsck {
   public void testSidelineOverlapRegion() throws Exception {
     TableName table =
         TableName.valueOf("testSidelineOverlapRegion");
-    try {
+    try (HConnection conn = (HConnection) ConnectionFactory.createConnection(conf)){
       setupTable(table);
       assertEquals(ROWKEYS.length, countRows());
 
@@ -849,7 +854,7 @@ public class TestHBaseFsck {
           }
 
           HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
-          HBaseFsckRepair.closeRegionSilentlyAndWait(admin,
+          HBaseFsckRepair.closeRegionSilentlyAndWait(conn,
             cluster.getRegionServer(k).getServerName(), hbi.getHdfsHRI());
           admin.offline(regionName);
           break;
@@ -858,7 +863,7 @@ public class TestHBaseFsck {
 
       assertNotNull(regionName);
       assertNotNull(serverName);
-      Table meta = new HTable(conf, TableName.META_TABLE_NAME, executorService);
+      Table meta = conn.getTable(TableName.META_TABLE_NAME, executorService);
       Put put = new Put(regionName);
       put.add(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
         Bytes.toBytes(serverName.getHostAndPort()));
@@ -1470,8 +1475,8 @@ public class TestHBaseFsck {
   public void testSplitDaughtersNotInMeta() throws Exception {
     TableName table =
         TableName.valueOf("testSplitdaughtersNotInMeta");
-    Table meta = null;
-    try {
+    try (HConnection conn = (HConnection) ConnectionFactory.createConnection(conf);
+        Table meta = conn.getTable(TableName.META_TABLE_NAME)){
       setupTable(table);
       assertEquals(ROWKEYS.length, countRows());
 
@@ -1479,13 +1484,11 @@ public class TestHBaseFsck {
       TEST_UTIL.getHBaseAdmin().flush(table);
       HRegionLocation location = tbl.getRegionLocation("B");
 
-      meta = new HTable(conf, TableName.META_TABLE_NAME);
       HRegionInfo hri = location.getRegionInfo();
 
       // do a regular split
-      HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
       byte[] regionName = location.getRegionInfo().getRegionName();
-      admin.splitRegion(location.getRegionInfo().getRegionName(), Bytes.toBytes("BM"));
+      conn.getAdmin().splitRegion(location.getRegionInfo().getRegionName(), Bytes.toBytes("BM"));
       TestEndToEndSplitTransaction.blockUntilRegionSplit(
           TEST_UTIL.getConfiguration(), 60000, regionName, true);
 
@@ -1493,8 +1496,8 @@ public class TestHBaseFsck {
 
       // Delete daughter regions from meta, but not hdfs, unassign it.
       Map<HRegionInfo, ServerName> hris = tbl.getRegionLocations();
-      undeployRegion(admin, hris.get(daughters.getFirst()), daughters.getFirst());
-      undeployRegion(admin, hris.get(daughters.getSecond()), daughters.getSecond());
+      undeployRegion(conn, hris.get(daughters.getFirst()), daughters.getFirst());
+      undeployRegion(conn, hris.get(daughters.getSecond()), daughters.getSecond());
 
       meta.delete(new Delete(daughters.getFirst().getRegionName()));
       meta.delete(new Delete(daughters.getSecond().getRegionName()));
@@ -1528,7 +1531,6 @@ public class TestHBaseFsck {
       assertNoErrors(doFsck(conf, false)); //should be fixed by now
     } finally {
       deleteTable(table);
-      IOUtils.closeQuietly(meta);
     }
   }
 
@@ -2253,13 +2255,9 @@ public class TestHBaseFsck {
     HRegionInfo hri = metaLocation.getRegionInfo();
     if (unassign) {
       LOG.info("Undeploying meta region " + hri + " from server " + hsa);
-      Connection unmanagedConnection = ConnectionFactory.createConnection(conf);
-      HBaseAdmin admin = (HBaseAdmin) unmanagedConnection.getAdmin();
-      try {
-        undeployRegion(admin, hsa, hri);
-      } finally {
-        admin.close();
-        unmanagedConnection.close();
+      try (HConnection unmanagedConnection =
+          (HConnection) ConnectionFactory.createConnection(conf)) {
+        undeployRegion(unmanagedConnection, hsa, hri);
       }
     }
 


Mime
View raw message