Package org.apache.bookkeeper.bookie
Class FileInfo
java.lang.Object
org.apache.bookkeeper.common.util.Watchable<LastAddConfirmedUpdateNotification>
org.apache.bookkeeper.bookie.FileInfo
- All Implemented Interfaces:
Recyclable
- Direct Known Subclasses:
FileInfoBackingCache.CachedFileInfo,ReadOnlyFileInfo
This is the file handle for a ledger's index file that maps entry ids to location.
It is used by LedgerCache.
Ledger index file is made of a header and several fixed-length index pages, which records the offsets of data stored in entry loggers
<header><index pages>Header is formatted as below:
<magic bytes><len of master key><master key>
- magic bytes: 4 bytes, 'BKLE', version: 4 bytes
- len of master key: indicates length of master key. -1 means no master key stored in header.
- master key: master key
- state: bit map to indicate the state, 32 bits.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int(package private) int(package private) byte[]protected String(package private) static final intstatic final intThe fingerprint of a ledger index file.(package private) static final long(package private) static final int(package private) static final int(package private) static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void(package private) voidcheckOpen(boolean create) voidclose(boolean force) Close a file info.booleandelete()voidio.netty.buffer.ByteBuf(package private) LonggetLf()byte[]longbooleanisClosed()booleanbooleanisFenced()booleanisSameFile(File f) voidmoveToNewLocation(File newFile, long size) Copies current file contents upto specified size to the target file and deletes the current file.intread(ByteBuffer bb, long position, boolean bestEffort) voidvoidsetExplicitLac(io.netty.buffer.ByteBuf lac) boolean(package private) longsetLastAddConfirmed(long lac) longsize()(package private) booleanwaitForLastAddConfirmedUpdate(long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) longwrite(ByteBuffer[] buffs, long position) Methods inherited from class org.apache.bookkeeper.common.util.Watchable
addWatcher, deleteWatcher, deleteWatchers, notifyWatchers, recycle
-
Field Details
-
NO_MASTER_KEY
static final int NO_MASTER_KEY- See Also:
-
STATE_FENCED_BIT
static final int STATE_FENCED_BIT- See Also:
-
masterKey
byte[] masterKey -
SIGNATURE
public static final int SIGNATUREThe fingerprint of a ledger index file. -
V0
static final int V0- See Also:
-
V1
static final int V1- See Also:
-
CURRENT_HEADER_VERSION
public static final int CURRENT_HEADER_VERSION- See Also:
-
START_OF_DATA
static final long START_OF_DATA- See Also:
-
mode
-
headerVersion
int headerVersion
-
-
Constructor Details
-
FileInfo
- Throws:
IOException
-
-
Method Details
-
getLastAddConfirmed
Long getLastAddConfirmed() -
setLastAddConfirmed
long setLastAddConfirmed(long lac) -
waitForLastAddConfirmedUpdate
boolean waitForLastAddConfirmedUpdate(long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) -
cancelWaitForLastAddConfirmedUpdate
-
isClosed
public boolean isClosed() -
getLf
-
getSizeSinceLastWrite
public long getSizeSinceLastWrite() -
getExplicitLac
public io.netty.buffer.ByteBuf getExplicitLac() -
setExplicitLac
public void setExplicitLac(io.netty.buffer.ByteBuf lac) -
readHeader
- Throws:
IOException
-
isDeleted
public boolean isDeleted() -
checkOpen
- Throws:
IOException
-
isFenced
- Throws:
IOException
-
setFenced
- Returns:
- true if set fence succeed, otherwise false when it already fenced or failed to set fenced.
- Throws:
IOException
-
flushHeader
- Throws:
IOException
-
size
- Throws:
IOException
-
read
- Throws:
IOException
-
close
Close a file info. Generally, force should be set to true. If set to false metadata will not be flushed and accessing metadata before restart and recovery will be unsafe (since reloading from the index file will cause metadata to be lost). Setting force=false helps avoid expensive file create during shutdown with many dirty ledgers, and is safe because ledger metadata will be recovered before being accessed again.- Parameters:
force- if set to true, the index is forced to create before closed, if set to false, the index is not forced to create.- Throws:
IOException
-
write
- Throws:
IOException
-
moveToNewLocation
Copies current file contents upto specified size to the target file and deletes the current file. If size not known then pass size as Long.MAX_VALUE to copy complete file.- Throws:
IOException
-
getMasterKey
- Throws:
IOException
-
delete
public boolean delete() -
isSameFile
-