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