|
22 | 22 |
|
23 | 23 | import java.io.IOException; |
24 | 24 | import java.io.UncheckedIOException; |
| 25 | +import java.util.ArrayList; |
25 | 26 | import java.util.EnumSet; |
26 | 27 | import java.util.HashMap; |
| 28 | +import java.util.List; |
27 | 29 | import java.util.Map; |
28 | 30 | import org.apache.hadoop.conf.Configuration; |
29 | 31 | import org.apache.hadoop.hbase.ClusterMetrics; |
30 | 32 | import org.apache.hadoop.hbase.CompatibilityFactory; |
31 | 33 | import org.apache.hadoop.hbase.HBaseClassTestRule; |
32 | 34 | import org.apache.hadoop.hbase.HBaseTestingUtil; |
| 35 | +import org.apache.hadoop.hbase.NamespaceDescriptor; |
33 | 36 | import org.apache.hadoop.hbase.ServerMetricsBuilder; |
34 | 37 | import org.apache.hadoop.hbase.ServerName; |
35 | 38 | import org.apache.hadoop.hbase.SingleProcessHBaseCluster; |
@@ -225,4 +228,70 @@ public void testClusterMetricsMetaTableSkipping() throws Exception { |
225 | 228 | master.getTableDescriptors().remove(replicaMetaTable); |
226 | 229 | } |
227 | 230 | } |
| 231 | + |
| 232 | + @Test |
| 233 | + public void testClusterMetricsForeignTableSkipping() throws Exception { |
| 234 | + List<TableName> allTables = new ArrayList<>(); |
| 235 | + |
| 236 | + // These tables, including the cluster's meta table, should not be foreign to the cluster. |
| 237 | + // The cluster should be able to find their state. |
| 238 | + allTables.add(TableName.META_TABLE_NAME); |
| 239 | + List<TableName> familiarTables = new ArrayList<>(); |
| 240 | + familiarTables.add(TableName.valueOf(null, "familiarTable1")); |
| 241 | + familiarTables.add(TableName.valueOf("", "familiarTable2")); |
| 242 | + familiarTables.add(TableName.valueOf("default", "familiarTable3")); |
| 243 | + familiarTables.add(TableName.valueOf("familiarNamespace", "familiarTable4")); |
| 244 | + familiarTables.add(TableName.valueOf("familiarNamespace", "familiarTable5")); |
| 245 | + |
| 246 | + // Create these "familiar" tables so their state can be found |
| 247 | + TEST_UTIL.getAdmin().createNamespace(NamespaceDescriptor.create("familiarNamespace").build()); |
| 248 | + for (TableName familiarTable : familiarTables) { |
| 249 | + TEST_UTIL.createTable(familiarTable, "cf"); |
| 250 | + allTables.add(familiarTable); |
| 251 | + } |
| 252 | + |
| 253 | + // These tables should be foreign to the cluster. |
| 254 | + // The cluster should not be able to find their state. |
| 255 | + allTables.add(TableName.valueOf("hbase", "meta_replica")); |
| 256 | + allTables.add(TableName.valueOf(null, "defaultNamespaceTable1")); |
| 257 | + allTables.add(TableName.valueOf("", "defaultNamespaceTable2")); |
| 258 | + allTables.add(TableName.valueOf("default", "defaultNamespaceTable3")); |
| 259 | + allTables.add(TableName.valueOf("customNamespace", "customNamespaceTable1")); |
| 260 | + allTables.add(TableName.valueOf("customNamespace", "customNamespaceTable2")); |
| 261 | + allTables.add(TableName.valueOf("anotherNamespace", "anotherNamespaceTable")); |
| 262 | + allTables.add(TableName.valueOf("sharedNamespace", "sharedNamespaceTable1")); |
| 263 | + allTables.add(TableName.valueOf("sharedNamespace", "sharedNamespaceTable2")); |
| 264 | + |
| 265 | + // Update master's table descriptors to have all tables |
| 266 | + TableDescriptor foreignTableDescriptor; |
| 267 | + for (TableName tableName : allTables) { |
| 268 | + foreignTableDescriptor = TableDescriptorBuilder.newBuilder(tableName) |
| 269 | + .setColumnFamily(ColumnFamilyDescriptorBuilder.of("cf")).build(); |
| 270 | + master.getTableDescriptors().update(foreignTableDescriptor, true); |
| 271 | + } |
| 272 | + |
| 273 | + // The state of the meta table and the familiar tables we created should exist. |
| 274 | + // The other tables' state should not exist. |
| 275 | + for (TableName tableName : allTables) { |
| 276 | + try { |
| 277 | + ClusterMetrics metrics = master.getClusterMetricsWithoutCoprocessor( |
| 278 | + EnumSet.of(ClusterMetrics.Option.TABLE_TO_REGIONS_COUNT)); |
| 279 | + Map<TableName, RegionStatesCount> tableRegionStatesCount = |
| 280 | + metrics.getTableRegionStatesCount(); |
| 281 | + |
| 282 | + if ( |
| 283 | + tableName.equals(TableName.META_TABLE_NAME) |
| 284 | + || tableName.getQualifierAsString().startsWith("familiar") |
| 285 | + ) { |
| 286 | + assertTrue("Expected this table's state to exist: " + tableName, |
| 287 | + tableRegionStatesCount.containsKey(tableName)); |
| 288 | + } else { |
| 289 | + assertFalse("This foreign table's state should not exist: " + tableName, |
| 290 | + tableRegionStatesCount.containsKey(tableName)); |
| 291 | + } |
| 292 | + } finally { |
| 293 | + master.getTableDescriptors().remove(tableName); |
| 294 | + } |
| 295 | + } |
| 296 | + } |
228 | 297 | } |
0 commit comments