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