HBASE-23737 [Flakey Tests] TestFavoredNodeTableImport fails 30% of the time

This commit is contained in:
stack 2020-01-24 17:56:42 -08:00
parent 134242720d
commit 9cf57a7db6
1 changed files with 19 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.master.balancer;
import static org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper.FAVORED_NODES_NUM; import static org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper.FAVORED_NODES_NUM;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -34,11 +35,13 @@ import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.favored.FavoredNodesManager; import org.apache.hadoop.hbase.favored.FavoredNodesManager;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.hbase.util.Threads;
import org.junit.After; import org.junit.After;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -66,7 +69,6 @@ public class TestFavoredNodeTableImport {
@After @After
public void stopCluster() throws Exception { public void stopCluster() throws Exception {
UTIL.cleanupTestDir();
UTIL.shutdownMiniCluster(); UTIL.shutdownMiniCluster();
} }
@ -81,13 +83,14 @@ public class TestFavoredNodeTableImport {
Threads.sleep(1); Threads.sleep(1);
} }
Admin admin = UTIL.getAdmin(); Admin admin = UTIL.getAdmin();
admin.setBalancerRunning(false, true); admin.balancerSwitch(false, true);
String tableName = "testFNImport"; String tableName = "testFNImport";
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
admin.createTable(desc, Bytes.toBytes("a"), Bytes.toBytes("z"), REGION_NUM); admin.createTable(desc, Bytes.toBytes("a"), Bytes.toBytes("z"), REGION_NUM);
UTIL.waitTableAvailable(desc.getTableName()); UTIL.waitTableAvailable(desc.getTableName());
admin.balancerSwitch(true, true);
LOG.info("Shutting down cluster"); LOG.info("Shutting down cluster");
UTIL.shutdownMiniHBaseCluster(); UTIL.shutdownMiniHBaseCluster();
@ -97,18 +100,26 @@ public class TestFavoredNodeTableImport {
UTIL.getConfiguration().set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, UTIL.getConfiguration().set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS,
FavoredStochasticBalancer.class.getName()); FavoredStochasticBalancer.class.getName());
UTIL.restartHBaseCluster(SLAVES); UTIL.restartHBaseCluster(SLAVES);
while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) { HMaster master = UTIL.getMiniHBaseCluster().getMaster();
while (!master.isInitialized()) {
Threads.sleep(1); Threads.sleep(1);
} }
admin = UTIL.getAdmin();
UTIL.waitTableAvailable(desc.getTableName()); UTIL.waitTableAvailable(desc.getTableName());
UTIL.waitUntilNoRegionsInTransition(10000);
assertTrue(master.isBalancerOn());
FavoredNodesManager fnm = UTIL.getHBaseCluster().getMaster().getFavoredNodesManager(); FavoredNodesManager fnm = master.getFavoredNodesManager();
assertNotNull(fnm);
admin = UTIL.getAdmin();
List<HRegionInfo> regionsOfTable = admin.getTableRegions(TableName.valueOf(tableName)); List<HRegionInfo> regionsOfTable = admin.getTableRegions(TableName.valueOf(tableName));
for (HRegionInfo rInfo : regionsOfTable) { for (HRegionInfo rInfo : regionsOfTable) {
Set<ServerName> favNodes = Sets.newHashSet(fnm.getFavoredNodes(rInfo)); assertNotNull(rInfo);
assertNotNull(fnm);
List<ServerName> fns = fnm.getFavoredNodes(rInfo);
LOG.info("FNS {} {}", rInfo, fns);
assertNotNull(rInfo.toString(), fns);
Set<ServerName> favNodes = Sets.newHashSet(fns);
assertNotNull(favNodes); assertNotNull(favNodes);
assertEquals("Required no of favored nodes not found.", FAVORED_NODES_NUM, favNodes.size()); assertEquals("Required no of favored nodes not found.", FAVORED_NODES_NUM, favNodes.size());
for (ServerName fn : favNodes) { for (ServerName fn : favNodes) {