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  
19  package org.apache.hadoop.hbase.io;
20  
21  import java.io.IOException;
22  
23  import org.apache.hadoop.classification.InterfaceAudience;
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.fs.Path;
26  import org.apache.hadoop.hbase.HConstants;
27  import org.apache.hadoop.hbase.util.FSUtils;
28  
29  /**
30   * HLogLink describes a link to a WAL.
31   *
32   * An hlog can be in /hbase/.logs/<server>/<hlog>
33   * or it can be in /hbase/.oldlogs/<hlog>
34   *
35   * The link checks first in the original path,
36   * if it is not present it fallbacks to the archived path.
37   */
38  @InterfaceAudience.Private
39  public class HLogLink extends FileLink {
40    /**
41     * @param conf {@link Configuration} from which to extract specific archive locations
42     * @param serverName Region Server owner of the log
43     * @param logName WAL file name
44     * @throws IOException on unexpected error.
45     */
46    public HLogLink(final Configuration conf,
47        final String serverName, final String logName) throws IOException {
48      this(FSUtils.getRootDir(conf), serverName, logName);
49    }
50  
51    /**
52     * @param rootDir Path to the root directory where hbase files are stored
53     * @param serverName Region Server owner of the log
54     * @param logName WAL file name
55     */
56    public HLogLink(final Path rootDir, final String serverName, final String logName) {
57      final Path oldLogDir = new Path(rootDir, HConstants.HREGION_OLDLOGDIR_NAME);
58      final Path logDir = new Path(new Path(rootDir, HConstants.HREGION_LOGDIR_NAME), serverName);
59      setLocations(new Path(logDir, logName), new Path(oldLogDir, logName));
60    }
61  
62    /**
63     * @param originPath Path to the wal in the log directory
64     * @param archivePath Path to the wal in the archived log directory
65     */
66    public HLogLink(final Path originPath, final Path archivePath) {
67      setLocations(originPath, archivePath);
68    }
69  }