Package org.apache.bookkeeper.bookie
Class Journal
- java.lang.Object
-
- org.apache.bookkeeper.bookie.Journal
-
- All Implemented Interfaces:
CheckpointSource
public class Journal extends java.lang.Object implements CheckpointSource
Provide journal related management.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceJournal.BufferedChannelBuilderFor testability.static classJournal.ForceWriteRequestToken which represents the need to force a write to the Journal.static interfaceJournal.JournalIdFilterFilter to pickup journals.static interfaceJournal.JournalScannerScanner used to scan a journal.classJournal.LastLogMarkLast Log Mark.(package private) static classJournal.QueueEntryJournal Entry to Record.-
Nested classes/interfaces inherited from interface org.apache.bookkeeper.bookie.CheckpointSource
CheckpointSource.Checkpoint
-
-
Field Summary
Fields Modifier and Type Field Description (package private) ServerConfigurationconf(package private) FileChannelProviderfileChannelProvider(package private) BatchedBlockingQueue<Journal.ForceWriteRequest>forceWriteRequests(package private) org.apache.bookkeeper.bookie.Journal.ForceWriteThreadforceWriteThread(package private) java.io.FilejournalDirectory(package private) longjournalPreAllocSize(package private) intjournalWriteBufferSize(package private) static intKB(package private) intmaxBackupJournals(package private) longmaxJournalSize(package private) static longMB(package private) static intPADDING_MASK(package private) BatchedBlockingQueue<Journal.QueueEntry>queue(package private) booleanrunning-
Fields inherited from interface org.apache.bookkeeper.bookie.CheckpointSource
DEFAULT
-
-
Constructor Summary
Constructors Constructor Description Journal(int journalIndex, java.io.File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager)Journal(int journalIndex, java.io.File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator)Journal(int journalIndex, java.io.File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, JournalAliveListener journalAliveListener)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckpointComplete(CheckpointSource.Checkpoint checkpoint, boolean compact)Telling journal a checkpoint is finished.(package private) voidforceLedger(long ledgerId, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx)Journal.BufferedChannelBuildergetBufferedChannelBuilder()java.io.FilegetJournalDirectory()intgetJournalQueueLength()Get the length of journal entries queue.(package private) JournalStatsgetJournalStats()Journal.LastLogMarkgetLastLogMark()(package private) longgetMemoryUsage()voidinterruptThread()voidjoinThread()Wait for the Journal thread to exit.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.voidlogAddEntry(long ledgerId, long entryId, io.netty.buffer.ByteBuf entry, boolean ackBeforeSync, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx)voidlogAddEntry(io.netty.buffer.ByteBuf entry, boolean ackBeforeSync, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx)record an add entry operation in journal.CheckpointSource.CheckpointnewCheckpoint()Application tried to schedule a checkpoint.(package private) static JournalnewJournal(int journalIndex, java.io.File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, JournalAliveListener journalAliveListener)(package private) JournalChannelnewLogFile(long logId, java.lang.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(java.lang.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 Detail
-
PADDING_MASK
static final int PADDING_MASK
- See Also:
- Constant Field Values
-
MB
static final long MB
- See Also:
- Constant Field Values
-
KB
static final int KB
- See Also:
- Constant Field Values
-
maxJournalSize
final long maxJournalSize
-
journalPreAllocSize
final long journalPreAllocSize
-
journalWriteBufferSize
final int journalWriteBufferSize
-
maxBackupJournals
final int maxBackupJournals
-
journalDirectory
final java.io.File journalDirectory
-
conf
final ServerConfiguration conf
-
forceWriteThread
final org.apache.bookkeeper.bookie.Journal.ForceWriteThread forceWriteThread
-
fileChannelProvider
final FileChannelProvider fileChannelProvider
-
queue
final BatchedBlockingQueue<Journal.QueueEntry> queue
-
forceWriteRequests
BatchedBlockingQueue<Journal.ForceWriteRequest> forceWriteRequests
-
running
volatile boolean running
-
-
Constructor Detail
-
Journal
public Journal(int journalIndex, java.io.File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager)
-
Journal
public Journal(int journalIndex, java.io.File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator)
-
Journal
public Journal(int journalIndex, java.io.File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, JournalAliveListener journalAliveListener)
-
-
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 dirfilter- 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
-
newJournal
static Journal newJournal(int journalIndex, java.io.File journalDirectory, ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, JournalAliveListener journalAliveListener)
-
getJournalStats
JournalStats getJournalStats()
-
getJournalDirectory
public java.io.File getJournalDirectory()
-
getLastLogMark
public Journal.LastLogMark getLastLogMark()
-
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:
newCheckpointin interfaceCheckpointSource- Returns:
- checkpoint.
-
checkpointComplete
public void checkpointComplete(CheckpointSource.Checkpoint checkpoint, boolean compact) throws java.io.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:
java.io.IOException
-
scanJournal
public long scanJournal(long journalId, long journalPos, Journal.JournalScanner scanner, boolean skipInvalidRecord) throws java.io.IOExceptionScan 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:
java.io.IOException
-
logAddEntry
public void logAddEntry(io.netty.buffer.ByteBuf entry, boolean ackBeforeSync, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx) throws java.lang.InterruptedExceptionrecord 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
-
forceLedger
void forceLedger(long ledgerId, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx)
-
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
-
getBufferedChannelBuilder
public Journal.BufferedChannelBuilder getBufferedChannelBuilder()
-
shutdown
public void shutdown()
Shuts down the journal.
-
joinThread
public void joinThread() throws java.lang.InterruptedExceptionWait 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)
-
setForceWriteRequests
public void setForceWriteRequests(BatchedBlockingQueue<Journal.ForceWriteRequest> forceWriteRequests)
-
-