001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.hbase.io;
020
021import java.io.IOException;
022
023import org.apache.yetus.audience.InterfaceAudience;
024import org.apache.hadoop.conf.Configuration;
025import org.apache.hadoop.fs.Path;
026import org.apache.hadoop.hbase.HConstants;
027import org.apache.hadoop.hbase.util.CommonFSUtils;
028
029/**
030 * WALLink describes a link to a WAL.
031 *
032 * An wal can be in /hbase/.logs/<server>/<wal>
033 * or it can be in /hbase/.oldlogs/<wal>
034 *
035 * The link checks first in the original path,
036 * if it is not present it fallbacks to the archived path.
037 */
038@InterfaceAudience.Private
039public class WALLink extends FileLink {
040  /**
041   * @param conf {@link Configuration} from which to extract specific archive locations
042   * @param serverName Region Server owner of the log
043   * @param logName WAL file name
044   * @throws IOException on unexpected error.
045   */
046  public WALLink(final Configuration conf,
047      final String serverName, final String logName) throws IOException {
048    this(CommonFSUtils.getWALRootDir(conf), serverName, logName);
049  }
050
051  /**
052   * @param walRootDir Path to the root directory where hbase files are stored
053   * @param serverName Region Server owner of the log
054   * @param logName WAL file name
055   */
056  public WALLink(final Path walRootDir, final String serverName, final String logName) {
057    final Path oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);
058    final Path logDir = new Path(new Path(walRootDir, HConstants.HREGION_LOGDIR_NAME), serverName);
059    setLocations(new Path(logDir, logName), new Path(oldLogDir, logName));
060  }
061
062  /**
063   * @param originPath Path to the wal in the log directory
064   * @param archivePath Path to the wal in the archived log directory
065   */
066  public WALLink(final Path originPath, final Path archivePath) {
067    setLocations(originPath, archivePath);
068  }
069}