Class TranslogWriter

All Implemented Interfaces:, java.lang.AutoCloseable, java.lang.Comparable<BaseTranslogReader>

public class TranslogWriter
extends BaseTranslogReader
  • Field Details

    • closed

      protected final java.util.concurrent.atomic.AtomicBoolean closed
  • Method Details

    • create

      public static TranslogWriter create​(ShardId shardId, java.lang.String translogUUID, long fileGeneration, java.nio.file.Path file, ChannelFactory channelFactory, ByteSizeValue bufferSize, long initialMinTranslogGen, long initialGlobalCheckpoint, java.util.function.LongSupplier globalCheckpointSupplier, java.util.function.LongSupplier minTranslogGenerationSupplier, long primaryTerm, TragicExceptionHolder tragedy, java.util.function.LongConsumer persistedSequenceNumberConsumer) throws
    • add

      public Translog.Location add​(BytesReference data, long seqNo) throws
      Add the given bytes to the translog with the specified sequence number; returns the location the bytes were written to.
      data - the bytes to write
      seqNo - the sequence number associated with the operation
      the location the bytes were written to
      Throws: - if writing to the translog resulted in an I/O exception
    • sync

      public void sync() throws
      write all buffered ops to disk and fsync file. Note: any exception during the sync process will be interpreted as a tragic exception and the writer will be closed before raising the exception.
    • syncNeeded

      public boolean syncNeeded()
      Returns true if there are buffered operations that have not been flushed and fsynced to disk or if the latest global checkpoint has not yet been fsynced
    • totalOperations

      public int totalOperations()
      Specified by:
      totalOperations in class BaseTranslogReader
    • sizeInBytes

      public long sizeInBytes()
      Specified by:
      sizeInBytes in class BaseTranslogReader
    • closeIntoReader

      public TranslogReader closeIntoReader() throws
      Closes this writer and transfers its underlying file channel to a new immutable TranslogReader
      a new TranslogReader
      Throws: - if any of the file operations resulted in an I/O exception
    • newSnapshot

      public org.elasticsearch.index.translog.TranslogSnapshot newSnapshot()
      newSnapshot in class BaseTranslogReader
    • readBytes

      protected void readBytes​(java.nio.ByteBuffer targetBuffer, long position) throws
      Description copied from class: BaseTranslogReader
      reads bytes at position into the given buffer, filling it.
      Specified by:
      readBytes in class BaseTranslogReader
    • ensureOpen

      protected final void ensureOpen()
    • close

      public final void close() throws
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface
    • isClosed

      protected final boolean isClosed()