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; 019 020import static org.apache.hadoop.hbase.wal.AbstractFSWALProvider.SPLITTING_EXT; 021import static org.junit.Assert.fail; 022 023import org.apache.hadoop.fs.FileStatus; 024import org.apache.hadoop.fs.Path; 025import org.apache.hadoop.hbase.HBaseClassTestRule; 026import org.apache.hadoop.hbase.HBaseTestingUtil; 027import org.apache.hadoop.hbase.HConstants; 028import org.apache.hadoop.hbase.TableName; 029import org.apache.hadoop.hbase.client.RegionInfoBuilder; 030import org.apache.hadoop.hbase.master.MasterFileSystem; 031import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure; 032import org.apache.hadoop.hbase.testclassification.MediumTests; 033import org.apache.hadoop.hbase.util.CommonFSUtils; 034import org.junit.AfterClass; 035import org.junit.BeforeClass; 036import org.junit.ClassRule; 037import org.junit.Test; 038import org.junit.experimental.categories.Category; 039import org.slf4j.Logger; 040import org.slf4j.LoggerFactory; 041 042@Category(MediumTests.class) 043public class TestCleanupMetaWAL { 044 private static final Logger LOG = LoggerFactory.getLogger(TestCleanupMetaWAL.class); 045 046 private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 047 048 @ClassRule 049 public static final HBaseClassTestRule CLASS_RULE = 050 HBaseClassTestRule.forClass(TestCleanupMetaWAL.class); 051 052 @BeforeClass 053 public static void before() throws Exception { 054 TEST_UTIL.startMiniCluster(2); 055 } 056 057 @AfterClass 058 public static void after() throws Exception { 059 TEST_UTIL.shutdownMiniZKCluster(); 060 } 061 062 @Test 063 public void testCleanupMetaWAL() throws Exception { 064 TEST_UTIL.createTable(TableName.valueOf("test"), "cf"); 065 HRegionServer serverWithMeta = TEST_UTIL.getMiniHBaseCluster() 066 .getRegionServer(TEST_UTIL.getMiniHBaseCluster().getServerWithMeta()); 067 TEST_UTIL.getAdmin().move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes()); 068 LOG.info("KILL"); 069 TEST_UTIL.getMiniHBaseCluster().killRegionServer(serverWithMeta.getServerName()); 070 LOG.info("WAIT"); 071 TEST_UTIL.waitFor(30000, () -> TEST_UTIL.getMiniHBaseCluster().getMaster().getProcedures() 072 .stream().filter(p -> p instanceof ServerCrashProcedure && p.isFinished()).count() > 0); 073 LOG.info("DONE WAITING"); 074 MasterFileSystem fs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem(); 075 Path walPath = new Path(fs.getWALRootDir(), HConstants.HREGION_LOGDIR_NAME); 076 for (FileStatus status : CommonFSUtils.listStatus(fs.getFileSystem(), walPath)) { 077 if (status.getPath().toString().contains(SPLITTING_EXT)) { 078 fail("Splitting WAL dir should have been cleaned up: " + status); 079 } 080 } 081 } 082}