diff --git a/hbase2.1/hbase-common-2.1/src/main/java/com/kakao/hbase/specific/CommandAdapter.java b/hbase2.1/hbase-common-2.1/src/main/java/com/kakao/hbase/specific/CommandAdapter.java index 06d25e8..ce98869 100644 --- a/hbase2.1/hbase-common-2.1/src/main/java/com/kakao/hbase/specific/CommandAdapter.java +++ b/hbase2.1/hbase-common-2.1/src/main/java/com/kakao/hbase/specific/CommandAdapter.java @@ -119,9 +119,23 @@ public static void loginUserFromSubject(Configuration conf, Subject subject) thr } @SuppressWarnings("SortedCollectionWithNonComparableKeys") - public static NavigableMap regionServerMap(Args args, Admin admin, final boolean offlined) throws IOException { + public static NavigableMap regionServerMap(Args args, Admin admin) throws IOException { long timestamp = System.currentTimeMillis(); + final Set disabledTables = new HashSet<>(); + Set tables = Args.tables(args, admin); + if (tables.size() == 0) { + for (TableDescriptor td : admin.listTableDescriptors()) { + if (admin.isTableDisabled(td.getTableName())) + disabledTables.add(td.getTableName()); + } + } else { + for (TableName table : Args.tables(args, admin)) { + if (admin.isTableDisabled(table)) + disabledTables.add(table); + } + } + final NavigableMap regions = new TreeMap<>(); MetaTableAccessor.Visitor visitor = new MetaTableAccessor.DefaultVisitorBase() { @Override @@ -131,8 +145,9 @@ public boolean visitInternal(Result result) { for (HRegionLocation loc : locations.getRegionLocations()) { if (loc != null) { RegionInfo regionInfo = loc.getRegion(); - if (regionInfo.getTable().getNameAsString().startsWith("hbase:")) return true; - if (regionInfo.isOffline() && !offlined) return true; + TableName table = regionInfo.getTable(); + if (table.getNameAsString().startsWith("hbase:")) return true; + if (disabledTables.contains(table)) return true; regions.put(regionInfo, loc.getServerName()); } } @@ -147,13 +162,19 @@ public boolean visitInternal(Result result) { @SuppressWarnings("SortedCollectionWithNonComparableKeys") public static NavigableMap regionServerMap(Args args, - Admin admin, final Set tableNames, final boolean offlined) throws IOException { + Admin admin, final Set tableNames) throws IOException { long timestamp = System.currentTimeMillis(); final NavigableMap regions = new TreeMap<>(); if (tableNames.size() == 1) { - return regionServerMap(args, admin, tableNames.toArray(new TableName[1])[0], offlined); + return regionServerMap(args, admin, tableNames.toArray(new TableName[1])[0]); } else if (tableNames.size() > 1) { + final Set disableTables = new HashSet<>(); + for (TableName tableName : tableNames) { + if (admin.isTableDisabled(tableName)) + disableTables.add(tableName); + } + MetaTableAccessor.Visitor visitor = new MetaTableAccessor.DefaultVisitorBase() { @Override public boolean visitInternal(Result result) { @@ -164,7 +185,7 @@ public boolean visitInternal(Result result) { RegionInfo regionInfo = loc.getRegion(); TableName table = regionInfo.getTable(); if (table.getNameAsString().startsWith("hbase:")) return true; - if (regionInfo.isOffline() && !offlined) return true; + if (disableTables.contains(table)) return true; if (tableNames.contains(table)) regions.put(regionInfo, loc.getServerName()); } @@ -181,9 +202,10 @@ public boolean visitInternal(Result result) { @SuppressWarnings("SortedCollectionWithNonComparableKeys") private static NavigableMap regionServerMap(Args args, - Admin admin, final TableName tableName, final boolean offlined) throws IOException { + Admin admin, final TableName tableName) throws IOException { long timestamp = System.currentTimeMillis(); + final boolean tableDisabled = admin.isTableDisabled(tableName); final NavigableMap regions = new TreeMap<>(); MetaTableAccessor.Visitor visitor = new MetaTableAccessor.TableVisitorBase(tableName) { @Override @@ -193,7 +215,7 @@ public boolean visitInternal(Result result) { for (HRegionLocation loc : locations.getRegionLocations()) { if (loc != null) { RegionInfo regionInfo = loc.getRegion(); - if (regionInfo.isOffline() && !offlined) return true; + if (tableDisabled) return true; regions.put(regionInfo, loc.getServerName()); } } diff --git a/hbase2.1/hbase-table-stat-2.1/src/main/java/com/kakao/hbase/stat/load/TableInfo.java b/hbase2.1/hbase-table-stat-2.1/src/main/java/com/kakao/hbase/stat/load/TableInfo.java index 28eab83..4997ed3 100644 --- a/hbase2.1/hbase-table-stat-2.1/src/main/java/com/kakao/hbase/stat/load/TableInfo.java +++ b/hbase2.1/hbase-table-stat-2.1/src/main/java/com/kakao/hbase/stat/load/TableInfo.java @@ -113,9 +113,9 @@ private void initializeRegionServerMap() throws Exception { Set tables = Args.tables(args, admin); if (tables.isEmpty()) { - regionServerMap = CommandAdapter.regionServerMap(args, admin, false); + regionServerMap = CommandAdapter.regionServerMap(args, admin); } else { - regionServerMap = CommandAdapter.regionServerMap(args, admin, tables, false); + regionServerMap = CommandAdapter.regionServerMap(args, admin, tables); } clean(regionServerMap); diff --git a/hbase2.1/hbase-table-stat-2.1/src/test/java/com/kakao/hbase/stat/TableStatTest.java b/hbase2.1/hbase-table-stat-2.1/src/test/java/com/kakao/hbase/stat/TableStatTest.java index 5bfc099..c36a639 100644 --- a/hbase2.1/hbase-table-stat-2.1/src/test/java/com/kakao/hbase/stat/TableStatTest.java +++ b/hbase2.1/hbase-table-stat-2.1/src/test/java/com/kakao/hbase/stat/TableStatTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import java.util.Set; -import java.util.regex.Pattern; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -53,15 +52,11 @@ public void testDisableEnableDrop() throws Exception { Assert.assertEquals(loadEntryLength, command.getLoad().getSummaryPrev().size()); // disable table - System.out.println(admin.listTableDescriptors(Pattern.compile(".*"))); admin.disableTable(tableName); waitForDisabled(tableName); - System.out.println(admin.isTableDisabled(tableName)); - System.out.println(admin.listTableDescriptors(Pattern.compile(".*"))); // iteration 3 command.run(); - //fixme Assert.assertEquals(0, command.getLoad().getLoadMap().size()); Assert.assertEquals(1, command.getLoad().getLoadMapPrev().size()); Assert.assertEquals(0, command.getLoad().getSummary().size()); @@ -107,7 +102,6 @@ public void testAllTables() throws Exception { TableStat command = new TableStat(admin, new StatArgs(args)); // iteration 1 - //fixme command.run(); Assert.assertEquals(1, command.getLoad().getLoadMap().size()); Assert.assertEquals(0, command.getLoad().getLoadMapPrev().size()); @@ -149,7 +143,6 @@ public void testTableRegex() throws Exception { waitForDisabled(tableName); // iteration 2 - //fixme command.run(); Assert.assertEquals(1, command.getLoad().getLoadMap().size()); Assert.assertEquals(2, command.getLoad().getLoadMapPrev().size());