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