Package org.apache.bookkeeper.bookie
Class DefaultEntryLogger
java.lang.Object
org.apache.bookkeeper.bookie.DefaultEntryLogger
- All Implemented Interfaces:
AutoCloseable,EntryLogger
- Direct Known Subclasses:
ReadOnlyDefaultEntryLogger
This class manages the writing of the bookkeeper entries. All the new
entries are written to a common log. The LedgerCache will have pointers
into files created by this class with offsets into the files to find
the actual ledger entry. The entry log files created by this class are
identified by a long.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class(package private) static interfaceEntry Log Listener.(package private) static classException type for representing lookup errors.(package private) static classDatastructure which maintains the status of logchannels. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ServerConfiguration(package private) final EntryLoggerAllocator(package private) static final int(package private) static final int(package private) static final long(package private) static final long(package private) static final int(package private) static final intLedgers map is composed of multiple parts that can be split into separated entries.(package private) static final int(package private) static final int(package private) static final intThe 1K block at the head of the entry logger file that contains the fingerprint and meta-data.(package private) static final long(package private) static final int(package private) final DefaultEntryLogger.RecentEntryLogsStatus(package private) static final intFields inherited from interface org.apache.bookkeeper.bookie.storage.EntryLogger
LOG_FILE_SUFFIX, UNASSIGNED_LEDGERID -
Constructor Summary
ConstructorsConstructorDescriptionDefaultEntryLogger(ServerConfiguration conf, LedgerDirsManager ledgerDirsManager) Create an EntryLogger that stores it's log files in the given directories.DefaultEntryLogger(ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, DefaultEntryLogger.EntryLogListener listener, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) -
Method Summary
Modifier and TypeMethodDescriptionlongaddEntry(long ledger, io.netty.buffer.ByteBuf entry) Add an entry for ledger ```ledgerId``` to the entrylog.(package private) longaddEntry(long ledger, io.netty.buffer.ByteBuf entry, boolean rollLog) (package private) longaddEntry(long ledger, ByteBuffer entry) (package private) void(package private) voidcheckEntry(long ledgerId, long entryId, long location) (package private) voidFlushes all rotated log channels.(package private) voidvoidclose()Shutdown method to gracefully stop entry logger.(package private) boolean(package private) EntryLogMetadataextractEntryLogMetadataFromIndex(long entryLogId) (package private) static longfileName2LogId(String fileName) Convert log filename (hex format with suffix) to logId in long.voidflush()Flush any outstanding writes to disk.(package private) BufferedReadChannelgetChannelForLogId(long entryLogId) (package private) EntryLoggerAllocatorget EntryLoggerAllocator, Just for tests.(package private) EntryLogManagergetEntryLogMetadata(long entryLogId, AbstractLogCompactor.Throttler throttler) Retrieve metadata for the given entrylog ID.Returns a set with the ids of all the entry log files.Get the log ids for the set of logs which have been completely flushed to disk.getFromChannels(long logId) (package private) longprotected LedgerDirsManager(package private) longReturn a collection of all the compaction entry logs which have been compacted, but have not been cleaned up.booleanlogExists(long logId) Whether the log file exists or not.(package private) static StringlogId2HexString(long logId) Convert log Id to hex string.(package private) static longlogIdForOffset(long offset) newCompactionLog(long logToCompact) Create a new entrylog into which compacted entries can be added.(package private) static longposForOffset(long location) (package private) void(package private) voidprepareSortedLedgerStorageCheckpoint(long numBytesFlushed) putInReadChannels(long logId, BufferedReadChannel bc) Put the logId, bc pair in the map responsible for the current thread.io.netty.buffer.ByteBufreadEntry(long location) Read an entry from an entrylog location.io.netty.buffer.ByteBufreadEntry(long ledgerId, long entryId, long entryLocation) Read an entry from an entrylog location, and verify that is matches the expected ledger and entry ID.booleanremoveEntryLog(long entryLogId) Remove entry log.voidremoveFromChannelsAndClose(long logId) Remove all entries for this log file in each thread's cache.voidscanEntryLog(long entryLogId, EntryLogScanner scanner) Scan entry log.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.bookkeeper.bookie.storage.EntryLogger
getEntryLogMetadata
-
Field Details
-
UNINITIALIZED_LOG_ID
static final int UNINITIALIZED_LOG_ID- See Also:
-
recentlyCreatedEntryLogsStatus
-
entryLoggerAllocator
-
HEADER_CURRENT_VERSION
static final int HEADER_CURRENT_VERSION- See Also:
-
LOGFILE_HEADER_SIZE
static final int LOGFILE_HEADER_SIZEThe 1K block at the head of the entry logger file that contains the fingerprint and meta-data.Header is composed of: Fingerprint: 4 bytes "BKLO" Log file HeaderVersion enum: 4 bytes Ledger map offset: 8 bytes Ledgers Count: 4 bytes
- See Also:
-
HEADER_VERSION_POSITION
static final int HEADER_VERSION_POSITION- See Also:
-
LEDGERS_MAP_OFFSET_POSITION
static final int LEDGERS_MAP_OFFSET_POSITION- See Also:
-
LEDGERS_MAP_HEADER_SIZE
static final int LEDGERS_MAP_HEADER_SIZELedgers map is composed of multiple parts that can be split into separated entries. Each of them is composed of:length: (4 bytes) [0-3] ledger id (-1): (8 bytes) [4 - 11] entry id: (8 bytes) [12-19] num ledgers stored in current metadata entry: (4 bytes) [20 - 23] ledger entries: sequence of (ledgerid, size) (8 + 8 bytes each) [24..]
- See Also:
-
LEDGERS_MAP_ENTRY_SIZE
static final int LEDGERS_MAP_ENTRY_SIZE- See Also:
-
LEDGERS_MAP_MAX_BATCH_SIZE
static final int LEDGERS_MAP_MAX_BATCH_SIZE- See Also:
-
INVALID_LID
static final long INVALID_LID- See Also:
-
LEDGERS_MAP_ENTRY_ID
static final long LEDGERS_MAP_ENTRY_ID- See Also:
-
MIN_SANE_ENTRY_SIZE
static final int MIN_SANE_ENTRY_SIZE- See Also:
-
MB
static final long MB- See Also:
-
conf
-
-
Constructor Details
-
DefaultEntryLogger
- Throws:
IOException
-
DefaultEntryLogger
public DefaultEntryLogger(ServerConfiguration conf, LedgerDirsManager ledgerDirsManager) throws IOException Create an EntryLogger that stores it's log files in the given directories.- Throws:
IOException
-
DefaultEntryLogger
public DefaultEntryLogger(ServerConfiguration conf, LedgerDirsManager ledgerDirsManager, DefaultEntryLogger.EntryLogListener listener, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator) throws IOException - Throws:
IOException
-
-
Method Details
-
getEntryLogManager
EntryLogManager getEntryLogManager() -
addListener
-
putInReadChannels
Put the logId, bc pair in the map responsible for the current thread.- Parameters:
logId-bc-
-
removeFromChannelsAndClose
public void removeFromChannelsAndClose(long logId) Remove all entries for this log file in each thread's cache.- Parameters:
logId-
-
getFromChannels
-
getLeastUnflushedLogId
long getLeastUnflushedLogId() -
getFlushedLogIds
Description copied from interface:EntryLoggerGet the log ids for the set of logs which have been completely flushed to disk. Only log ids in this set are considered for either compaction or garbage collection.- Specified by:
getFlushedLogIdsin interfaceEntryLogger
-
getPreviousAllocatedEntryLogId
long getPreviousAllocatedEntryLogId() -
prepareSortedLedgerStorageCheckpoint
- Throws:
IOException
-
prepareEntryMemTableFlush
void prepareEntryMemTableFlush() -
commitEntryMemTableFlush
- Throws:
IOException
-
getEntryLoggerAllocator
EntryLoggerAllocator getEntryLoggerAllocator()get EntryLoggerAllocator, Just for tests. -
removeEntryLog
public boolean removeEntryLog(long entryLogId) Remove entry log.- Specified by:
removeEntryLogin interfaceEntryLogger- Parameters:
entryLogId- Entry Log File Id- Returns:
- false if the entrylog doesn't exist.
-
clearCompactingLogId
void clearCompactingLogId() -
checkpoint
Flushes all rotated log channels. After log channels are flushed, move leastUnflushedLogId ptr to current logId.- Throws:
IOException
-
flush
Description copied from interface:EntryLoggerFlush any outstanding writes to disk.- Specified by:
flushin interfaceEntryLogger- Throws:
IOException
-
addEntry
- Throws:
IOException
-
addEntry
- Throws:
IOException
-
addEntry
Description copied from interface:EntryLoggerAdd an entry for ledger ```ledgerId``` to the entrylog.- Specified by:
addEntryin interfaceEntryLogger- Parameters:
ledger- the ledger for which the entry is being addedentry- the contents of the entry (this method does not take ownership of the refcount)- Returns:
- the location in the entry log of the added entry
- Throws:
IOException
-
logIdForOffset
static long logIdForOffset(long offset) -
posForOffset
static long posForOffset(long location) -
checkEntry
void checkEntry(long ledgerId, long entryId, long location) throws DefaultEntryLogger.EntryLookupException, IOException -
readEntry
public io.netty.buffer.ByteBuf readEntry(long ledgerId, long entryId, long entryLocation) throws IOException, Bookie.NoEntryException Description copied from interface:EntryLoggerRead an entry from an entrylog location, and verify that is matches the expected ledger and entry ID.- Specified by:
readEntryin interfaceEntryLogger- Parameters:
ledgerId- the ledgerID to matchentryId- the entryID to matchentryLocation- the location from which to read the entry- Returns:
- the entry
- Throws:
IOExceptionBookie.NoEntryException
-
readEntry
Description copied from interface:EntryLoggerRead an entry from an entrylog location.- Specified by:
readEntryin interfaceEntryLogger- Parameters:
location- the location from which to read the entry- Returns:
- the entry
- Throws:
IOExceptionBookie.NoEntryException
-
getChannelForLogId
- Throws:
IOException
-
logExists
public boolean logExists(long logId) Whether the log file exists or not.- Specified by:
logExistsin interfaceEntryLogger
-
getEntryLogsSet
Returns a set with the ids of all the entry log files.- Throws:
IOException
-
scanEntryLog
Scan entry log.- Specified by:
scanEntryLogin interfaceEntryLogger- Parameters:
entryLogId- Entry Log Idscanner- Entry Log Scanner- Throws:
IOException
-
getEntryLogMetadata
public EntryLogMetadata getEntryLogMetadata(long entryLogId, AbstractLogCompactor.Throttler throttler) throws IOException Description copied from interface:EntryLoggerRetrieve metadata for the given entrylog ID. The metadata contains the size of the log, the size of the data in the log which is still active, and a list of all the ledgers contained in the log and the size of the data stored for each ledger.- Specified by:
getEntryLogMetadatain interfaceEntryLogger- Throws:
IOException
-
extractEntryLogMetadataFromIndex
- Throws:
IOException
-
close
public void close()Shutdown method to gracefully stop entry logger.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceEntryLogger
-
getLedgerDirsManager
-
fileName2LogId
Convert log filename (hex format with suffix) to logId in long. -
logId2HexString
Convert log Id to hex string. -
newCompactionLog
Description copied from interface:EntryLoggerCreate a new entrylog into which compacted entries can be added. There is a 1-1 mapping between logs that are being compacted and the log the compacted entries are written to.- Specified by:
newCompactionLogin interfaceEntryLogger- Throws:
IOException
-
incompleteCompactionLogs
Description copied from interface:EntryLoggerReturn a collection of all the compaction entry logs which have been compacted, but have not been cleaned up.- Specified by:
incompleteCompactionLogsin interfaceEntryLogger
-