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 */
018package org.apache.hadoop.hbase.io;
019
020import java.io.IOException;
021import org.apache.hadoop.conf.Configuration;
022import org.apache.hadoop.fs.Path;
023import org.apache.hadoop.hbase.HConstants;
024import org.apache.hadoop.hbase.util.CommonFSUtils;
025import org.apache.yetus.audience.InterfaceAudience;
026
027/**
028 * WALLink describes a link to a WAL. An wal can be in /hbase/.logs/<server>/<wal> or it
029 * can be in /hbase/.oldlogs/<wal> The link checks first in the original path, if it is not
030 * present it fallbacks to the archived path.
031 */
032@InterfaceAudience.Private
033public class WALLink extends FileLink {
034  /**
035   * @param conf       {@link Configuration} from which to extract specific archive locations
036   * @param serverName Region Server owner of the log
037   * @param logName    WAL file name
038   * @throws IOException on unexpected error.
039   */
040  public WALLink(final Configuration conf, final String serverName, final String logName)
041    throws IOException {
042    this(CommonFSUtils.getWALRootDir(conf), serverName, logName);
043  }
044
045  /**
046   * @param walRootDir Path to the root directory where hbase files are stored
047   * @param serverName Region Server owner of the log
048   * @param logName    WAL file name
049   */
050  public WALLink(final Path walRootDir, final String serverName, final String logName) {
051    final Path oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);
052    final Path logDir = new Path(new Path(walRootDir, HConstants.HREGION_LOGDIR_NAME), serverName);
053    setLocations(new Path(logDir, logName), new Path(oldLogDir, logName));
054  }
055
056  /**
057   * @param originPath  Path to the wal in the log directory
058   * @param archivePath Path to the wal in the archived log directory
059   */
060  public WALLink(final Path originPath, final Path archivePath) {
061    setLocations(originPath, archivePath);
062  }
063}