View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.regionserver.wal;
19  
20  import java.io.IOException;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.fs.FileSystem;
26  import org.apache.hadoop.fs.Path;
27  import org.apache.hadoop.hbase.HBaseFileSystem;
28  import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
29  import org.apache.hadoop.hbase.regionserver.wal.HLog.Writer;
30  
31  /**
32   * Acts as an abstraction between the HLog and the underlying filesystem. This is analogous to the
33   * {@link HRegionFileSystem} class.
34   */
35  public class HLogFileSystem extends HBaseFileSystem {
36    public static final Log LOG = LogFactory.getLog(HLogFileSystem.class);
37  
38    /**
39     * In order to handle NN connectivity hiccups, one need to retry non-idempotent operation at the
40     * client level.
41     */
42  
43    public HLogFileSystem(Configuration conf) {
44      setRetryCounts(conf);
45    }
46  
47    /**
48     * Creates writer for the given path.
49     * @param fs
50     * @param conf
51     * @param hlogFile
52     * @return an init'ed writer for the given path.
53     * @throws IOException
54     */
55    public Writer createWriter(FileSystem fs, Configuration conf, Path hlogFile) throws IOException {
56      int i = 0;
57      IOException lastIOE = null;
58      do {
59        try {
60          return HLog.createWriter(fs, hlogFile, conf);
61        } catch (IOException ioe) {
62          lastIOE = ioe;
63          sleepBeforeRetry("Create Writer", i+1);
64        }
65      } while (++i <= hdfsClientRetriesNumber);
66      throw new IOException("Exception in createWriter", lastIOE);
67  
68    }
69  }