Skip to content

Commit 7c24ed4

Browse files
authored
HBASE-25897 TestRetainAssignmentOnRestart is flaky after HBASE-25032 (#3281)
Signed-off-by: Xiaolin Ha <haxiaolin@apache.org>
1 parent fe47557 commit 7c24ed4

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,8 @@ public void abortProcess() {
14981498
}
14991499
}
15001500

1501-
private void startProcedureExecutor() throws IOException {
1501+
// will be override in UT
1502+
protected void startProcedureExecutor() throws IOException {
15021503
procedureExecutor.startWorkers();
15031504
}
15041505

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRetainAssignmentOnRestart.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import static org.junit.Assert.assertTrue;
2323

2424
import java.io.IOException;
25+
import java.io.UncheckedIOException;
2526
import java.util.List;
2627
import java.util.Map;
27-
28+
import org.apache.hadoop.conf.Configuration;
2829
import org.apache.hadoop.hbase.HBaseClassTestRule;
2930
import org.apache.hadoop.hbase.HConstants;
3031
import org.apache.hadoop.hbase.MiniHBaseCluster;
3132
import org.apache.hadoop.hbase.ServerName;
33+
import org.apache.hadoop.hbase.StartMiniClusterOption;
3234
import org.apache.hadoop.hbase.TableName;
3335
import org.apache.hadoop.hbase.client.RegionInfo;
3436
import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure;
@@ -52,6 +54,33 @@ public class TestRetainAssignmentOnRestart extends AbstractTestRestartCluster {
5254

5355
private static int NUM_OF_RS = 3;
5456

57+
public static final class HMasterForTest extends HMaster {
58+
59+
public HMasterForTest(Configuration conf) throws IOException {
60+
super(conf);
61+
}
62+
63+
@Override
64+
protected void startProcedureExecutor() throws IOException {
65+
// only start procedure executor when we have all the regionservers ready to take regions
66+
new Thread(() -> {
67+
for (;;) {
68+
if (getServerManager().createDestinationServersList().size() == NUM_OF_RS) {
69+
try {
70+
HMasterForTest.super.startProcedureExecutor();
71+
} catch (IOException e) {
72+
throw new UncheckedIOException(e);
73+
}
74+
}
75+
try {
76+
Thread.sleep(1000);
77+
} catch (InterruptedException e) {
78+
}
79+
}
80+
}).start();
81+
}
82+
}
83+
5584
@Override
5685
protected boolean splitWALCoordinatedByZk() {
5786
return true;
@@ -205,7 +234,8 @@ private void setupCluster() throws Exception, IOException, InterruptedException
205234
HConstants.ZK_CONNECTION_REGISTRY_CLASS);
206235
// Enable retain assignment during ServerCrashProcedure
207236
UTIL.getConfiguration().setBoolean(ServerCrashProcedure.MASTER_SCP_RETAIN_ASSIGNMENT, true);
208-
UTIL.startMiniCluster(NUM_OF_RS);
237+
UTIL.startMiniCluster(StartMiniClusterOption.builder().masterClass(HMasterForTest.class)
238+
.numRegionServers(NUM_OF_RS).build());
209239

210240
// Turn off balancer
211241
UTIL.getMiniHBaseCluster().getMaster().getMasterRpcServices().synchronousBalanceSwitch(false);

0 commit comments

Comments
 (0)