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
class FileInfo extends Watchable<LastAddConfirmedUpdateNotification>
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 Modifier and Type Class Description static class
FileInfo.FileInfoDeletedException
-
Field Summary
Fields Modifier and Type Field Description static int
CURRENT_HEADER_VERSION
(package private) int
headerVersion
(package private) byte[]
masterKey
protected java.lang.String
mode
(package private) static int
NO_MASTER_KEY
static int
SIGNATURE
The fingerprint of a ledger index file.(package private) static long
START_OF_DATA
(package private) static int
STATE_FENCED_BIT
(package private) static int
V0
(package private) static int
V1
-
Constructor Summary
Constructors Constructor Description FileInfo(java.io.File lf, byte[] masterKey, int fileInfoVersionToWrite)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
cancelWaitForLastAddConfirmedUpdate(Watcher<LastAddConfirmedUpdateNotification> watcher)
(package private) void
checkOpen(boolean create)
void
close(boolean force)
Close a file info.boolean
delete()
void
flushHeader()
io.netty.buffer.ByteBuf
getExplicitLac()
(package private) java.lang.Long
getLastAddConfirmed()
java.io.File
getLf()
byte[]
getMasterKey()
long
getSizeSinceLastWrite()
boolean
isClosed()
boolean
isDeleted()
boolean
isFenced()
boolean
isSameFile(java.io.File f)
void
moveToNewLocation(java.io.File newFile, long size)
Copies current file contents upto specified size to the target file and deletes the current file.int
read(java.nio.ByteBuffer bb, long position, boolean bestEffort)
void
readHeader()
void
setExplicitLac(io.netty.buffer.ByteBuf lac)
boolean
setFenced()
(package private) long
setLastAddConfirmed(long lac)
long
size()
(package private) boolean
waitForLastAddConfirmedUpdate(long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher)
long
write(java.nio.ByteBuffer[] buffs, long position)
-
Methods inherited from class org.apache.bookkeeper.common.util.Watchable
addWatcher, deleteWatcher, deleteWatchers, notifyWatchers, recycle
-
-
-
-
Field Detail
-
NO_MASTER_KEY
static final int NO_MASTER_KEY
- See Also:
- Constant Field Values
-
STATE_FENCED_BIT
static final int STATE_FENCED_BIT
- See Also:
- Constant Field Values
-
masterKey
byte[] masterKey
-
SIGNATURE
public static final int SIGNATURE
The fingerprint of a ledger index file.
-
V0
static final int V0
- See Also:
- Constant Field Values
-
V1
static final int V1
- See Also:
- Constant Field Values
-
CURRENT_HEADER_VERSION
public static final int CURRENT_HEADER_VERSION
- See Also:
- Constant Field Values
-
START_OF_DATA
static final long START_OF_DATA
- See Also:
- Constant Field Values
-
mode
protected java.lang.String mode
-
headerVersion
int headerVersion
-
-
Method Detail
-
getLastAddConfirmed
java.lang.Long getLastAddConfirmed()
-
setLastAddConfirmed
long setLastAddConfirmed(long lac)
-
waitForLastAddConfirmedUpdate
boolean waitForLastAddConfirmedUpdate(long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher)
-
cancelWaitForLastAddConfirmedUpdate
void cancelWaitForLastAddConfirmedUpdate(Watcher<LastAddConfirmedUpdateNotification> watcher)
-
isClosed
public boolean isClosed()
-
getLf
public java.io.File getLf()
-
getSizeSinceLastWrite
public long getSizeSinceLastWrite()
-
getExplicitLac
public io.netty.buffer.ByteBuf getExplicitLac()
-
setExplicitLac
public void setExplicitLac(io.netty.buffer.ByteBuf lac)
-
readHeader
public void readHeader() throws java.io.IOException
- Throws:
java.io.IOException
-
isDeleted
public boolean isDeleted()
-
checkOpen
void checkOpen(boolean create) throws java.io.IOException
- Throws:
java.io.IOException
-
isFenced
public boolean isFenced() throws java.io.IOException
- Throws:
java.io.IOException
-
setFenced
public boolean setFenced() throws java.io.IOException
- Returns:
- true if set fence succeed, otherwise false when it already fenced or failed to set fenced.
- Throws:
java.io.IOException
-
flushHeader
public void flushHeader() throws java.io.IOException
- Throws:
java.io.IOException
-
size
public long size() throws java.io.IOException
- Throws:
java.io.IOException
-
read
public int read(java.nio.ByteBuffer bb, long position, boolean bestEffort) throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close(boolean force) throws java.io.IOException
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:
java.io.IOException
-
write
public long write(java.nio.ByteBuffer[] buffs, long position) throws java.io.IOException
- Throws:
java.io.IOException
-
moveToNewLocation
public void moveToNewLocation(java.io.File newFile, long size) throws java.io.IOException
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:
java.io.IOException
-
getMasterKey
public byte[] getMasterKey() throws java.io.IOException
- Throws:
java.io.IOException
-
delete
public boolean delete()
-
isSameFile
public boolean isSameFile(java.io.File f)
-
-