Class Journal

java.lang.Object
org.apache.bookkeeper.bookie.Journal
All Implemented Interfaces:
CheckpointSource

public class Journal extends Object implements CheckpointSource
Provide journal related management.
  • Field Details

  • Constructor Details

  • Method Details

    • listJournalIds

      public static List<Long> listJournalIds(File journalDir, Journal.JournalIdFilter filter)
      List all journal ids by a specified journal id filer.
      Parameters:
      journalDir - journal dir
      filter - journal id filter
      Returns:
      list of filtered ids
    • writePaddingBytes

      static void writePaddingBytes(JournalChannel jc, io.netty.buffer.ByteBuf paddingBuffer, int journalAlignSize) throws IOException
      Throws:
      IOException
    • newJournal

      static Journal newJournal(int journalIndex, File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, JournalAliveListener journalAliveListener)
    • getJournalStats

      JournalStats getJournalStats()
    • getJournalDirectory

      public File getJournalDirectory()
    • getLastLogMark

      public Journal.LastLogMark getLastLogMark()
    • setLastLogMark

      void setLastLogMark(Long id, long scanOffset)
      Update lastLogMark of the journal Indicates that the file has been processed.
      Parameters:
      id -
      scanOffset -
    • newCheckpoint

      public CheckpointSource.Checkpoint newCheckpoint()
      Application tried to schedule a checkpoint. After all the txns added before checkpoint are persisted, a checkpoint will be returned to application. Application could use checkpoint to do its logic.
      Specified by:
      newCheckpoint in interface CheckpointSource
      Returns:
      checkpoint.
    • checkpointComplete

      public void checkpointComplete(CheckpointSource.Checkpoint checkpoint, boolean compact) throws IOException
      Telling journal a checkpoint is finished.
      Specified by:
      checkpointComplete in interface CheckpointSource
      Parameters:
      checkpoint - The checkpoint that has been completed
      compact - Flag to compact old checkpoints.
      Throws:
      IOException
    • scanJournal

      public long scanJournal(long journalId, long journalPos, Journal.JournalScanner scanner, boolean skipInvalidRecord) throws IOException
      Scan the journal.
      Parameters:
      journalId - Journal Log Id
      journalPos - Offset to start scanning
      scanner - Scanner to handle entries
      skipInvalidRecord - when invalid record,should we skip it or not
      Returns:
      scanOffset - represents the byte till which journal was read
      Throws:
      IOException
    • logAddEntry

      public void logAddEntry(io.netty.buffer.ByteBuf entry, boolean ackBeforeSync, BookkeeperInternalCallbacks.WriteCallback cb, Object ctx) throws InterruptedException
      record an add entry operation in journal.
      Throws:
      InterruptedException
    • logAddEntry

      public void logAddEntry(long ledgerId, long entryId, io.netty.buffer.ByteBuf entry, boolean ackBeforeSync, BookkeeperInternalCallbacks.WriteCallback cb, Object ctx) throws InterruptedException
      Throws:
      InterruptedException
    • forceLedger

      void forceLedger(long ledgerId, BookkeeperInternalCallbacks.WriteCallback cb, Object ctx)
    • getJournalQueueLength

      public int getJournalQueueLength()
      Get the length of journal entries queue.
      Returns:
      length of journal entry queue.
    • newLogFile

      JournalChannel newLogFile(long logId, Long replaceLogId) throws IOException
      Throws:
      IOException
    • run

      public void run()
      A thread used for persisting journal entries to journal files.

      Besides persisting journal entries, it also takes responsibility of rolling journal files when a journal file reaches journal file size limitation.

      During journal rolling, it first closes the writing journal, generates new journal file using current timestamp, and continue persistence logic. Those journals will be garbage collected in SyncThread.

      See Also:
    • getBufferedChannelBuilder

      public Journal.BufferedChannelBuilder getBufferedChannelBuilder()
    • shutdown

      public void shutdown()
      Shuts down the journal.
    • joinThread

      public void joinThread() throws InterruptedException
      Wait for the Journal thread to exit. This is method is needed in order to mock the journal, we can't mock final method of java.lang.Thread class
      Throws:
      InterruptedException
    • interruptThread

      public void interruptThread()
    • start

      public void start()
    • getMemoryUsage

      long getMemoryUsage()
    • setMemoryLimitController

      void setMemoryLimitController(MemoryLimitController memoryLimitController)
    • setForceWriteRequests

      public void setForceWriteRequests(BatchedBlockingQueue<Journal.ForceWriteRequest> forceWriteRequests)