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.wal; 019 020import java.io.IOException; 021import java.util.List; 022import org.apache.hadoop.conf.Configuration; 023import org.apache.hadoop.fs.FileSystem; 024import org.apache.hadoop.fs.Path; 025import org.apache.hadoop.hbase.HBaseClassTestRule; 026import org.apache.hadoop.hbase.regionserver.wal.FSHLog; 027import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener; 028import org.apache.hadoop.hbase.testclassification.MediumTests; 029import org.apache.hadoop.hbase.testclassification.RegionServerTests; 030import org.apache.hadoop.hbase.util.CommonFSUtils; 031import org.junit.AfterClass; 032import org.junit.BeforeClass; 033import org.junit.ClassRule; 034import org.junit.experimental.categories.Category; 035 036/** 037 * Testcase for HBASE-22539 038 */ 039@Category({ RegionServerTests.class, MediumTests.class }) 040public class TestFSHLogCorruptionDueToDanglingByteBuffer 041 extends WALCorruptionDueToDanglingByteBufferTestBase { 042 043 @ClassRule 044 public static final HBaseClassTestRule CLASS_RULE = 045 HBaseClassTestRule.forClass(TestFSHLogCorruptionDueToDanglingByteBuffer.class); 046 047 public static final class PauseWAL extends FSHLog { 048 049 public PauseWAL(FileSystem fs, Path rootDir, String logDir, String archiveDir, 050 Configuration conf, List<WALActionsListener> listeners, boolean failIfWALExists, 051 String prefix, String suffix) throws IOException { 052 super(fs, rootDir, logDir, archiveDir, conf, listeners, failIfWALExists, prefix, suffix); 053 } 054 055 @Override 056 protected void atHeadOfRingBufferEventHandlerAppend() { 057 if (ARRIVE != null) { 058 ARRIVE.countDown(); 059 try { 060 RESUME.await(); 061 } catch (InterruptedException e) { 062 } 063 } 064 } 065 } 066 067 public static final class PauseWALProvider extends AbstractFSWALProvider<PauseWAL> { 068 069 @Override 070 protected PauseWAL createWAL() throws IOException { 071 return new PauseWAL(CommonFSUtils.getWALFileSystem(conf), CommonFSUtils.getWALRootDir(conf), 072 getWALDirectoryName(factory.factoryId), getWALArchiveDirectoryName(conf, factory.factoryId), 073 conf, listeners, true, logPrefix, 074 META_WAL_PROVIDER_ID.equals(providerId) ? META_WAL_PROVIDER_ID : null); 075 } 076 077 @Override 078 protected void doInit(Configuration conf) throws IOException { 079 } 080 } 081 082 @BeforeClass 083 public static void setUp() throws Exception { 084 UTIL.getConfiguration().setClass(WALFactory.WAL_PROVIDER, PauseWALProvider.class, 085 WALProvider.class); 086 UTIL.startMiniCluster(1); 087 UTIL.createTable(TABLE_NAME, CF); 088 UTIL.waitTableAvailable(TABLE_NAME); 089 } 090 091 @AfterClass 092 public static void tearDown() throws Exception { 093 UTIL.shutdownMiniCluster(); 094 } 095}