1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.util.hbck;
19
20 import static org.apache.hadoop.hbase.util.hbck.HbckTestingUtil.assertErrors;
21 import static org.apache.hadoop.hbase.util.hbck.HbckTestingUtil.doFsck;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.Arrays;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.hadoop.hbase.HTableDescriptor;
30 import org.apache.hadoop.hbase.testclassification.MediumTests;
31 import org.apache.hadoop.hbase.client.Admin;
32 import org.apache.hadoop.hbase.client.Connection;
33 import org.apache.hadoop.hbase.client.ConnectionFactory;
34 import org.apache.hadoop.hbase.util.HBaseFsck;
35 import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter.ERROR_CODE;
36 import org.junit.Test;
37 import org.junit.experimental.categories.Category;
38
39
40
41
42 @Category(MediumTests.class)
43 public class TestOfflineMetaRebuildBase extends OfflineMetaRebuildTestCore {
44 private static final Log LOG = LogFactory.getLog(TestOfflineMetaRebuildBase.class);
45
46 @Test(timeout = 120000)
47 public void testMetaRebuild() throws Exception {
48 wipeOutMeta();
49
50
51 assertEquals(1, scanMeta());
52 assertErrors(doFsck(conf, false),
53 new ERROR_CODE[] {
54 ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
55 ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
56 ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
57 ERROR_CODE.NOT_IN_META_OR_DEPLOYED});
58
59
60
61
62 TEST_UTIL.shutdownMiniHBaseCluster();
63 TEST_UTIL.shutdownMiniZKCluster();
64
65
66 HBaseFsck fsck = new HBaseFsck(conf);
67 assertTrue(fsck.rebuildMeta(false));
68
69
70 TEST_UTIL.startMiniZKCluster();
71 TEST_UTIL.restartHBaseCluster(3);
72 try (Connection connection = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
73 Admin admin = connection.getAdmin();
74 admin.enableTable(table);
75 LOG.info("Waiting for no more RIT");
76 TEST_UTIL.waitUntilNoRegionsInTransition(60000);
77 LOG.info("No more RIT in ZK, now doing final test verification");
78
79
80 assertEquals(5, scanMeta());
81 HTableDescriptor[] htbls = admin.listTables();
82 LOG.info("Tables present after restart: " + Arrays.toString(htbls));
83 assertEquals(1, htbls.length);
84 }
85
86 assertErrors(doFsck(conf, false), new ERROR_CODE[] {});
87 LOG.info("Table " + table + " has " + tableRowCount(conf, table) + " entries.");
88 assertEquals(16, tableRowCount(conf, table));
89 }
90 }