Class Journal

    • Method Detail

      • listJournalIds

        public static java.util.List<java.lang.Long> listJournalIds​(java.io.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 java.io.IOException
        Throws:
        java.io.IOException
      • getJournalDirectory

        public java.io.File getJournalDirectory()
      • setLastLogMark

        void setLastLogMark​(java.lang.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 java.io.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:
        java.io.IOException
      • scanJournal

        public long scanJournal​(long journalId,
                                long journalPos,
                                Journal.JournalScanner scanner,
                                boolean skipInvalidRecord)
                         throws java.io.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:
        java.io.IOException
      • logAddEntry

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

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

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

        JournalChannel newLogFile​(long logId,
                                  java.lang.Long replaceLogId)
                           throws java.io.IOException
        Throws:
        java.io.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:
        SyncThread
      • shutdown

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

        public void joinThread()
                        throws java.lang.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:
        java.lang.InterruptedException
      • interruptThread

        public void interruptThread()
      • start

        public void start()
      • getMemoryUsage

        long getMemoryUsage()
      • setMemoryLimitController

        void setMemoryLimitController​(MemoryLimitController memoryLimitController)