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