001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021 022import org.apache.hadoop.conf.Configuration; 023import org.apache.hadoop.hbase.Waiter.ExplainingPredicate; 024import org.apache.hadoop.hbase.client.Table; 025import org.apache.hadoop.hbase.testclassification.MediumTests; 026import org.apache.hadoop.hbase.testclassification.MiscTests; 027import org.apache.hadoop.hbase.util.Bytes; 028import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; 029import org.junit.jupiter.api.AfterAll; 030import org.junit.jupiter.api.BeforeAll; 031import org.junit.jupiter.api.Tag; 032import org.junit.jupiter.api.Test; 033import org.slf4j.Logger; 034import org.slf4j.LoggerFactory; 035 036@Tag(MiscTests.TAG) 037@Tag(MediumTests.TAG) 038public class TestFullLogReconstruction { 039 private static final Logger LOG = LoggerFactory.getLogger(TestFullLogReconstruction.class); 040 041 private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 042 043 private final static TableName TABLE_NAME = TableName.valueOf("tabletest"); 044 private final static byte[] FAMILY = Bytes.toBytes("family"); 045 046 @BeforeAll 047 public static void setUpBeforeClass() throws Exception { 048 Configuration c = TEST_UTIL.getConfiguration(); 049 // quicker heartbeat interval for faster DN death notification 050 c.setInt("dfs.namenode.heartbeat.recheck-interval", 5000); 051 c.setInt("dfs.heartbeat.interval", 1); 052 c.setInt("dfs.client.socket-timeout", 5000); 053 // faster failover with cluster.shutdown();fs.close() idiom 054 c.setInt("hbase.ipc.client.connect.max.retries", 1); 055 c.setInt("dfs.client.block.recovery.retries", 1); 056 c.setInt(HConstants.ZK_SESSION_TIMEOUT, 1000); 057 TEST_UTIL.startMiniCluster(3); 058 } 059 060 @AfterAll 061 public static void tearDownAfterClass() throws Exception { 062 TEST_UTIL.shutdownMiniCluster(); 063 } 064 065 /** 066 * Test the whole reconstruction loop. Build a table with regions aaa to zzz and load every one of 067 * them multiple times with the same date and do a flush at some point. Kill one of the region 068 * servers and scan the table. We should see all the rows. 069 */ 070 @Test 071 public void testReconstruction() throws Exception { 072 Table table = TEST_UTIL.createMultiRegionTable(TABLE_NAME, FAMILY); 073 074 // Load up the table with simple rows and count them 075 int initialCount = TEST_UTIL.loadTable(table, FAMILY); 076 int count = HBaseTestingUtil.countRows(table); 077 078 assertEquals(initialCount, count); 079 080 for (int i = 0; i < 4; i++) { 081 TEST_UTIL.loadTable(table, FAMILY); 082 } 083 RegionServerThread rsThread = TEST_UTIL.getHBaseCluster().getRegionServerThreads().get(0); 084 int index = 0; 085 LOG.info("Expiring {}", TEST_UTIL.getMiniHBaseCluster().getRegionServer(index)); 086 TEST_UTIL.expireRegionServerSession(index); 087 // make sure that the RS is fully down before reading, so that we will read the data from other 088 // RSes. 089 TEST_UTIL.waitFor(30000, new ExplainingPredicate<Exception>() { 090 091 @Override 092 public boolean evaluate() throws Exception { 093 return !rsThread.isAlive(); 094 } 095 096 @Override 097 public String explainFailure() throws Exception { 098 return rsThread.getRegionServer() + " is still alive"; 099 } 100 }); 101 LOG.info("Starting count"); 102 103 int newCount = HBaseTestingUtil.countRows(table); 104 assertEquals(count, newCount); 105 table.close(); 106 } 107}