Class SegmentedJournal

java.lang.Object
io.camunda.zeebe.journal.file.SegmentedJournal
All Implemented Interfaces:
Journal, AutoCloseable

public final class SegmentedJournal extends Object implements Journal
A file based journal. The journal is split into multiple segments files.
  • Field Details

  • Method Details

    • builder

      public static SegmentedJournalBuilder builder()
      Returns a new SegmentedJournal builder.
      Returns:
      A new Segmented journal builder.
    • append

      public JournalRecord append(BufferWriter recordDataWriter)
      Description copied from interface: Journal
      Appends a new JournalRecord that contains the data to be written by the recordDataWriter. Use this for records that do not have a specific applicationSqNum. Examples for such record is raft record that indicates a leader change.
      Specified by:
      append in interface Journal
      Parameters:
      recordDataWriter - a writer that outputs the data of the record
      Returns:
      the journal record that was appended
    • append

      public JournalRecord append(long asqn, BufferWriter recordDataWriter)
      Description copied from interface: Journal
      Appends a new JournalRecord that contains the data to be written by the recordDataWriter. asqn refers to Application Sequence Number. It is a sequence number provided by the application. The given asqn must be positive and, it must be greater than the asqn of the previous record.
      Specified by:
      append in interface Journal
      Parameters:
      asqn - A sequence number provided by the application.
      recordDataWriter - a writer that outputs the data of the record
      Returns:
      the journal record that was appended
    • append

      public void append(JournalRecord record)
      Description copied from interface: Journal
      Appends a JournalRecord. If the index of the record is not the next expected index, the append will fail.
      Specified by:
      append in interface Journal
      Parameters:
      record - the record to be appended
    • deleteAfter

      public void deleteAfter(long indexExclusive)
      Description copied from interface: Journal
      Delete all records after indexExclusive. After a call to this method, Journal.getLastIndex() should return indexExclusive.
      Specified by:
      deleteAfter in interface Journal
      Parameters:
      indexExclusive - the index after which the records will be deleted.
    • deleteUntil

      public boolean deleteUntil(long index)
      Description copied from interface: Journal
      Attempts to delete all records until indexExclusive. The records may be immediately deleted or marked to be deleted later depending on the implementation.
      Specified by:
      deleteUntil in interface Journal
      Parameters:
      index - the index until which will be deleted. The record at this index is not deleted.
      Returns:
      true if anything was deleted, false otherwise
    • reset

      public void reset(long nextIndex)
      Description copied from interface: Journal
      Delete all records in the journal and reset the next index to nextIndex. The following calls to Journal.append(long, BufferWriter) will append at index nextIndex.

      After this operation, all readers must be reset explicitly. The readers that are not reset will return false for Iterator.hasNext(), cannot read any record.

      Specified by:
      reset in interface Journal
      Parameters:
      nextIndex - the next index of the journal.
    • getLastIndex

      public long getLastIndex()
      Description copied from interface: Journal
      Returns the index of last record in the journal
      Specified by:
      getLastIndex in interface Journal
      Returns:
      the last index
    • getFirstIndex

      public long getFirstIndex()
      Description copied from interface: Journal
      Returns the index of the first record.
      Specified by:
      getFirstIndex in interface Journal
      Returns:
      the first index
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Journal
      Check if the journal is empty.
      Specified by:
      isEmpty in interface Journal
      Returns:
      true if empty, false otherwise.
    • flush

      public void flush()
      Description copied from interface: Journal
      Depending on the implementation, appends to the journal may not be immediately flushed to the persistent storage. A call to this method guarantees that all records written are safely flushed to the persistent storage.
      Specified by:
      flush in interface Journal
    • openReader

      public JournalReader openReader()
      Description copied from interface: Journal
      Opens a new JournalReader
      Specified by:
      openReader in interface Journal
      Returns:
      a journal reader
    • isOpen

      public boolean isOpen()
      Description copied from interface: Journal
      Check if the journal is open
      Specified by:
      isOpen in interface Journal
      Returns:
      true if open, false otherwise
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • closeReader

      public void closeReader(io.camunda.zeebe.journal.file.SegmentedJournalReader segmentedJournalReader)
    • getJournalIndex

      public io.camunda.zeebe.journal.file.JournalIndex getJournalIndex()