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 java.io.IOException; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.fs.FileSystem; 023import org.apache.hadoop.fs.Path; 024import org.apache.hadoop.hbase.testclassification.MediumTests; 025import org.apache.hadoop.hbase.testclassification.RegionServerTests; 026import org.apache.hadoop.hbase.wal.WALProvider.Writer; 027import org.junit.jupiter.api.Tag; 028 029@Tag(RegionServerTests.TAG) 030@Tag(MediumTests.TAG) 031public class TestFSHLogDurability extends WALDurabilityTestBase<CustomFSHLog> { 032 033 @Override 034 protected CustomFSHLog getWAL0(FileSystem fs, Path root, String logDir, Configuration conf) 035 throws IOException { 036 CustomFSHLog wal = new CustomFSHLog(fs, root, logDir, conf); 037 wal.init(); 038 return wal; 039 } 040 041 @Override 042 protected void resetSyncFlag(CustomFSHLog wal) { 043 wal.resetSyncFlag(); 044 } 045 046 @Override 047 protected Boolean getSyncFlag(CustomFSHLog wal) { 048 return wal.getSyncFlag(); 049 } 050 051 @Override 052 protected Boolean getWriterSyncFlag(CustomFSHLog wal) { 053 return wal.getWriterSyncFlag(); 054 } 055} 056 057class CustomFSHLog extends FSHLog { 058 private Boolean syncFlag; 059 060 private Boolean writerSyncFlag; 061 062 public CustomFSHLog(FileSystem fs, Path root, String logDir, Configuration conf) 063 throws IOException { 064 super(fs, root, logDir, conf); 065 } 066 067 @Override 068 protected Writer createWriterInstance(FileSystem fs, Path path) throws IOException { 069 Writer writer = super.createWriterInstance(fs, path); 070 return new Writer() { 071 072 @Override 073 public void close() throws IOException { 074 writer.close(); 075 } 076 077 @Override 078 public long getLength() { 079 return writer.getLength(); 080 } 081 082 @Override 083 public long getSyncedLength() { 084 return writer.getSyncedLength(); 085 } 086 087 @Override 088 public void sync(boolean forceSync) throws IOException { 089 writerSyncFlag = forceSync; 090 writer.sync(forceSync); 091 } 092 093 @Override 094 public void append(Entry entry) throws IOException { 095 writer.append(entry); 096 } 097 }; 098 } 099 100 @Override 101 protected void doSync(boolean forceSync) throws IOException { 102 syncFlag = forceSync; 103 super.doSync(forceSync); 104 } 105 106 @Override 107 protected void doSync(long txid, boolean forceSync) throws IOException { 108 syncFlag = forceSync; 109 super.doSync(txid, forceSync); 110 } 111 112 void resetSyncFlag() { 113 this.syncFlag = null; 114 this.writerSyncFlag = null; 115 } 116 117 Boolean getSyncFlag() { 118 return syncFlag; 119 } 120 121 Boolean getWriterSyncFlag() { 122 return writerSyncFlag; 123 } 124}