View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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.hadoop.hbase.HTableDescriptor;
28  import org.apache.hadoop.hbase.testclassification.MediumTests;
29  import org.apache.hadoop.hbase.client.Admin;
30  import org.apache.hadoop.hbase.client.Connection;
31  import org.apache.hadoop.hbase.client.ConnectionFactory;
32  import org.apache.hadoop.hbase.util.HBaseFsck;
33  import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter.ERROR_CODE;
34  import org.junit.Test;
35  import org.junit.experimental.categories.Category;
36  
37  /**
38   * This builds a table, removes info from meta, and then rebuilds meta.
39   */
40  @Category(MediumTests.class)
41  public class TestOfflineMetaRebuildBase extends OfflineMetaRebuildTestCore {
42  
43    @Test(timeout = 120000)
44    public void testMetaRebuild() throws Exception {
45      wipeOutMeta();
46  
47      // is meta really messed up?
48      assertEquals(1, scanMeta());
49      assertErrors(doFsck(conf, false),
50          new ERROR_CODE[] {
51              ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
52              ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
53              ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
54              ERROR_CODE.NOT_IN_META_OR_DEPLOYED});
55      // Note, would like to check # of tables, but this takes a while to time
56      // out.
57  
58      // shutdown the minicluster
59      TEST_UTIL.shutdownMiniHBaseCluster();
60      TEST_UTIL.shutdownMiniZKCluster();
61  
62      // rebuild meta table from scratch
63      HBaseFsck fsck = new HBaseFsck(conf);
64      assertTrue(fsck.rebuildMeta(false));
65  
66      // bring up the minicluster
67      TEST_UTIL.startMiniZKCluster();
68      TEST_UTIL.restartHBaseCluster(3);
69      try (Connection connection = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
70        Admin admin = connection.getAdmin();
71        admin.enableTable(table);
72        LOG.info("Waiting for no more RIT");
73        TEST_UTIL.waitUntilNoRegionsInTransition(60000);
74        LOG.info("No more RIT in ZK, now doing final test verification");
75  
76        // everything is good again.
77        assertEquals(5, scanMeta());
78        HTableDescriptor[] htbls = admin.listTables();
79        LOG.info("Tables present after restart: " + Arrays.toString(htbls));
80        assertEquals(1, htbls.length);
81      }
82  
83      assertErrors(doFsck(conf, false), new ERROR_CODE[] {});
84      LOG.info("Table " + table + " has " + tableRowCount(conf, table) + " entries.");
85      assertEquals(16, tableRowCount(conf, table));
86    }
87  }