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.wal;
019
020import java.io.Closeable;
021import java.io.IOException;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * A one way WAL reader, without reset and seek support.
026 * <p/>
027 * In most cases you should use this interface to read WAL file, as the implementation is simple and
028 * robust. For replication, where we want to tail the WAL file which is currently being written, you
029 * should use {@link WALTailingReader} instead.
030 * @see WALTailingReader
031 */
032@InterfaceAudience.Private
033public interface WALStreamReader extends Closeable {
034
035  /**
036   * Read the next entry in WAL.
037   * <p/>
038   * In most cases you should just use this method, especially when reading a closed wal file for
039   * splitting or printing.
040   */
041  default WAL.Entry next() throws IOException {
042    return next(null);
043  }
044
045  /**
046   * Read the next entry in WAL, use the given {@link WAL.Entry} if not {@code null} to hold the
047   * data.
048   * <p/>
049   * Mainly used in MR.
050   * @param reuse the entry to be used for reading, can be {@code null}
051   */
052  WAL.Entry next(WAL.Entry reuse) throws IOException;
053
054  /**
055   * Get the current reading position.
056   */
057  long getPosition() throws IOException;
058
059  /**
060   * Override to remove the 'throws IOException' as we are just a reader.
061   */
062  @Override
063  void close();
064}