Package org.apache.bookkeeper.bookie
Class Journal
java.lang.Object
org.apache.bookkeeper.bookie.Journal
- All Implemented Interfaces:
CheckpointSource
Provide journal related management.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFor testability.static classToken which represents the need to force a write to the Journal.static interfaceFilter to pickup journals.static interfaceScanner used to scan a journal.classLast Log Mark.(package private) static classJournal Entry to Record.Nested classes/interfaces inherited from interface org.apache.bookkeeper.bookie.CheckpointSource
CheckpointSource.Checkpoint -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ServerConfiguration(package private) final FileChannelProvider(package private) BatchedBlockingQueue<Journal.ForceWriteRequest>(package private) final org.apache.bookkeeper.bookie.Journal.ForceWriteThread(package private) final File(package private) final long(package private) final int(package private) static final int(package private) final int(package private) final long(package private) static final long(package private) static final int(package private) final BatchedBlockingQueue<Journal.QueueEntry>(package private) booleanFields inherited from interface org.apache.bookkeeper.bookie.CheckpointSource
DEFAULT -
Constructor Summary
ConstructorsConstructorDescriptionJournal(int journalIndex, File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager) Journal(int journalIndex, File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) Journal(int journalIndex, File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, JournalAliveListener journalAliveListener) -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckpointComplete(CheckpointSource.Checkpoint checkpoint, boolean compact) Telling journal a checkpoint is finished.(package private) voidforceLedger(long ledgerId, BookkeeperInternalCallbacks.WriteCallback cb, Object ctx) intGet the length of journal entries queue.(package private) JournalStats(package private) longvoidvoidWait for the Journal thread to exit.listJournalIds(File journalDir, Journal.JournalIdFilter filter) List all journal ids by a specified journal id filer.voidlogAddEntry(long ledgerId, long entryId, io.netty.buffer.ByteBuf entry, boolean ackBeforeSync, BookkeeperInternalCallbacks.WriteCallback cb, Object ctx) voidlogAddEntry(io.netty.buffer.ByteBuf entry, boolean ackBeforeSync, BookkeeperInternalCallbacks.WriteCallback cb, Object ctx) record an add entry operation in journal.Application tried to schedule a checkpoint.(package private) static JournalnewJournal(int journalIndex, File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, JournalAliveListener journalAliveListener) (package private) JournalChannelnewLogFile(long logId, Long replaceLogId) voidrun()A thread used for persisting journal entries to journal files.longscanJournal(long journalId, long journalPos, Journal.JournalScanner scanner, boolean skipInvalidRecord) Scan the journal.voidsetForceWriteRequests(BatchedBlockingQueue<Journal.ForceWriteRequest> forceWriteRequests) (package private) voidsetLastLogMark(Long id, long scanOffset) Update lastLogMark of the journal Indicates that the file has been processed.(package private) voidsetMemoryLimitController(MemoryLimitController memoryLimitController) voidshutdown()Shuts down the journal.voidstart()(package private) static voidwritePaddingBytes(JournalChannel jc, io.netty.buffer.ByteBuf paddingBuffer, int journalAlignSize)
-
Field Details
-
PADDING_MASK
static final int PADDING_MASK- See Also:
-
MB
static final long MB- See Also:
-
KB
static final int KB- See Also:
-
maxJournalSize
final long maxJournalSize -
journalPreAllocSize
final long journalPreAllocSize -
journalWriteBufferSize
final int journalWriteBufferSize -
maxBackupJournals
final int maxBackupJournals -
journalDirectory
-
conf
-
forceWriteThread
final org.apache.bookkeeper.bookie.Journal.ForceWriteThread forceWriteThread -
fileChannelProvider
-
queue
-
forceWriteRequests
BatchedBlockingQueue<Journal.ForceWriteRequest> forceWriteRequests -
running
volatile boolean running
-
-
Constructor Details
-
Journal
public Journal(int journalIndex, File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager) -
Journal
public Journal(int journalIndex, File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) -
Journal
public Journal(int journalIndex, File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, JournalAliveListener journalAliveListener)
-
-
Method Details
-
listJournalIds
List all journal ids by a specified journal id filer.- Parameters:
journalDir- journal dirfilter- 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
-
getLastLogMark
-
setLastLogMark
Update lastLogMark of the journal Indicates that the file has been processed.- Parameters:
id-scanOffset-
-
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:
newCheckpointin interfaceCheckpointSource- Returns:
- checkpoint.
-
checkpointComplete
public void checkpointComplete(CheckpointSource.Checkpoint checkpoint, boolean compact) throws IOException Telling journal a checkpoint is finished.- Specified by:
checkpointCompletein interfaceCheckpointSource- Parameters:
checkpoint- The checkpoint that has been completedcompact- 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 IdjournalPos- Offset to start scanningscanner- Scanner to handle entriesskipInvalidRecord- 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
-
getJournalQueueLength
public int getJournalQueueLength()Get the length of journal entries queue.- Returns:
- length of journal entry queue.
-
newLogFile
- 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
-
shutdown
public void shutdown()Shuts down the journal. -
joinThread
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
-
setForceWriteRequests
public void setForceWriteRequests(BatchedBlockingQueue<Journal.ForceWriteRequest> forceWriteRequests)
-