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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org
.apache
.hadoop
.hbase
;
20 import static org
.junit
.Assert
.assertEquals
;
22 import org
.apache
.hadoop
.conf
.Configuration
;
23 import org
.apache
.hadoop
.hbase
.Waiter
.ExplainingPredicate
;
24 import org
.apache
.hadoop
.hbase
.client
.Table
;
25 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
26 import org
.apache
.hadoop
.hbase
.testclassification
.MiscTests
;
27 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
28 import org
.apache
.hadoop
.hbase
.util
.JVMClusterUtil
.RegionServerThread
;
29 import org
.junit
.AfterClass
;
30 import org
.junit
.BeforeClass
;
31 import org
.junit
.ClassRule
;
32 import org
.junit
.Test
;
33 import org
.junit
.experimental
.categories
.Category
;
34 import org
.slf4j
.Logger
;
35 import org
.slf4j
.LoggerFactory
;
37 @Category({ MiscTests
.class, MediumTests
.class })
38 public class TestFullLogReconstruction
{
39 private static final Logger LOG
= LoggerFactory
.getLogger(TestFullLogReconstruction
.class);
42 public static final HBaseClassTestRule CLASS_RULE
=
43 HBaseClassTestRule
.forClass(TestFullLogReconstruction
.class);
45 private final static HBaseTestingUtility TEST_UTIL
= new HBaseTestingUtility();
47 private final static TableName TABLE_NAME
= TableName
.valueOf("tabletest");
48 private final static byte[] FAMILY
= Bytes
.toBytes("family");
51 public static void setUpBeforeClass() throws Exception
{
52 Configuration c
= TEST_UTIL
.getConfiguration();
53 // quicker heartbeat interval for faster DN death notification
54 c
.setInt("dfs.namenode.heartbeat.recheck-interval", 5000);
55 c
.setInt("dfs.heartbeat.interval", 1);
56 c
.setInt("dfs.client.socket-timeout", 5000);
57 // faster failover with cluster.shutdown();fs.close() idiom
58 c
.setInt("hbase.ipc.client.connect.max.retries", 1);
59 c
.setInt("dfs.client.block.recovery.retries", 1);
60 c
.setInt(HConstants
.ZK_SESSION_TIMEOUT
, 1000);
61 TEST_UTIL
.startMiniCluster(3);
65 public static void tearDownAfterClass() throws Exception
{
66 TEST_UTIL
.shutdownMiniCluster();
70 * Test the whole reconstruction loop. Build a table with regions aaa to zzz and load every one of
71 * them multiple times with the same date and do a flush at some point. Kill one of the region
72 * servers and scan the table. We should see all the rows.
75 public void testReconstruction() throws Exception
{
76 Table table
= TEST_UTIL
.createMultiRegionTable(TABLE_NAME
, FAMILY
);
78 // Load up the table with simple rows and count them
79 int initialCount
= TEST_UTIL
.loadTable(table
, FAMILY
);
80 int count
= TEST_UTIL
.countRows(table
);
82 assertEquals(initialCount
, count
);
84 for (int i
= 0; i
< 4; i
++) {
85 TEST_UTIL
.loadTable(table
, FAMILY
);
87 RegionServerThread rsThread
= TEST_UTIL
.getHBaseCluster().getRegionServerThreads().get(0);
89 LOG
.info("Expiring {}", TEST_UTIL
.getMiniHBaseCluster().getRegionServer(index
));
90 TEST_UTIL
.expireRegionServerSession(index
);
91 // make sure that the RS is fully down before reading, so that we will read the data from other
93 TEST_UTIL
.waitFor(30000, new ExplainingPredicate
<Exception
>() {
96 public boolean evaluate() throws Exception
{
97 return !rsThread
.isAlive();
101 public String
explainFailure() throws Exception
{
102 return rsThread
.getRegionServer() + " is still alive";
105 LOG
.info("Starting count");
107 int newCount
= TEST_UTIL
.countRows(table
);
108 assertEquals(count
, newCount
);