Class BaseTranslogReader

java.lang.Object
org.elasticsearch.index.translog.BaseTranslogReader
All Implemented Interfaces:
java.lang.Comparable<BaseTranslogReader>
Direct Known Subclasses:
TranslogReader, TranslogWriter

public abstract class BaseTranslogReader
extends java.lang.Object
implements java.lang.Comparable<BaseTranslogReader>
A base class for all classes that allows reading ops from translog files
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected java.nio.channels.FileChannel channel  
    protected long generation  
    protected org.elasticsearch.index.translog.TranslogHeader header  
    protected java.nio.file.Path path  
  • Constructor Summary

    Constructors 
    Constructor Description
    BaseTranslogReader​(long generation, java.nio.channels.FileChannel channel, java.nio.file.Path path, org.elasticsearch.index.translog.TranslogHeader header)  
  • Method Summary

    Modifier and Type Method Description
    protected BufferedChecksumStreamInput checksummedStream​(java.nio.ByteBuffer reusableBuffer, long position, int opSize, BufferedChecksumStreamInput reuse)
    reads an operation at the given position and returns it.
    int compareTo​(BaseTranslogReader o)  
    long getFirstOperationOffset()  
    long getGeneration()  
    long getLastModifiedTime()  
    long getPrimaryTerm()
    Returns the primary term associated with this translog reader.
    org.elasticsearch.index.translog.TranslogSnapshot newSnapshot()  
    java.nio.file.Path path()  
    protected Translog.Operation read​(BufferedChecksumStreamInput inStream)  
    protected abstract void readBytes​(java.nio.ByteBuffer buffer, long position)
    reads bytes at position into the given buffer, filling it.
    protected int readSize​(java.nio.ByteBuffer reusableBuffer, long position)
    read the size of the op (i.e., number of bytes, including the op size) written at the given position
    abstract long sizeInBytes()  
    java.lang.String toString()  
    abstract int totalOperations()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • generation

      protected final long generation
    • channel

      protected final java.nio.channels.FileChannel channel
    • path

      protected final java.nio.file.Path path
    • header

      protected final org.elasticsearch.index.translog.TranslogHeader header
  • Constructor Details

    • BaseTranslogReader

      public BaseTranslogReader​(long generation, java.nio.channels.FileChannel channel, java.nio.file.Path path, org.elasticsearch.index.translog.TranslogHeader header)
  • Method Details

    • getGeneration

      public long getGeneration()
    • sizeInBytes

      public abstract long sizeInBytes()
    • totalOperations

      public abstract int totalOperations()
    • getFirstOperationOffset

      public final long getFirstOperationOffset()
    • getPrimaryTerm

      public final long getPrimaryTerm()
      Returns the primary term associated with this translog reader.
    • readSize

      protected final int readSize​(java.nio.ByteBuffer reusableBuffer, long position) throws java.io.IOException
      read the size of the op (i.e., number of bytes, including the op size) written at the given position
      Throws:
      java.io.IOException
    • newSnapshot

      public org.elasticsearch.index.translog.TranslogSnapshot newSnapshot()
    • checksummedStream

      protected final BufferedChecksumStreamInput checksummedStream​(java.nio.ByteBuffer reusableBuffer, long position, int opSize, BufferedChecksumStreamInput reuse) throws java.io.IOException
      reads an operation at the given position and returns it. The buffer length is equal to the number of bytes reads.
      Throws:
      java.io.IOException
    • read

      protected Translog.Operation read​(BufferedChecksumStreamInput inStream) throws java.io.IOException
      Throws:
      java.io.IOException
    • readBytes

      protected abstract void readBytes​(java.nio.ByteBuffer buffer, long position) throws java.io.IOException
      reads bytes at position into the given buffer, filling it.
      Throws:
      java.io.IOException
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • compareTo

      public int compareTo​(BaseTranslogReader o)
      Specified by:
      compareTo in interface java.lang.Comparable<BaseTranslogReader>
    • path

      public java.nio.file.Path path()
    • getLastModifiedTime

      public long getLastModifiedTime() throws java.io.IOException
      Throws:
      java.io.IOException