Package org.apache.bookkeeper.bookie
Class BookieImpl
- java.lang.Object
-
- org.apache.bookkeeper.bookie.BookieImpl
-
- All Implemented Interfaces:
Bookie
- Direct Known Subclasses:
ReadOnlyBookie
public class BookieImpl extends java.lang.Object implements Bookie
Implements a bookie.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classBookieImpl.NopWriteCallback-
Nested classes/interfaces inherited from interface org.apache.bookkeeper.bookie.Bookie
Bookie.NoEntryException, Bookie.NoLedgerException
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.function.Supplier<BookieServiceInfo>bookieServiceInfoProvider(package private) ServerConfigurationconf(package private) LedgerDirsMonitordirsMonitor(package private) booleanentryLogPerLedgerEnabled(package private) HandleFactoryhandles(package private) java.util.List<java.io.File>journalDirectories(package private) java.util.List<Journal>journals(package private) LedgerStorageledgerStorage(package private) java.util.concurrent.locks.ReentrantLocklockstatic longMETAENTRY_ID_FENCE_KEYstatic longMETAENTRY_ID_FORCE_LEDGER(package private) static longMETAENTRY_ID_LEDGER_EXPLICITLACstatic longMETAENTRY_ID_LEDGER_KEY(package private) RegistrationManagerregistrationManager(package private) java.util.concurrent.atomic.AtomicBooleanshutdownTriggeredprotected StateManagerstateManager(package private) StatsLoggerstatsLogger(package private) SyncThreadsyncThread
-
Constructor Summary
Constructors Constructor Description BookieImpl(ServerConfiguration conf, RegistrationManager registrationManager, LedgerStorage storage, DiskChecker diskChecker, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, java.util.function.Supplier<BookieServiceInfo> bookieServiceInfoProvider)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEntry(io.netty.buffer.ByteBuf entry, boolean ackBeforeSync, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx, byte[] masterKey)Add entry to a ledger.voidcancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher)static voidcheckDirectoryStructure(java.io.File dir)io.netty.buffer.ByteBufcreateExplicitLACEntry(long ledgerId, io.netty.buffer.ByteBuf explicitLac)io.netty.buffer.ByteBufcreateMasterKeyEntry(long ledgerId, byte[] masterKey)java.util.concurrent.CompletableFuture<java.lang.Boolean>fenceLedger(long ledgerId, byte[] masterKey)Fences a ledger.voidforceLedger(long ledgerId, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx)Force sync given 'ledgerId' entries on the journal to the disk.static booleanformat(ServerConfiguration conf, boolean isInteractive, boolean force)Format the bookie server data.io.netty.buffer.ByteBufAllocatorgetAllocator()static BookieSocketAddressgetBookieAddress(ServerConfiguration conf)Return the configured address of the bookie.static BookieIdgetBookieId(ServerConfiguration conf)static java.io.File[]getCurrentDirectories(java.io.File[] dirs)static java.io.FilegetCurrentDirectory(java.io.File dir)intgetExitCode()Returns exit code - cause of failure.io.netty.buffer.ByteBufgetExplicitLac(long ledgerId)(package private) LedgerDirsManagergetIndexDirsManager()java.util.List<Journal>getJournals()LedgerDirsManagergetLedgerDirsManager()(package private) LedgerDescriptorgetLedgerForEntry(io.netty.buffer.ByteBuf entry, byte[] masterKey)Retrieve the ledger descriptor for the ledger which entry should be added to.LedgerStoragegetLedgerStorage()java.util.PrimitiveIterator.OfLonggetListOfEntriesOfLedger(long ledgerId)BookieStateManagergetStateManager()longgetTotalDiskSpace()longgetTotalFreeSpace()(package private) StateManagerinitializeStateManager()booleanisAlive()booleanisAvailableForHighPriorityWrites()Check whether Bookie is available for high priority writes.booleanisReadOnly()booleanisRunning()voidjoin()static LedgerStoragemountLedgerStorageOffline(ServerConfiguration conf, LedgerStorage ledgerStorage)Initialize LedgerStorage instance without checkpointing for use within the shell and other RO users.static BookieImplnewBookieImpl(ServerConfiguration conf, RegistrationManager registrationManager, LedgerStorage storage, DiskChecker diskChecker, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, java.util.function.Supplier<BookieServiceInfo> bookieServiceInfoProvider)io.netty.buffer.ByteBufreadEntry(long ledgerId, long entryId)(package private) voidreadJournal()longreadLastAddConfirmed(long ledgerId)voidrecoveryAddEntry(io.netty.buffer.ByteBuf entry, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx, byte[] masterKey)Add entry to a ledger, even if the ledger has previous been fenced.voidrun()voidsetExplicitLac(io.netty.buffer.ByteBuf entry, BookkeeperInternalCallbacks.WriteCallback writeCallback, java.lang.Object ctx, byte[] masterKey)intshutdown()(package private) intshutdown(int exitCode)voidstart()(package private) voidtriggerBookieShutdown(int exitCode)booleanwaitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher)
-
-
-
Field Detail
-
journalDirectories
final java.util.List<java.io.File> journalDirectories
-
conf
final ServerConfiguration conf
-
syncThread
final SyncThread syncThread
-
ledgerStorage
final LedgerStorage ledgerStorage
-
registrationManager
final RegistrationManager registrationManager
-
journals
final java.util.List<Journal> journals
-
handles
final HandleFactory handles
-
entryLogPerLedgerEnabled
final boolean entryLogPerLedgerEnabled
-
METAENTRY_ID_LEDGER_KEY
public static final long METAENTRY_ID_LEDGER_KEY
- See Also:
- Constant Field Values
-
METAENTRY_ID_FENCE_KEY
public static final long METAENTRY_ID_FENCE_KEY
- See Also:
- Constant Field Values
-
METAENTRY_ID_FORCE_LEDGER
public static final long METAENTRY_ID_FORCE_LEDGER
- See Also:
- Constant Field Values
-
METAENTRY_ID_LEDGER_EXPLICITLAC
static final long METAENTRY_ID_LEDGER_EXPLICITLAC
- See Also:
- Constant Field Values
-
bookieServiceInfoProvider
protected final java.util.function.Supplier<BookieServiceInfo> bookieServiceInfoProvider
-
dirsMonitor
LedgerDirsMonitor dirsMonitor
-
stateManager
protected StateManager stateManager
-
statsLogger
final StatsLogger statsLogger
-
shutdownTriggered
java.util.concurrent.atomic.AtomicBoolean shutdownTriggered
-
lock
java.util.concurrent.locks.ReentrantLock lock
-
-
Constructor Detail
-
BookieImpl
public BookieImpl(ServerConfiguration conf, RegistrationManager registrationManager, LedgerStorage storage, DiskChecker diskChecker, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, java.util.function.Supplier<BookieServiceInfo> bookieServiceInfoProvider) throws java.io.IOException, java.lang.InterruptedException, BookieException
- Throws:
java.io.IOExceptionjava.lang.InterruptedExceptionBookieException
-
-
Method Detail
-
checkDirectoryStructure
public static void checkDirectoryStructure(java.io.File dir) throws java.io.IOException- Throws:
java.io.IOException
-
getBookieId
public static BookieId getBookieId(ServerConfiguration conf) throws java.net.UnknownHostException
- Throws:
java.net.UnknownHostException
-
getBookieAddress
public static BookieSocketAddress getBookieAddress(ServerConfiguration conf) throws java.net.UnknownHostException
Return the configured address of the bookie.- Throws:
java.net.UnknownHostException
-
getLedgerDirsManager
public LedgerDirsManager getLedgerDirsManager()
-
getIndexDirsManager
LedgerDirsManager getIndexDirsManager()
-
getTotalDiskSpace
public long getTotalDiskSpace() throws java.io.IOException- Specified by:
getTotalDiskSpacein interfaceBookie- Throws:
java.io.IOException
-
getTotalFreeSpace
public long getTotalFreeSpace() throws java.io.IOException- Specified by:
getTotalFreeSpacein interfaceBookie- Throws:
java.io.IOException
-
getCurrentDirectory
public static java.io.File getCurrentDirectory(java.io.File dir)
-
getCurrentDirectories
public static java.io.File[] getCurrentDirectories(java.io.File[] dirs)
-
mountLedgerStorageOffline
public static LedgerStorage mountLedgerStorageOffline(ServerConfiguration conf, LedgerStorage ledgerStorage) throws java.io.IOException
Initialize LedgerStorage instance without checkpointing for use within the shell and other RO users. ledgerStorage must not have already been initialized.The caller is responsible for disposing of the ledgerStorage object.
- Parameters:
conf- Bookie config.ledgerStorage- Instance to initialize.- Returns:
- Passed ledgerStorage instance
- Throws:
java.io.IOException
-
newBookieImpl
public static BookieImpl newBookieImpl(ServerConfiguration conf, RegistrationManager registrationManager, LedgerStorage storage, DiskChecker diskChecker, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, java.util.function.Supplier<BookieServiceInfo> bookieServiceInfoProvider) throws java.io.IOException, java.lang.InterruptedException, BookieException
- Throws:
java.io.IOExceptionjava.lang.InterruptedExceptionBookieException
-
initializeStateManager
StateManager initializeStateManager() throws java.io.IOException
- Throws:
java.io.IOException
-
readJournal
void readJournal() throws java.io.IOException, BookieException- Throws:
java.io.IOExceptionBookieException
-
join
public void join() throws java.lang.InterruptedException
-
isAlive
public boolean isAlive()
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnlyin interfaceBookie
-
isAvailableForHighPriorityWrites
public boolean isAvailableForHighPriorityWrites()
Check whether Bookie is available for high priority writes.- Specified by:
isAvailableForHighPriorityWritesin interfaceBookie- Returns:
- true if the bookie is able to take high priority writes.
-
run
public void run()
-
triggerBookieShutdown
void triggerBookieShutdown(int exitCode)
-
shutdown
int shutdown(int exitCode)
-
getLedgerForEntry
LedgerDescriptor getLedgerForEntry(io.netty.buffer.ByteBuf entry, byte[] masterKey) throws java.io.IOException, BookieException
Retrieve the ledger descriptor for the ledger which entry should be added to. The LedgerDescriptor returned from this method should be eventually freed with #putHandle().- Throws:
BookieException- if masterKey does not match the master key of the ledgerjava.io.IOException
-
createMasterKeyEntry
public io.netty.buffer.ByteBuf createMasterKeyEntry(long ledgerId, byte[] masterKey)
-
recoveryAddEntry
public void recoveryAddEntry(io.netty.buffer.ByteBuf entry, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx, byte[] masterKey) throws java.io.IOException, BookieException, java.lang.InterruptedExceptionAdd entry to a ledger, even if the ledger has previous been fenced. This should only happen in bookie recovery or ledger recovery cases, where entries are being replicates so that they exist on a quorum of bookies. The corresponding client side call for this is not exposed to users.- Specified by:
recoveryAddEntryin interfaceBookie- Throws:
java.io.IOExceptionBookieExceptionjava.lang.InterruptedException
-
createExplicitLACEntry
public io.netty.buffer.ByteBuf createExplicitLACEntry(long ledgerId, io.netty.buffer.ByteBuf explicitLac)
-
setExplicitLac
public void setExplicitLac(io.netty.buffer.ByteBuf entry, BookkeeperInternalCallbacks.WriteCallback writeCallback, java.lang.Object ctx, byte[] masterKey) throws java.io.IOException, java.lang.InterruptedException, BookieException- Specified by:
setExplicitLacin interfaceBookie- Throws:
java.io.IOExceptionjava.lang.InterruptedExceptionBookieException
-
getExplicitLac
public io.netty.buffer.ByteBuf getExplicitLac(long ledgerId) throws java.io.IOException, Bookie.NoLedgerException, BookieException- Specified by:
getExplicitLacin interfaceBookie- Throws:
java.io.IOExceptionBookie.NoLedgerExceptionBookieException
-
forceLedger
public void forceLedger(long ledgerId, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx)Force sync given 'ledgerId' entries on the journal to the disk. It works like a regular addEntry with ackBeforeSync=false. This is useful for ledgers with DEFERRED_SYNC write flag.- Specified by:
forceLedgerin interfaceBookie
-
addEntry
public void addEntry(io.netty.buffer.ByteBuf entry, boolean ackBeforeSync, BookkeeperInternalCallbacks.WriteCallback cb, java.lang.Object ctx, byte[] masterKey) throws java.io.IOException, BookieException, java.lang.InterruptedExceptionAdd entry to a ledger.- Specified by:
addEntryin interfaceBookie- Throws:
java.io.IOExceptionBookieExceptionjava.lang.InterruptedException
-
fenceLedger
public java.util.concurrent.CompletableFuture<java.lang.Boolean> fenceLedger(long ledgerId, byte[] masterKey) throws java.io.IOException, BookieExceptionFences a ledger. From this point on, clients will be unable to write to this ledger. Only recoveryAddEntry will be able to add entries to the ledger. This method is idempotent. Once a ledger is fenced, it can never be unfenced. Fencing a fenced ledger has no effect.- Specified by:
fenceLedgerin interfaceBookie- Returns:
- Throws:
java.io.IOExceptionBookieException
-
readEntry
public io.netty.buffer.ByteBuf readEntry(long ledgerId, long entryId) throws java.io.IOException, Bookie.NoLedgerException, BookieException- Specified by:
readEntryin interfaceBookie- Throws:
java.io.IOExceptionBookie.NoLedgerExceptionBookieException
-
readLastAddConfirmed
public long readLastAddConfirmed(long ledgerId) throws java.io.IOException, BookieException- Specified by:
readLastAddConfirmedin interfaceBookie- Throws:
java.io.IOExceptionBookieException
-
waitForLastAddConfirmedUpdate
public boolean waitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) throws java.io.IOException- Specified by:
waitForLastAddConfirmedUpdatein interfaceBookie- Throws:
java.io.IOException
-
cancelWaitForLastAddConfirmedUpdate
public void cancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) throws java.io.IOException- Specified by:
cancelWaitForLastAddConfirmedUpdatein interfaceBookie- Throws:
java.io.IOException
-
getLedgerStorage
public LedgerStorage getLedgerStorage()
- Specified by:
getLedgerStoragein interfaceBookie
-
getStateManager
public BookieStateManager getStateManager()
- Specified by:
getStateManagerin interfaceBookie
-
getAllocator
public io.netty.buffer.ByteBufAllocator getAllocator()
-
format
public static boolean format(ServerConfiguration conf, boolean isInteractive, boolean force)
Format the bookie server data.- Parameters:
conf- ServerConfigurationisInteractive- Whether format should ask prompt for confirmation if old data exists or not.force- If non interactive and force is true, then old data will be removed without confirm prompt.- Returns:
- Returns true if the format is success else returns false
-
getExitCode
public int getExitCode()
Returns exit code - cause of failure.- Specified by:
getExitCodein interfaceBookie- Returns:
ExitCode
-
getListOfEntriesOfLedger
public java.util.PrimitiveIterator.OfLong getListOfEntriesOfLedger(long ledgerId) throws java.io.IOException, Bookie.NoLedgerException- Specified by:
getListOfEntriesOfLedgerin interfaceBookie- Throws:
java.io.IOExceptionBookie.NoLedgerException
-
getJournals
public java.util.List<Journal> getJournals()
-
-