PHOENIX-4934 Make BaseTest.splitSystemCatalog generic
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/0020ff20 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/0020ff20 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/0020ff20 Branch: refs/heads/omid2 Commit: 0020ff20f2a5f8d8a5fafe735bf7d201b245afdd Parents: 352cde5 Author: Thomas D'Silva <[email protected]> Authored: Fri Sep 28 17:56:22 2018 -0700 Committer: Thomas D'Silva <[email protected]> Committed: Fri Sep 28 17:58:14 2018 -0700 ---------------------------------------------------------------------- .../java/org/apache/phoenix/query/BaseTest.java | 73 +++++++++----------- 1 file changed, 34 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/0020ff20/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java index 45b61c1..5ca247b 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java @@ -1804,36 +1804,14 @@ public abstract class BaseTest { } return false; } - - /** - * Splits SYSTEM.CATALOG into multiple regions based on the table or view names passed in. - * Metadata for each table or view is moved to a separate region, - * @param tenantToTableAndViewMap map from tenant to tables and views owned by the tenant - */ - protected static void splitSystemCatalog(Map<String, List<String>> tenantToTableAndViewMap) throws Exception { - List<byte[]> splitPoints = Lists.newArrayListWithExpectedSize(5); - // add the rows keys of the table or view metadata rows - Set<String> schemaNameSet=Sets.newHashSetWithExpectedSize(15); - for (Entry<String, List<String>> entrySet : tenantToTableAndViewMap.entrySet()) { - String tenantId = entrySet.getKey(); - for (String fullName : entrySet.getValue()) { - String schemaName = SchemaUtil.getSchemaNameFromFullName(fullName); - // we don't allow SYSTEM.CATALOG to split within a schema, so to ensure each table - // or view is on a separate region they need to have a unique tenant and schema name - assertTrue("Schema names of tables/view must be unique ", schemaNameSet.add(tenantId+"."+schemaName)); - String tableName = SchemaUtil.getTableNameFromFullName(fullName); - splitPoints.add( - SchemaUtil.getTableKey(tenantId, "".equals(schemaName) ? null : schemaName, tableName)); - } - } - Collections.sort(splitPoints, Bytes.BYTES_COMPARATOR); - + + protected static void splitTable(TableName fullTableName, List<byte[]> splitPoints) throws Exception { HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); assertTrue("Needs at least two split points ", splitPoints.size() > 1); assertTrue( - "Number of split points should be less than or equal to the number of region servers ", - splitPoints.size() <= NUM_SLAVES_BASE); + "Number of split points should be less than or equal to the number of region servers ", + splitPoints.size() <= NUM_SLAVES_BASE); HBaseTestingUtility util = getUtility(); MiniHBaseCluster cluster = util.getHBaseCluster(); HMaster master = cluster.getMaster(); @@ -1848,7 +1826,7 @@ public abstract class BaseTest { availableRegionServers.push(util.getHBaseCluster().getRegionServer(i).getServerName()); } List<HRegionInfo> tableRegions = - admin.getTableRegions(PhoenixDatabaseMetaData.SYSTEM_CATALOG_HBASE_TABLE_NAME); + admin.getTableRegions(fullTableName); for (HRegionInfo hRegionInfo : tableRegions) { // filter on regions we are interested in if (regionContainsMetadataRows(hRegionInfo, splitPoints)) { @@ -1858,15 +1836,6 @@ public abstract class BaseTest { } serverToRegionsList.get(serverName).add(hRegionInfo); availableRegionServers.remove(serverName); - // Scan scan = new Scan(); - // scan.setStartRow(hRegionInfo.getStartKey()); - // scan.setStopRow(hRegionInfo.getEndKey()); - // HTable primaryTable = new HTable(getUtility().getConfiguration(), - // PhoenixDatabaseMetaData.SYSTEM_CATALOG_HBASE_TABLE_NAME); - // ResultScanner resultScanner = primaryTable.getScanner(scan); - // for (Result result : resultScanner) { - // System.out.println(result); - // } } } assertTrue("No region servers available to move regions on to ", !availableRegionServers.isEmpty()); @@ -1878,10 +1847,10 @@ public abstract class BaseTest { } } } - - // verify each region of SYSTEM.CATALOG is on its own region server + + // verify each region is on its own region server tableRegions = - admin.getTableRegions(PhoenixDatabaseMetaData.SYSTEM_CATALOG_HBASE_TABLE_NAME); + admin.getTableRegions(fullTableName); Set<ServerName> serverNames = Sets.newHashSet(); for (HRegionInfo hRegionInfo : tableRegions) { // filter on regions we are interested in @@ -1896,6 +1865,32 @@ public abstract class BaseTest { } } } + + /** + * Splits SYSTEM.CATALOG into multiple regions based on the table or view names passed in. + * Metadata for each table or view is moved to a separate region, + * @param tenantToTableAndViewMap map from tenant to tables and views owned by the tenant + */ + protected static void splitSystemCatalog(Map<String, List<String>> tenantToTableAndViewMap) throws Exception { + List<byte[]> splitPoints = Lists.newArrayListWithExpectedSize(5); + // add the rows keys of the table or view metadata rows + Set<String> schemaNameSet=Sets.newHashSetWithExpectedSize(15); + for (Entry<String, List<String>> entrySet : tenantToTableAndViewMap.entrySet()) { + String tenantId = entrySet.getKey(); + for (String fullName : entrySet.getValue()) { + String schemaName = SchemaUtil.getSchemaNameFromFullName(fullName); + // we don't allow SYSTEM.CATALOG to split within a schema, so to ensure each table + // or view is on a separate region they need to have a unique tenant and schema name + assertTrue("Schema names of tables/view must be unique ", schemaNameSet.add(tenantId+"."+schemaName)); + String tableName = SchemaUtil.getTableNameFromFullName(fullName); + splitPoints.add( + SchemaUtil.getTableKey(tenantId, "".equals(schemaName) ? null : schemaName, tableName)); + } + } + Collections.sort(splitPoints, Bytes.BYTES_COMPARATOR); + + splitTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_HBASE_TABLE_NAME, splitPoints); + } private static int getRegionServerIndex(MiniHBaseCluster cluster, ServerName serverName) { // we have a small number of region servers, this should be fine for now.
