1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.regionserver.wal;
21
22 import java.io.IOException;
23 import java.util.List;
24 import java.util.UUID;
25 import java.util.concurrent.atomic.AtomicLong;
26
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.fs.FileSystem;
29 import org.apache.hadoop.fs.Path;
30 import org.apache.hadoop.hbase.HRegionInfo;
31 import org.apache.hadoop.hbase.HTableDescriptor;
32 import org.apache.hadoop.hbase.TableName;
33
34
35
36
37 public class FaultyHLog extends FSHLog {
38 public enum FailureType {
39 NONE, APPENDNOSYNC, SYNC
40 }
41 FailureType ft = FailureType.NONE;
42
43 public FaultyHLog(FileSystem fs, Path rootDir, String logName, Configuration conf)
44 throws IOException {
45 super(fs, rootDir, logName, conf);
46 }
47
48 public void setFailureType(FailureType fType) {
49 this.ft = fType;
50 }
51
52 @Override
53 public void sync(long txid) throws IOException {
54 if (this.ft == FailureType.SYNC) {
55 throw new IOException("sync");
56 }
57 super.sync(txid);
58 }
59 @Override
60 public long appendNoSync(HRegionInfo info, TableName tableName, WALEdit edits,
61 List<UUID> clusterIds, final long now, HTableDescriptor htd, AtomicLong sequenceId,
62 boolean isInMemstore, long nonceGroup, long nonce) throws IOException {
63 if (this.ft == FailureType.APPENDNOSYNC) {
64 throw new IOException("appendNoSync");
65 }
66 return super.appendNoSync(info, tableName, edits, clusterIds, now, htd, sequenceId,
67 isInMemstore, nonceGroup, nonce);
68 }
69 }
70