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.regionserver.wal; 019 020import static org.junit.Assert.assertEquals; 021 022import java.io.IOException; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.HBaseClassTestRule; 025import org.apache.hadoop.hbase.client.RegionInfo; 026import org.apache.hadoop.hbase.client.Table; 027import org.apache.hadoop.hbase.io.asyncfs.FanOutOneBlockAsyncDFSOutputHelper; 028import org.apache.hadoop.hbase.testclassification.LargeTests; 029import org.apache.hadoop.hbase.testclassification.VerySlowRegionServerTests; 030import org.apache.hadoop.hbase.wal.AsyncFSWALProvider; 031import org.apache.hadoop.hbase.wal.WALFactory; 032import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties; 033import org.apache.hadoop.hdfs.protocol.DatanodeInfo; 034import org.junit.BeforeClass; 035import org.junit.ClassRule; 036import org.junit.Test; 037import org.junit.experimental.categories.Category; 038 039@Category({ VerySlowRegionServerTests.class, LargeTests.class }) 040public class TestAsyncLogRolling extends AbstractTestLogRolling { 041 042 @ClassRule 043 public static final HBaseClassTestRule CLASS_RULE = 044 HBaseClassTestRule.forClass(TestAsyncLogRolling.class); 045 046 @BeforeClass 047 public static void setUpBeforeClass() throws Exception { 048 Configuration conf = TestAsyncLogRolling.TEST_UTIL.getConfiguration(); 049 conf.setInt(FanOutOneBlockAsyncDFSOutputHelper.ASYNC_DFS_OUTPUT_CREATE_MAX_RETRIES, 100); 050 conf.set(WALFactory.WAL_PROVIDER, "asyncfs"); 051 conf.set(WALFactory.META_WAL_PROVIDER, "asyncfs"); 052 AbstractTestLogRolling.setUpBeforeClass(); 053 } 054 055 @Test 056 public void testLogRollOnDatanodeDeath() throws IOException, InterruptedException { 057 dfsCluster.startDataNodes(TEST_UTIL.getConfiguration(), 3, true, null, null); 058 tableName = getName(); 059 Table table = createTestTable(tableName); 060 TEST_UTIL.waitUntilAllRegionsAssigned(table.getName()); 061 doPut(table, 1); 062 server = TEST_UTIL.getRSForFirstRegionInTable(table.getName()); 063 RegionInfo hri = server.getRegions(table.getName()).get(0).getRegionInfo(); 064 AsyncFSWAL wal = (AsyncFSWAL) server.getWAL(hri); 065 int numRolledLogFiles = AsyncFSWALProvider.getNumRolledLogFiles(wal); 066 DatanodeInfo[] dnInfos = wal.getPipeline(); 067 DataNodeProperties dnProp = TEST_UTIL.getDFSCluster().stopDataNode(dnInfos[0].getName()); 068 TEST_UTIL.getDFSCluster().restartDataNode(dnProp); 069 doPut(table, 2); 070 assertEquals(numRolledLogFiles + 1, AsyncFSWALProvider.getNumRolledLogFiles(wal)); 071 } 072}