Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.apache.hadoop.hbase.replication.regionserver;
Wrapper class around HLog to help manage the implementation details such as compression.
 public class ReplicationHLogReaderManager {
   private static final Log LOG = LogFactory.getLog(ReplicationHLogReaderManager.class);
   private final FileSystem fs;
   private final Configuration conf;
   private long position = 0;
   private HLog.Reader reader;
   private Path lastPath;

Creates the helper but doesn't open any file Use setInitialPosition after using the constructor if some content needs to be skipped

     this. = fs;
     this. = conf;

Opens the file at the current position

an HLog reader.
   public HLog.Reader openReader(Path paththrows IOException {
     // Detect if this is a new file, if so get a new reader else
     // reset the current reader so that we see the new data
     if (this. == null || !this..equals(path)) {
       this. = HLogFactory.createReader(this.paththis.);
       this. = path;
     } else {
       try {
       } catch (NullPointerException npe) {
         throw new IOException("NPE resetting reader, likely HDFS-4380"npe);
     return this.;

Get the next entry, returned and also added in the array

a new entry or null
   public HLog.Entry readNextAndSetPosition() throws IOException {
     HLog.Entry entry =;
     // Store the position so that in the future the reader can start
     // reading from here. If the above call to next() throws an
     // exception, the position won't be changed and retry will happen
     // from the last known good position
     this. = this..getPosition();
     // We need to set the CC to null else it will be compressed when sent to the sink
     if (entry != null) {
     return entry;

Advance the reader to the current position

  public void seek() throws IOException {
    if (this. != 0) {;

Get the position that we stopped reading at

current position, cannot be negative
  public long getPosition() {
    return this.;
  public void setPosition(long pos) {
    this. = pos;

Close the current reader

  public void closeReader() throws IOException {
    if (this. != null) {
      this. = null;

Tell the helper to reset internal state
  void finishCurrentFile() {
    this. = 0;
    try {
    } catch (IOException e) {
      .warn("Unable to close reader"e);
New to GrepCode? Check out our FAQ X