View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.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.hbase.classification.InterfaceAudience;
28  import org.apache.hadoop.conf.Configuration;
29  import org.apache.hadoop.fs.FileSystem;
30  import org.apache.hadoop.fs.Path;
31  import org.apache.hadoop.hbase.Cell;
32  import org.apache.hadoop.hbase.HRegionInfo;
33  import org.apache.hadoop.hbase.HTableDescriptor;
34  import org.apache.hadoop.hbase.TableName;
35  
36  // imports for things that haven't moved yet
37  import org.apache.hadoop.hbase.regionserver.wal.FSHLog;
38  import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
39  
40  /**
41   * This is a utility class, used by tests, which fails operation specified by FailureType enum
42   */
43  @InterfaceAudience.Private
44  public class FaultyFSLog extends FSHLog {
45    public enum FailureType {
46      NONE, APPEND, SYNC
47    }
48    FailureType ft = FailureType.NONE;
49  
50    public FaultyFSLog(FileSystem fs, Path rootDir, String logName, Configuration conf)
51        throws IOException {
52      super(fs, rootDir, logName, conf);
53    }
54    
55    public void setFailureType(FailureType fType) {
56      this.ft = fType;
57    }
58    
59    @Override
60    public void sync(long txid) throws IOException {
61      if (this.ft == FailureType.SYNC) {
62        throw new IOException("sync");
63      }
64      super.sync(txid);
65    }
66  
67    @Override
68    public long append(HTableDescriptor htd, HRegionInfo info, WALKey key, WALEdit edits,
69        boolean inMemstore) throws IOException {
70      if (this.ft == FailureType.APPEND) {
71        throw new IOException("append");
72      }
73      return super.append(htd, info, key, edits, inMemstore);
74    }
75  }
76