From 7d0f5eba2d9fc9dcc8c8900ced86560f7443257f Mon Sep 17 00:00:00 2001 From: stack Date: Fri, 19 Sep 2014 11:02:35 -0700 Subject: [PATCH] HBASE-11462 MetaTableAccessor shouldn't use ZooKeeeper (Mikhail Antononv) --- .../hadoop/hbase/MetaTableAccessor.java | 48 ++++++++----------- .../hadoop/hbase/client/HBaseAdmin.java | 35 ++++++++++---- .../hbase/zookeeper/MetaTableLocator.java | 34 +++++++++++++ .../hbase/master/AssignmentManager.java | 11 +++-- .../master/handler/EnableTableHandler.java | 15 ++++-- .../master/handler/TableEventHandler.java | 10 ++-- .../snapshot/MasterSnapshotVerifier.java | 9 +++- .../master/snapshot/TakeSnapshotHandler.java | 12 +++-- .../MasterFlushTableProcedureManager.java | 14 ++++-- .../hadoop/hbase/TestMetaTableAccessor.java | 19 ++++---- ...estLoadIncrementalHFilesSplitRecovery.java | 2 +- .../hadoop/hbase/master/TestMaster.java | 7 ++- ...TestMasterOperationsForRegionReplicas.java | 11 ++--- .../TestRegionMergeTransactionOnCluster.java | 17 ++++--- .../hadoop/hbase/util/TestMergeTable.java | 6 +-- 15 files changed, 156 insertions(+), 94 deletions(-) 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 04979b56dcf..b4ecdd929f9 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 @@ -44,8 +44,6 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.PairOfSameType; import org.apache.hadoop.hbase.util.Threads; -import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; -import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; import java.io.IOException; import java.io.InterruptedIOException; @@ -367,22 +365,21 @@ public class MetaTableAccessor { } /** - * Gets all of the regions of the specified table. - * @param zkw zookeeper connection to access meta table + * Gets all of the regions of the specified table. Do not use this method + * to get meta table regions, use methods in MetaTableLocator instead. * @param hConnection connection we're using * @param tableName table we're looking for * @return Ordered list of {@link HRegionInfo}. * @throws IOException */ - public static List getTableRegions(ZooKeeperWatcher zkw, - HConnection hConnection, TableName tableName) + public static List getTableRegions(HConnection hConnection, TableName tableName) throws IOException { - return getTableRegions(zkw, hConnection, tableName, false); + return getTableRegions(hConnection, tableName, false); } /** - * Gets all of the regions of the specified table. - * @param zkw zookeeper connection to access meta table + * Gets all of the regions of the specified table. Do not use this method + * to get meta table regions, use methods in MetaTableLocator instead. * @param hConnection connection we're using * @param tableName table we're looking for * @param excludeOfflinedSplitParents If true, do not include offlined split @@ -390,12 +387,12 @@ public class MetaTableAccessor { * @return Ordered list of {@link HRegionInfo}. * @throws IOException */ - public static List getTableRegions(ZooKeeperWatcher zkw, - HConnection hConnection, TableName tableName, final boolean excludeOfflinedSplitParents) - throws IOException { - List> result = null; + public static List getTableRegions(HConnection hConnection, + TableName tableName, final boolean excludeOfflinedSplitParents) + throws IOException { + List> result; try { - result = getTableRegionsAndLocations(zkw, hConnection, tableName, + result = getTableRegionsAndLocations(hConnection, tableName, excludeOfflinedSplitParents); } catch (InterruptedException e) { throw (InterruptedIOException)new InterruptedIOException().initCause(e); @@ -457,7 +454,7 @@ public class MetaTableAccessor { } /** - * @param zkw zookeeper connection to access meta table + * Do not use this method to get meta table regions, use methods in MetaTableLocator instead. * @param hConnection connection we're using * @param tableName table we're looking for * @return Return list of regioninfos and server. @@ -465,14 +462,13 @@ public class MetaTableAccessor { * @throws InterruptedException */ public static List> - getTableRegionsAndLocations(ZooKeeperWatcher zkw, - HConnection hConnection, TableName tableName) - throws IOException, InterruptedException { - return getTableRegionsAndLocations(zkw, hConnection, tableName, true); + getTableRegionsAndLocations(HConnection hConnection, TableName tableName) + throws IOException, InterruptedException { + return getTableRegionsAndLocations(hConnection, tableName, true); } /** - * @param zkw ZooKeeperWatcher instance we're using to get hbase:meta location + * Do not use this method to get meta table regions, use methods in MetaTableLocator instead. * @param hConnection connection we're using * @param tableName table to work with * @return Return list of regioninfos and server addresses. @@ -480,17 +476,11 @@ public class MetaTableAccessor { * @throws InterruptedException */ public static List> getTableRegionsAndLocations( - ZooKeeperWatcher zkw, HConnection hConnection, final TableName tableName, + HConnection hConnection, final TableName tableName, final boolean excludeOfflinedSplitParents) throws IOException, InterruptedException { - if (tableName.equals(TableName.META_TABLE_NAME)) { - // If meta, do a bit of special handling. - ServerName serverName = new MetaTableLocator().getMetaRegionLocation(zkw); - List> list = - new ArrayList>(); - list.add(new Pair(HRegionInfo.FIRST_META_REGIONINFO, - serverName)); - return list; + throw new IOException("This method can't be used to locate meta regions;" + + " use MetaTableLocator instead"); } // Make a version of CollectingVisitor that collects HRegionInfo and ServerAddress CollectingVisitor> visitor = diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index aa8d21e106b..232538d6dd7 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -146,6 +146,7 @@ import org.apache.hadoop.hbase.util.Addressing; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.Pair; +import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.util.StringUtils; @@ -1724,8 +1725,12 @@ public class HBaseAdmin implements Admin { checkTableExists(tableName); zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), new ThrowableAbortable()); - List> pairs = - MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, tableName); + List> pairs; + if (TableName.META_TABLE_NAME.equals(tableName)) { + pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper); + } else { + pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName); + } for (Pair pair: pairs) { if (pair.getFirst().isOffline()) continue; if (pair.getSecond() == null) continue; @@ -2078,8 +2083,12 @@ public class HBaseAdmin implements Admin { checkTableExists(tableName); zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), new ThrowableAbortable()); - List> pairs = - MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, tableName); + List> pairs; + if (TableName.META_TABLE_NAME.equals(tableName)) { + pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper); + } else { + pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName); + } for (Pair pair: pairs) { // May not be a server for a particular row if (pair.getSecond() == null) continue; @@ -2559,13 +2568,17 @@ public class HBaseAdmin implements Admin { ZooKeeperWatcher zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), new ThrowableAbortable()); - List Regions = null; + List regions = null; try { - Regions = MetaTableAccessor.getTableRegions(zookeeper, connection, tableName, true); + if (TableName.META_TABLE_NAME.equals(tableName)) { + regions = new MetaTableLocator().getMetaRegions(zookeeper); + } else { + regions = MetaTableAccessor.getTableRegions(connection, tableName, true); + } } finally { zookeeper.close(); } - return Regions; + return regions; } public List getTableRegions(final byte[] tableName) @@ -2664,8 +2677,12 @@ public class HBaseAdmin implements Admin { new ThrowableAbortable()); try { checkTableExists(tableName); - List> pairs = - MetaTableAccessor.getTableRegionsAndLocations(zookeeper, connection, tableName); + List> pairs; + if (TableName.META_TABLE_NAME.equals(tableName)) { + pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper); + } else { + pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName); + } for (Pair pair: pairs) { if (pair.getFirst().isOffline()) continue; if (pair.getSecond() == null) continue; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java index f0c1d87a20d..98a69ffd73d 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java @@ -24,6 +24,8 @@ import java.net.NoRouteToHostException; import java.net.SocketException; import java.net.SocketTimeoutException; import java.rmi.UnknownHostException; +import java.util.ArrayList; +import java.util.List; import javax.annotation.Nullable; @@ -48,6 +50,7 @@ import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos.MetaRegionServer; import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.ipc.RemoteException; import org.apache.zookeeper.KeeperException; @@ -87,6 +90,37 @@ public class MetaTableLocator { return getMetaRegionLocation(zkw) != null; } + /** + * @param zkw ZooKeeper watcher to be used + * @return meta table regions and their locations. + */ + public List> getMetaRegionsAndLocations(ZooKeeperWatcher zkw) { + ServerName serverName = new MetaTableLocator().getMetaRegionLocation(zkw); + List> list = new ArrayList<>(); + list.add(new Pair<>(HRegionInfo.FIRST_META_REGIONINFO, serverName)); + return list; + } + + /** + * @param zkw ZooKeeper watcher to be used + * @return List of meta regions + */ + public List getMetaRegions(ZooKeeperWatcher zkw) { + List> result; + result = getMetaRegionsAndLocations(zkw); + return getListOfHRegionInfos(result); + } + + private List getListOfHRegionInfos( + final List> pairs) { + if (pairs == null || pairs.isEmpty()) return null; + List result = new ArrayList<>(pairs.size()); + for (Pair pair: pairs) { + result.add(pair.getFirst()); + } + return result; + } + /** * Gets the meta region location, if available. Does not block. * @param zkw zookeeper connection to use diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java index 7e0a5e29803..f184ba077de 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java @@ -84,6 +84,7 @@ import org.apache.hadoop.hbase.util.KeyLocker; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.PairOfSameType; import org.apache.hadoop.hbase.util.Threads; +import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; import org.apache.hadoop.ipc.RemoteException; import org.apache.zookeeper.KeeperException; @@ -335,9 +336,13 @@ public class AssignmentManager { */ public Pair getReopenStatus(TableName tableName) throws IOException { - List hris = MetaTableAccessor.getTableRegions( - this.server.getZooKeeper(), this.server.getShortCircuitConnection(), - tableName, true); + List hris; + if (TableName.META_TABLE_NAME.equals(tableName)) { + hris = new MetaTableLocator().getMetaRegions(server.getZooKeeper()); + } else { + hris = MetaTableAccessor.getTableRegions(server.getShortCircuitConnection(), tableName, true); + } + Integer pending = 0; for (HRegionInfo hri : hris) { String name = hri.getEncodedName(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java index 5f313898b9a..3f3c81a21a8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java @@ -48,6 +48,7 @@ import org.apache.hadoop.hbase.master.ServerManager; import org.apache.hadoop.hbase.master.TableLockManager; import org.apache.hadoop.hbase.master.TableLockManager.TableLock; import org.apache.hadoop.hbase.util.Pair; +import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; /** * Handler to run enable of a table. @@ -170,9 +171,15 @@ public class EnableTableHandler extends EventHandler { ServerManager serverManager = ((HMaster)this.server).getServerManager(); // Get the regions of this table. We're done when all listed // tables are onlined. - List> tableRegionsAndLocations = MetaTableAccessor - .getTableRegionsAndLocations(this.server.getZooKeeper(), - this.server.getShortCircuitConnection(), tableName, true); + List> tableRegionsAndLocations; + if (TableName.META_TABLE_NAME.equals(tableName)) { + tableRegionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations( + server.getZooKeeper()); + } else { + tableRegionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations( + server.getShortCircuitConnection(), tableName, true); + } + int countOfRegionsInTable = tableRegionsAndLocations.size(); Map regionsToAssign = regionsToAssignWithServerName(tableRegionsAndLocations); @@ -202,7 +209,7 @@ public class EnableTableHandler extends EventHandler { this.assignmentManager.getBalancer().retainAssignment(regionsToAssign, onlineServers); LOG.info("Bulk assigning " + regionsCount + " region(s) across " + bulkPlan.size() + " server(s), retainAssignment=true"); - + BulkAssigner ba = new GeneralBulkAssigner(this.server, bulkPlan, this.assignmentManager, true); try { if (ba.bulkAssign()) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java index 8993840a650..1a4d1f613ea 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/TableEventHandler.java @@ -51,6 +51,7 @@ import org.apache.hadoop.hbase.util.Bytes; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; /** * Base class for performing operations against tables. @@ -125,9 +126,12 @@ public abstract class TableEventHandler extends EventHandler { LOG.info("Handling table operation " + eventType + " on table " + tableName); - List hris = - MetaTableAccessor.getTableRegions(this.server.getZooKeeper(), - this.server.getShortCircuitConnection(), tableName); + List hris; + if (TableName.META_TABLE_NAME.equals(tableName)) { + hris = new MetaTableLocator().getMetaRegions(server.getZooKeeper()); + } else { + hris = MetaTableAccessor.getTableRegions(server.getShortCircuitConnection(), tableName); + } handleTableOperation(hris); if (eventType.isOnlineSchemaChangeSupported() && this.masterServices. getAssignmentManager().getTableStateManager().isTableState( diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/MasterSnapshotVerifier.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/MasterSnapshotVerifier.java index b140300b87c..8a1b11373aa 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/MasterSnapshotVerifier.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/MasterSnapshotVerifier.java @@ -42,6 +42,7 @@ import org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException; import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils; import org.apache.hadoop.hbase.snapshot.SnapshotManifest; import org.apache.hadoop.hbase.snapshot.SnapshotReferenceUtil; +import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; /** * General snapshot verification on the master. @@ -150,8 +151,12 @@ public final class MasterSnapshotVerifier { * @throws IOException if we can't reach hbase:meta or read the files from the FS */ private void verifyRegions(final SnapshotManifest manifest) throws IOException { - List regions = MetaTableAccessor.getTableRegions( - this.services.getZooKeeper(), this.services.getShortCircuitConnection(), tableName); + List regions; + if (TableName.META_TABLE_NAME.equals(tableName)) { + regions = new MetaTableLocator().getMetaRegions(services.getZooKeeper()); + } else { + regions = MetaTableAccessor.getTableRegions(services.getShortCircuitConnection(), tableName); + } // Remove the non-default regions RegionReplicaUtil.removeNonDefaultRegions(regions); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/TakeSnapshotHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/TakeSnapshotHandler.java index 9857acff852..f7c7b5fe6fe 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/TakeSnapshotHandler.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/TakeSnapshotHandler.java @@ -54,6 +54,7 @@ import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils; import org.apache.hadoop.hbase.snapshot.SnapshotManifest; import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.Pair; +import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; import org.apache.zookeeper.KeeperException; /** @@ -167,9 +168,14 @@ public abstract class TakeSnapshotHandler extends EventHandler implements Snapsh snapshotManifest.addTableDescriptor(this.htd); monitor.rethrowException(); - List> regionsAndLocations = - MetaTableAccessor.getTableRegionsAndLocations(this.server.getZooKeeper(), - this.server.getShortCircuitConnection(), snapshotTable, false); + List> regionsAndLocations; + if (TableName.META_TABLE_NAME.equals(snapshotTable)) { + regionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations( + server.getZooKeeper()); + } else { + regionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations( + server.getShortCircuitConnection(), snapshotTable, false); + } // run the snapshot snapshotRegions(regionsAndLocations); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/flush/MasterFlushTableProcedureManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/flush/MasterFlushTableProcedureManager.java index e92b1e0420d..abee323549b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/flush/MasterFlushTableProcedureManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/procedure/flush/MasterFlushTableProcedureManager.java @@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.procedure.ProcedureCoordinatorRpcs; import org.apache.hadoop.hbase.procedure.ZKProcedureCoordinatorRpcs; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ProcedureDescription; import org.apache.hadoop.hbase.util.Pair; +import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; import org.apache.zookeeper.KeeperException; import com.google.common.collect.Lists; @@ -124,12 +125,15 @@ public class MasterFlushTableProcedureManager extends MasterProcedureManager { // It is possible that regions may move after we get the region server list. // Each region server will get its own online regions for the table. // We may still miss regions that need to be flushed. - List> regionsAndLocations = null; + List> regionsAndLocations; try { - regionsAndLocations = - MetaTableAccessor.getTableRegionsAndLocations(this.master.getZooKeeper(), - this.master.getShortCircuitConnection(), - TableName.valueOf(desc.getInstance()), false); + if (TableName.META_TABLE_NAME.equals(tableName)) { + regionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations( + master.getZooKeeper()); + } else { + regionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations( + master.getShortCircuitConnection(), tableName, false); + } } catch (InterruptedException e1) { String msg = "Failed to get regions for '" + desc.getInstance() + "'"; LOG.error(msg); 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 1a43796dc21..66a859ef6a4 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 @@ -41,6 +41,7 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Pair; +import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -198,14 +199,13 @@ public class TestMetaTableAccessor { abstract void metaTask() throws Throwable; } - @Test public void testGetRegionsCatalogTables() + @Test public void testGetRegionsFromMetaTable() throws IOException, InterruptedException { List regions = - MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(), - hConnection, TableName.META_TABLE_NAME); + new MetaTableLocator().getMetaRegions(UTIL.getZooKeeperWatcher()); assertTrue(regions.size() >= 1); - assertTrue(MetaTableAccessor.getTableRegionsAndLocations(UTIL.getZooKeeperWatcher(), - hConnection,TableName.META_TABLE_NAME).size() >= 1); + assertTrue(new MetaTableLocator().getMetaRegionsAndLocations( + UTIL.getZooKeeperWatcher()).size() >= 1); } @Test public void testTableExists() throws IOException { @@ -252,17 +252,14 @@ public class TestMetaTableAccessor { // Now make sure we only get the regions from 1 of the tables at a time - assertEquals(1, MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(), - hConnection, name).size()); - assertEquals(1, MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(), - hConnection, greaterName).size()); + assertEquals(1, MetaTableAccessor.getTableRegions(hConnection, name).size()); + assertEquals(1, MetaTableAccessor.getTableRegions(hConnection, greaterName).size()); } private static List testGettingTableRegions(final HConnection hConnection, final TableName name, final int regionCount) throws IOException, InterruptedException { - List regions = MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(), - hConnection, name); + List regions = MetaTableAccessor.getTableRegions(hConnection, name); assertEquals(regionCount, regions.size()); Pair pair = MetaTableAccessor.getRegion(hConnection, regions.get(0).getRegionName()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFilesSplitRecovery.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFilesSplitRecovery.java index 6ea14c93b82..e7b1516fa3f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFilesSplitRecovery.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestLoadIncrementalHFilesSplitRecovery.java @@ -477,7 +477,7 @@ public class TestLoadIncrementalHFilesSplitRecovery { // Mess it up by leaving a hole in the hbase:meta HConnection hConnection = HConnectionManager.getConnection(util.getConfiguration()); List regionInfos = MetaTableAccessor.getTableRegions( - util.getZooKeeperWatcher(), hConnection, TableName.valueOf(tableName)); + hConnection, TableName.valueOf(tableName)); for (HRegionInfo regionInfo : regionInfos) { if (Bytes.equals(regionInfo.getStartKey(), HConstants.EMPTY_BYTE_ARRAY)) { MetaTableAccessor.deleteRegion(hConnection, regionInfo); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java index 6129dd7668c..73a16631b7a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java @@ -86,8 +86,7 @@ public class TestMaster { TEST_UTIL.loadTable(ht, FAMILYNAME, false); ht.close(); - List> tableRegions = - MetaTableAccessor.getTableRegionsAndLocations(m.getZooKeeper(), + List> tableRegions = MetaTableAccessor.getTableRegionsAndLocations( m.getShortCircuitConnection(), TABLENAME); LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions)); assertEquals(1, tableRegions.size()); @@ -105,8 +104,8 @@ public class TestMaster { Thread.sleep(100); } LOG.info("Making sure we can call getTableRegions while opening"); - tableRegions = MetaTableAccessor.getTableRegionsAndLocations(m.getZooKeeper(), - m.getShortCircuitConnection(), TABLENAME, false); + tableRegions = MetaTableAccessor.getTableRegionsAndLocations(m.getShortCircuitConnection(), + TABLENAME, false); LOG.info("Regions: " + Joiner.on(',').join(tableRegions)); // We have three regions because one is split-in-progress diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java index 8f894c8d96c..61967b780ab 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java @@ -95,7 +95,7 @@ public class TestMasterOperationsForRegionReplicas { admin.createTable(desc, Bytes.toBytes("A"), Bytes.toBytes("Z"), numRegions); validateNumberOfRowsInMeta(table, numRegions, admin.getConnection()); - List hris = MetaTableAccessor.getTableRegions(TEST_UTIL.getZooKeeperWatcher(), + List hris = MetaTableAccessor.getTableRegions( admin.getConnection(), table); assert(hris.size() == numRegions * numReplica); } finally { @@ -117,8 +117,7 @@ public class TestMasterOperationsForRegionReplicas { TEST_UTIL.waitTableEnabled(table.getName()); validateNumberOfRowsInMeta(table, numRegions, admin.getConnection()); - List hris = MetaTableAccessor.getTableRegions(TEST_UTIL.getZooKeeperWatcher(), - admin.getConnection(), table); + List hris = MetaTableAccessor.getTableRegions(admin.getConnection(), table); assert(hris.size() == numRegions * numReplica); // check that the master created expected number of RegionState objects for (int i = 0; i < numRegions; i++) { @@ -211,8 +210,7 @@ public class TestMasterOperationsForRegionReplicas { .getAssignmentManager().getRegionStates().getRegionsOfTable(table); assert(regions.size() == numRegions * numReplica); //also make sure the meta table has the replica locations removed - hris = MetaTableAccessor.getTableRegions(TEST_UTIL.getZooKeeperWatcher(), - admin.getConnection(), table); + hris = MetaTableAccessor.getTableRegions(admin.getConnection(), table); assert(hris.size() == numRegions * numReplica); //just check that the number of default replica regions in the meta table are the same //as the number of regions the table was created with, and the count of the @@ -247,8 +245,7 @@ public class TestMasterOperationsForRegionReplicas { admin.createTable(desc, Bytes.toBytes("A"), Bytes.toBytes("Z"), numRegions); TEST_UTIL.waitTableEnabled(table.getName()); Set tableRows = new HashSet(); - List hris = MetaTableAccessor.getTableRegions(TEST_UTIL.getZooKeeperWatcher(), - admin.getConnection(), table); + List hris = MetaTableAccessor.getTableRegions(admin.getConnection(), table); for (HRegionInfo hri : hris) { tableRows.add(hri.getRegionName()); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java index a0cc36dd70c..07c1a582d42 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java @@ -173,8 +173,7 @@ public class TestRegionMergeTransactionOnCluster { table.close(); List> tableRegions = MetaTableAccessor - .getTableRegionsAndLocations(master.getZooKeeper(), - master.getShortCircuitConnection(), tableName); + .getTableRegionsAndLocations(master.getShortCircuitConnection(), tableName); HRegionInfo mergedRegionInfo = tableRegions.get(0).getFirst(); HTableDescriptor tableDescritor = master.getTableDescriptors().get( tableName); @@ -291,13 +290,13 @@ public class TestRegionMergeTransactionOnCluster { // Create table and load data. createTableAndLoadData(master, tableName, 5, 2); List> initialRegionToServers = - MetaTableAccessor.getTableRegionsAndLocations(master.getZooKeeper(), + MetaTableAccessor.getTableRegionsAndLocations( master.getShortCircuitConnection(), tableName); // Merge 1st and 2nd region PairOfSameType mergedRegions = mergeRegionsAndVerifyRegionNum(master, tableName, 0, 2, 5 * 2 - 2); List> currentRegionToServers = - MetaTableAccessor.getTableRegionsAndLocations(master.getZooKeeper(), + MetaTableAccessor.getTableRegionsAndLocations( master.getShortCircuitConnection(), tableName); List initialRegions = new ArrayList(); for (Pair p : initialRegionToServers) { @@ -337,7 +336,7 @@ public class TestRegionMergeTransactionOnCluster { HMaster master, TableName tablename, int regionAnum, int regionBnum) throws Exception { List> tableRegions = MetaTableAccessor - .getTableRegionsAndLocations(master.getZooKeeper(), + .getTableRegionsAndLocations( master.getShortCircuitConnection(), tablename); HRegionInfo regionA = tableRegions.get(regionAnum).getFirst(); HRegionInfo regionB = tableRegions.get(regionBnum).getFirst(); @@ -354,7 +353,7 @@ public class TestRegionMergeTransactionOnCluster { long timeout = System.currentTimeMillis() + waitTime; while (System.currentTimeMillis() < timeout) { tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations( - master.getZooKeeper(), master.getShortCircuitConnection(), tablename); + master.getShortCircuitConnection(), tablename); tableRegionsInMaster = master.getAssignmentManager().getRegionStates() .getRegionsOfTable(tablename); if (tableRegionsInMeta.size() == expectedRegionNum @@ -365,7 +364,7 @@ public class TestRegionMergeTransactionOnCluster { } tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations( - master.getZooKeeper(), master.getShortCircuitConnection(), tablename); + master.getShortCircuitConnection(), tablename); LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta)); assertEquals(expectedRegionNum, tableRegionsInMeta.size()); } @@ -395,14 +394,14 @@ public class TestRegionMergeTransactionOnCluster { List> tableRegions; while (System.currentTimeMillis() < timeout) { tableRegions = MetaTableAccessor.getTableRegionsAndLocations( - master.getZooKeeper(), master.getShortCircuitConnection(), tablename); + master.getShortCircuitConnection(), tablename); if (tableRegions.size() == numRegions * replication) break; Thread.sleep(250); } tableRegions = MetaTableAccessor.getTableRegionsAndLocations( - master.getZooKeeper(), master.getShortCircuitConnection(), tablename); + master.getShortCircuitConnection(), tablename); LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions)); assertEquals(numRegions * replication, tableRegions.size()); return table; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMergeTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMergeTable.java index 418f9770bd2..828dcfa699d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMergeTable.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestMergeTable.java @@ -118,16 +118,14 @@ public class TestMergeTable { HConnection hConnection = HConnectionManager.getConnection(c); List originalTableRegions = - MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(), hConnection, - desc.getTableName()); + MetaTableAccessor.getTableRegions(hConnection, desc.getTableName()); LOG.info("originalTableRegions size=" + originalTableRegions.size() + "; " + originalTableRegions); Admin admin = new HBaseAdmin(c); admin.disableTable(desc.getTableName()); HMerge.merge(c, FileSystem.get(c), desc.getTableName()); List postMergeTableRegions = - MetaTableAccessor.getTableRegions(UTIL.getZooKeeperWatcher(), hConnection, - desc.getTableName()); + MetaTableAccessor.getTableRegions(hConnection, desc.getTableName()); LOG.info("postMergeTableRegions size=" + postMergeTableRegions.size() + "; " + postMergeTableRegions); assertTrue("originalTableRegions=" + originalTableRegions.size() +