1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.regionserver;
19
20 import java.util.List;
21 import org.apache.hadoop.fs.FileStatus;
22 import org.apache.hadoop.fs.Path;
23 import org.apache.hadoop.hbase.HBaseTestingUtility;
24 import org.apache.hadoop.hbase.HConstants;
25 import org.apache.hadoop.hbase.HRegionInfo;
26 import org.apache.hadoop.hbase.ProcedureInfo;
27 import org.apache.hadoop.hbase.TableName;
28 import org.apache.hadoop.hbase.master.MasterFileSystem;
29 import org.apache.hadoop.hbase.protobuf.generated.ProcedureProtos;
30 import org.apache.hadoop.hbase.testclassification.MediumTests;
31 import org.apache.hadoop.hbase.util.FSUtils;
32 import org.apache.hadoop.hbase.wal.DefaultWALProvider;
33 import org.junit.AfterClass;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.junit.experimental.categories.Category;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 import static org.junit.Assert.fail;
41
42 @Category(MediumTests.class)
43 public class TestCleanupMetaWAL {
44 private static final Logger LOG = LoggerFactory.getLogger(TestCleanupMetaWAL.class);
45
46 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
47
48 @BeforeClass
49 public static void before() throws Exception {
50 TEST_UTIL.startMiniCluster(2);
51 }
52
53 @AfterClass
54 public static void after() throws Exception {
55 TEST_UTIL.shutdownMiniZKCluster();
56 }
57
58 @Test
59 public void testCleanupMetaWAL() throws Exception {
60 TEST_UTIL.createTable(TableName.valueOf("test"), "cf");
61 HRegionServer serverWithMeta = TEST_UTIL.getMiniHBaseCluster()
62 .getRegionServer(TEST_UTIL.getMiniHBaseCluster().getServerWithMeta());
63 TEST_UTIL.getHBaseAdmin()
64 .move(HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), null);
65 TEST_UTIL.getMiniHBaseCluster().killRegionServer(serverWithMeta.getServerName());
66 int count = 0;
67 boolean scpFinished = false;
68 while(count < 25 && !scpFinished) {
69 List<ProcedureInfo> procs = TEST_UTIL.getMiniHBaseCluster().getMaster().listProcedures();
70 for(ProcedureInfo pi : procs) {
71 if(pi.getProcName().startsWith("ServerCrashProcedure") && pi.getProcState() ==
72 ProcedureProtos.ProcedureState.FINISHED){
73 LOG.info("SCP is finished: " + pi.getProcName());
74 scpFinished = true;
75 break;
76 }
77 }
78 Thread.sleep(1000);
79 count++;
80 }
81
82 MasterFileSystem fs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
83 Path walPath = new Path(fs.getWALRootDir(), HConstants.HREGION_LOGDIR_NAME);
84 for (FileStatus status : FSUtils.listStatus(fs.getFileSystem(), walPath)) {
85 if (status.getPath().toString().contains(DefaultWALProvider.SPLITTING_EXT)) {
86 fail("Should not have splitting wal dir here:" + status);
87 }
88 }
89 }
90 }