Interface EntryLogger
-
- All Superinterfaces:
java.lang.AutoCloseable
- All Known Implementing Classes:
DefaultEntryLogger
,DirectEntryLogger
,ReadOnlyDefaultEntryLogger
public interface EntryLogger extends java.lang.AutoCloseable
Entry logger. Sequentially writes entries for a large number of ledgers to a small number of log files, to avoid many random writes. When an entry is added, a location is returned, which consists of the ID of the log into which the entry was added, and the offset of that entry within the log. The location is a long, with 32 bits each for the log ID and the offset. This naturally limits the offset and thus the size of the log to Integer.MAX_VALUE.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
LOG_FILE_SUFFIX
static long
UNASSIGNED_LEDGERID
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description long
addEntry(long ledgerId, io.netty.buffer.ByteBuf buf)
Add an entry for ledger ```ledgerId``` to the entrylog.void
close()
void
flush()
Flush any outstanding writes to disk.default EntryLogMetadata
getEntryLogMetadata(long entryLogId)
Retrieve metadata for the given entrylog ID.EntryLogMetadata
getEntryLogMetadata(long entryLogId, AbstractLogCompactor.Throttler throttler)
Retrieve metadata for the given entrylog ID.java.util.Collection<java.lang.Long>
getFlushedLogIds()
Get the log ids for the set of logs which have been completely flushed to disk.java.util.Collection<CompactionEntryLog>
incompleteCompactionLogs()
Return a collection of all the compaction entry logs which have been compacted, but have not been cleaned up.boolean
logExists(long logId)
Check whether an entrylog with the given ID exists.CompactionEntryLog
newCompactionLog(long logToCompact)
Create a new entrylog into which compacted entries can be added.io.netty.buffer.ByteBuf
readEntry(long entryLocation)
Read an entry from an entrylog location.io.netty.buffer.ByteBuf
readEntry(long ledgerId, long entryId, long entryLocation)
Read an entry from an entrylog location, and verify that is matches the expected ledger and entry ID.boolean
removeEntryLog(long entryLogId)
Delete the entrylog with the given ID.void
scanEntryLog(long entryLogId, EntryLogScanner scanner)
Scan the given entrylog, returning all entries contained therein.
-
-
-
Field Detail
-
UNASSIGNED_LEDGERID
static final long UNASSIGNED_LEDGERID
- See Also:
- Constant Field Values
-
LOG_FILE_SUFFIX
static final java.lang.String LOG_FILE_SUFFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
addEntry
long addEntry(long ledgerId, io.netty.buffer.ByteBuf buf) throws java.io.IOException
Add an entry for ledger ```ledgerId``` to the entrylog.- Parameters:
ledgerId
- the ledger for which the entry is being addedbuf
- 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:
java.io.IOException
-
readEntry
io.netty.buffer.ByteBuf readEntry(long entryLocation) throws java.io.IOException, Bookie.NoEntryException
Read an entry from an entrylog location.- Parameters:
entryLocation
- the location from which to read the entry- Returns:
- the entry
- Throws:
java.io.IOException
Bookie.NoEntryException
-
readEntry
io.netty.buffer.ByteBuf readEntry(long ledgerId, long entryId, long entryLocation) throws java.io.IOException, Bookie.NoEntryException
Read an entry from an entrylog location, and verify that is matches the expected ledger and entry ID.- Parameters:
ledgerId
- the ledgerID to matchentryId
- the entryID to matchentryLocation
- the location from which to read the entry- Returns:
- the entry
- Throws:
java.io.IOException
Bookie.NoEntryException
-
flush
void flush() throws java.io.IOException
Flush any outstanding writes to disk.- Throws:
java.io.IOException
-
close
void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.io.IOException
-
newCompactionLog
CompactionEntryLog newCompactionLog(long logToCompact) throws java.io.IOException
Create 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.- Throws:
java.io.IOException
-
incompleteCompactionLogs
java.util.Collection<CompactionEntryLog> incompleteCompactionLogs()
Return a collection of all the compaction entry logs which have been compacted, but have not been cleaned up.
-
getFlushedLogIds
java.util.Collection<java.lang.Long> getFlushedLogIds()
Get 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.
-
scanEntryLog
void scanEntryLog(long entryLogId, EntryLogScanner scanner) throws java.io.IOException
Scan the given entrylog, returning all entries contained therein.- Throws:
java.io.IOException
-
getEntryLogMetadata
default EntryLogMetadata getEntryLogMetadata(long entryLogId) throws java.io.IOException
Retrieve 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.- Throws:
java.io.IOException
-
getEntryLogMetadata
EntryLogMetadata getEntryLogMetadata(long entryLogId, AbstractLogCompactor.Throttler throttler) throws java.io.IOException
Retrieve 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.- Throws:
java.io.IOException
-
logExists
boolean logExists(long logId)
Check whether an entrylog with the given ID exists.
-
removeEntryLog
boolean removeEntryLog(long entryLogId)
Delete the entrylog with the given ID.- Returns:
- false if the entrylog doesn't exist.
-
-