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.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   * This is a utility class, used by tests, which fails operation specified by FailureType enum
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