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.hdfs.server.namenode;
019
020import java.io.Closeable;
021import java.io.IOException;
022
023import org.apache.hadoop.classification.InterfaceAudience;
024import org.apache.hadoop.classification.InterfaceStability;
025import org.apache.hadoop.hdfs.server.common.Storage.FormatConfirmable;
026import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
027
028/**
029 * A JournalManager is responsible for managing a single place of storing
030 * edit logs. It may correspond to multiple files, a backup node, etc.
031 * Even when the actual underlying storage is rolled, or failed and restored,
032 * each conceptual place of storage corresponds to exactly one instance of
033 * this class, which is created when the EditLog is first opened.
034 */
035@InterfaceAudience.Private
036@InterfaceStability.Evolving
037public interface JournalManager extends Closeable, LogsPurgeable,
038                                        FormatConfirmable {
039
040  /**
041   * Format the underlying storage, removing any previously
042   * stored data.
043   */
044  void format(NamespaceInfo ns) throws IOException;
045
046  /**
047   * Begin writing to a new segment of the log stream, which starts at
048   * the given transaction ID.
049   */
050  EditLogOutputStream startLogSegment(long txId) throws IOException;
051
052  /**
053   * Mark the log segment that spans from firstTxId to lastTxId
054   * as finalized and complete.
055   */
056  void finalizeLogSegment(long firstTxId, long lastTxId) throws IOException;
057
058  /**
059   * Set the amount of memory that this stream should use to buffer edits
060   */
061  void setOutputBufferCapacity(int size);
062
063  /**
064   * Recover segments which have not been finalized.
065   */
066  void recoverUnfinalizedSegments() throws IOException;
067
068  /**
069   * Close the journal manager, freeing any resources it may hold.
070   */
071  @Override
072  void close() throws IOException;
073  
074  /** 
075   * Indicate that a journal is cannot be used to load a certain range of 
076   * edits.
077   * This exception occurs in the case of a gap in the transactions, or a
078   * corrupt edit file.
079   */
080  public static class CorruptionException extends IOException {
081    static final long serialVersionUID = -4687802717006172702L;
082    
083    public CorruptionException(String reason) {
084      super(reason);
085    }
086  }
087}