Skip to content

Commit 902067d

Browse files
authored
HBASE-29292 Revise TestRecreateCluster (#6981)
Signed-off-by: Wellington Chevreuil <[email protected]>
1 parent d9b1aa1 commit 902067d

1 file changed

Lines changed: 25 additions & 42 deletions

File tree

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

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,22 @@
2828
import org.apache.hadoop.hbase.Cell;
2929
import org.apache.hadoop.hbase.HBaseClassTestRule;
3030
import org.apache.hadoop.hbase.HBaseTestingUtil;
31-
import org.apache.hadoop.hbase.HConstants;
3231
import org.apache.hadoop.hbase.ServerName;
3332
import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
33+
import org.apache.hadoop.hbase.StartTestingClusterOption;
3434
import org.apache.hadoop.hbase.TableName;
3535
import org.apache.hadoop.hbase.Waiter;
3636
import org.apache.hadoop.hbase.client.Get;
3737
import org.apache.hadoop.hbase.client.Put;
3838
import org.apache.hadoop.hbase.client.RegionInfo;
3939
import org.apache.hadoop.hbase.client.Result;
4040
import org.apache.hadoop.hbase.client.Table;
41-
import org.apache.hadoop.hbase.master.region.MasterRegionFactory;
42-
import org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore;
4341
import org.apache.hadoop.hbase.regionserver.HRegionServer;
4442
import org.apache.hadoop.hbase.testclassification.LargeTests;
4543
import org.apache.hadoop.hbase.util.Bytes;
4644
import org.apache.hadoop.hbase.util.CommonFSUtils;
4745
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
46+
import org.junit.After;
4847
import org.junit.Before;
4948
import org.junit.ClassRule;
5049
import org.junit.Rule;
@@ -72,9 +71,16 @@ public class TestRecreateCluster {
7271
private static final long MASTER_INIT_TIMEOUT_MS = Duration.ofSeconds(45).toMillis();
7372

7473
@Before
75-
public void setup() {
74+
public void setup() throws Exception {
7675
TEST_UTIL.getConfiguration().setLong("hbase.master.init.timeout.localHBaseCluster",
7776
MASTER_INIT_TIMEOUT_MS);
77+
TEST_UTIL.startMiniCluster(StartTestingClusterOption.builder().numRegionServers(NUM_RS)
78+
.numDataNodes(NUM_RS).createWALDir(true).build());
79+
}
80+
81+
@After
82+
public void tearDown() throws Exception {
83+
TEST_UTIL.shutdownMiniCluster();
7884
}
7985

8086
@Test
@@ -89,44 +95,33 @@ public void testRecreateCluster_UserTableEnabled_ReuseWALsAndZNodes() throws Exc
8995

9096
@Test
9197
public void testRecreateCluster_UserTableEnabled_CleanupZNodes() throws Exception {
92-
// this is no longer failing and is a different behavior compared to branch-2
98+
// this is no longer failing because master region stores the information the region servers
99+
// as long as it's gracefully flushed before shutdown
93100
validateRecreateClusterWithUserTableEnabled(false, true);
94101
}
95102

96-
@Test(expected = IOException.class)
103+
@Test
97104
public void testRecreateCluster_UserTableEnabled_CleanupWALAndZNodes() throws Exception {
98-
// master fails with InitMetaProcedure because it cannot delete existing meta table directory,
99-
// region server cannot join and time-out the cluster starts.
100105
validateRecreateClusterWithUserTableEnabled(true, true);
101106
}
102107

103108
private void validateRecreateClusterWithUserDisabled(boolean cleanupWALs, boolean cleanUpZNodes)
104109
throws Exception {
105-
TEST_UTIL.startMiniCluster(NUM_RS);
106-
try {
107-
TableName tableName = TableName.valueOf("t1");
108-
prepareDataBeforeRecreate(TEST_UTIL, tableName);
109-
TEST_UTIL.getAdmin().disableTable(tableName);
110-
TEST_UTIL.waitTableDisabled(tableName.getName());
111-
restartHBaseCluster(cleanupWALs, cleanUpZNodes);
112-
TEST_UTIL.getAdmin().enableTable(tableName);
113-
validateDataAfterRecreate(TEST_UTIL, tableName);
114-
} finally {
115-
TEST_UTIL.shutdownMiniCluster();
116-
}
110+
TableName tableName = TableName.valueOf("t1");
111+
prepareDataBeforeRecreate(TEST_UTIL, tableName);
112+
TEST_UTIL.getAdmin().disableTable(tableName);
113+
TEST_UTIL.waitTableDisabled(tableName.getName());
114+
restartHBaseCluster(cleanupWALs, cleanUpZNodes);
115+
TEST_UTIL.getAdmin().enableTable(tableName);
116+
validateDataAfterRecreate(TEST_UTIL, tableName);
117117
}
118118

119119
private void validateRecreateClusterWithUserTableEnabled(boolean cleanupWALs,
120120
boolean cleanUpZNodes) throws Exception {
121-
TEST_UTIL.startMiniCluster(NUM_RS);
122-
try {
123-
TableName tableName = TableName.valueOf("t1");
124-
prepareDataBeforeRecreate(TEST_UTIL, tableName);
125-
restartHBaseCluster(cleanupWALs, cleanUpZNodes);
126-
validateDataAfterRecreate(TEST_UTIL, tableName);
127-
} finally {
128-
TEST_UTIL.shutdownMiniCluster();
129-
}
121+
TableName tableName = TableName.valueOf("t1");
122+
prepareDataBeforeRecreate(TEST_UTIL, tableName);
123+
restartHBaseCluster(cleanupWALs, cleanUpZNodes);
124+
validateDataAfterRecreate(TEST_UTIL, tableName);
130125
}
131126

132127
private void restartHBaseCluster(boolean cleanUpWALs, boolean cleanUpZnodes) throws Exception {
@@ -147,17 +142,7 @@ private void restartHBaseCluster(boolean cleanUpWALs, boolean cleanUpZnodes) thr
147142
TEST_UTIL.shutdownMiniHBaseCluster();
148143

149144
if (cleanUpWALs) {
150-
TEST_UTIL.getDFSCluster().getFileSystem()
151-
.delete(new Path(rootDirPath, MasterRegionFactory.MASTER_STORE_DIR), true);
152-
TEST_UTIL.getDFSCluster().getFileSystem()
153-
.delete(new Path(walRootDirPath, MasterRegionFactory.MASTER_STORE_DIR), true);
154-
TEST_UTIL.getDFSCluster().getFileSystem()
155-
.delete(new Path(walRootDirPath, WALProcedureStore.MASTER_PROCEDURE_LOGDIR), true);
156-
157-
TEST_UTIL.getDFSCluster().getFileSystem()
158-
.delete(new Path(walRootDirPath, HConstants.HREGION_LOGDIR_NAME), true);
159-
TEST_UTIL.getDFSCluster().getFileSystem()
160-
.delete(new Path(walRootDirPath, HConstants.HREGION_OLDLOGDIR_NAME), true);
145+
TEST_UTIL.getDFSCluster().getFileSystem().delete(walRootDirPath, true);
161146
}
162147

163148
if (cleanUpZnodes) {
@@ -200,7 +185,6 @@ private void ensureTableNotColocatedWithSystemTable(TableName userTable, TableNa
200185
SingleProcessHBaseCluster hbaseCluster = TEST_UTIL.getHBaseCluster();
201186
assertTrue("Please start more than 1 regionserver",
202187
hbaseCluster.getRegionServerThreads().size() > 1);
203-
204188
int userTableServerNum = getServerNumForTableWithOnlyOneRegion(userTable);
205189
int systemTableServerNum = getServerNumForTableWithOnlyOneRegion(systemTable);
206190

@@ -241,5 +225,4 @@ private void validateDataAfterRecreate(HBaseTestingUtil testUtil, TableName tabl
241225
Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
242226
assertFalse(result.advance());
243227
}
244-
245228
}

0 commit comments

Comments
 (0)