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.assertFalse;
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.HBaseTestingUtility;
30  import org.apache.hadoop.hbase.HTableDescriptor;
31  import org.apache.hadoop.hbase.testclassification.MediumTests;
32  import org.apache.hadoop.hbase.util.HBaseFsck;
33  import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter.ERROR_CODE;
34  import org.apache.hadoop.hbase.zookeeper.ZKAssign;
35  import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
36  import org.junit.Test;
37  import org.junit.experimental.categories.Category;
38  
39  /**
40   * This builds a table, removes info from meta, and then fails when attempting
41   * to rebuild meta.
42   */
43  @Category(MediumTests.class)
44  public class TestOfflineMetaRebuildHole extends OfflineMetaRebuildTestCore {
45    private final static Log LOG = LogFactory.getLog(TestOfflineMetaRebuildHole.class);
46  
47    @Test(timeout = 120000)
48    public void testMetaRebuildHoleFail() throws Exception {
49      // Fully remove a meta entry and hdfs region
50      byte[] startKey = splits[1];
51      byte[] endKey = splits[2];
52      deleteRegion(conf, htbl, startKey, endKey);
53  
54      wipeOutMeta();
55  
56      // is meta really messed up?
57      assertEquals(1, scanMeta());
58      assertErrors(doFsck(conf, false), new ERROR_CODE[] {
59          ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
60          ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
61          ERROR_CODE.NOT_IN_META_OR_DEPLOYED});
62      // Note, would like to check # of tables, but this takes a while to time
63      // out.
64  
65      // shutdown the minicluster
66      TEST_UTIL.shutdownMiniHBaseCluster();
67      TEST_UTIL.shutdownMiniZKCluster();
68  
69      // attempt to rebuild meta table from scratch
70      HBaseFsck fsck = new HBaseFsck(conf);
71      assertFalse(fsck.rebuildMeta(false));
72      fsck.close();
73  
74      // bring up the minicluster
75      TEST_UTIL.startMiniZKCluster(); // tables seem enabled by default
76      TEST_UTIL.restartHBaseCluster(3);
77  
78      ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(TEST_UTIL);
79  
80      LOG.info("Waiting for no more RIT");
81      ZKAssign.blockUntilNoRIT(zkw);
82      LOG.info("No more RIT in ZK, now doing final test verification");
83      int tries = 60;
84      while(TEST_UTIL.getHBaseCluster()
85          .getMaster().getAssignmentManager().getRegionStates().getRegionsInTransition().size() > 0 &&
86          tries-- > 0) {
87        LOG.info("Waiting for RIT: "+TEST_UTIL.getHBaseCluster()
88                .getMaster().getAssignmentManager().getRegionStates().getRegionsInTransition());
89        Thread.sleep(1000);
90      }
91  
92      // Meta still messed up.
93      assertEquals(1, scanMeta());
94      HTableDescriptor[] htbls = getTables(TEST_UTIL.getConfiguration());
95      LOG.info("Tables present after restart: " + Arrays.toString(htbls));
96  
97      // After HBASE-451 HBaseAdmin.listTables() gets table descriptors from FS,
98      // so the table is still present and this should be 1.
99      assertEquals(1, htbls.length);
100     assertErrors(doFsck(conf, false), new ERROR_CODE[] {
101         ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
102         ERROR_CODE.NOT_IN_META_OR_DEPLOYED,
103         ERROR_CODE.NOT_IN_META_OR_DEPLOYED});
104   }
105 }