Package org.apache.bookkeeper.bookie
Class BookieImpl
java.lang.Object
org.apache.bookkeeper.bookie.BookieImpl
- All Implemented Interfaces:
Bookie
- Direct Known Subclasses:
ReadOnlyBookie
Implements a bookie.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.apache.bookkeeper.bookie.Bookie
Bookie.NoEntryException, Bookie.NoLedgerException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Supplier<BookieServiceInfo>(package private) final ServerConfiguration(package private) LedgerDirsMonitor(package private) final boolean(package private) final HandleFactory(package private) final LedgerStorage(package private) ReentrantLockstatic final longstatic final long(package private) static final longstatic final long(package private) final RegistrationManager(package private) AtomicBooleanprotected StateManager(package private) final StatsLogger(package private) final SyncThread -
Constructor Summary
ConstructorsConstructorDescriptionBookieImpl(ServerConfiguration conf, RegistrationManager registrationManager, LedgerStorage storage, DiskChecker diskChecker, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, Supplier<BookieServiceInfo> bookieServiceInfoProvider) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEntry(io.netty.buffer.ByteBuf entry, boolean ackBeforeSync, BookkeeperInternalCallbacks.WriteCallback cb, Object ctx, byte[] masterKey) Add entry to a ledger.voidcancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) static voidio.netty.buffer.ByteBufcreateExplicitLACEntry(long ledgerId, io.netty.buffer.ByteBuf explicitLac) io.netty.buffer.ByteBufcreateMasterKeyEntry(long ledgerId, byte[] masterKey) fenceLedger(long ledgerId, byte[] masterKey) Fences a ledger.voidforceLedger(long ledgerId, BookkeeperInternalCallbacks.WriteCallback cb, 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.ByteBufAllocatorstatic BookieSocketAddressReturn the configured address of the bookie.static BookieIdstatic File[]getCurrentDirectories(File[] dirs) static FilegetCurrentDirectory(File dir) intReturns exit code - cause of failure.io.netty.buffer.ByteBufgetExplicitLac(long ledgerId) (package private) LedgerDirsManager(package private) LedgerDescriptorgetLedgerForEntry(io.netty.buffer.ByteBuf entry, byte[] masterKey) Retrieve the ledger descriptor for the ledger which entry should be added to.getListOfEntriesOfLedger(long ledgerId) longlong(package private) StateManagerbooleanisAlive()booleanCheck whether Bookie is available for high priority writes.booleanbooleanvoidjoin()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, Supplier<BookieServiceInfo> bookieServiceInfoProvider) io.netty.buffer.ByteBufreadEntry(long ledgerId, long entryId) (package private) voidlongreadLastAddConfirmed(long ledgerId) voidrecoveryAddEntry(io.netty.buffer.ByteBuf entry, BookkeeperInternalCallbacks.WriteCallback cb, 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, 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 Details
-
journalDirectories
-
conf
-
syncThread
-
ledgerStorage
-
registrationManager
-
journals
-
handles
-
entryLogPerLedgerEnabled
final boolean entryLogPerLedgerEnabled -
METAENTRY_ID_LEDGER_KEY
public static final long METAENTRY_ID_LEDGER_KEY- See Also:
-
METAENTRY_ID_FENCE_KEY
public static final long METAENTRY_ID_FENCE_KEY- See Also:
-
METAENTRY_ID_FORCE_LEDGER
public static final long METAENTRY_ID_FORCE_LEDGER- See Also:
-
METAENTRY_ID_LEDGER_EXPLICITLAC
static final long METAENTRY_ID_LEDGER_EXPLICITLAC- See Also:
-
bookieServiceInfoProvider
-
dirsMonitor
LedgerDirsMonitor dirsMonitor -
stateManager
-
statsLogger
-
shutdownTriggered
AtomicBoolean shutdownTriggered -
lock
ReentrantLock lock
-
-
Constructor Details
-
BookieImpl
public BookieImpl(ServerConfiguration conf, RegistrationManager registrationManager, LedgerStorage storage, DiskChecker diskChecker, LedgerDirsManager ledgerDirsManager, LedgerDirsManager indexDirsManager, StatsLogger statsLogger, io.netty.buffer.ByteBufAllocator allocator, Supplier<BookieServiceInfo> bookieServiceInfoProvider) throws IOException, InterruptedException, BookieException
-
-
Method Details
-
checkDirectoryStructure
- Throws:
IOException
-
getBookieId
- Throws:
UnknownHostException
-
getBookieAddress
public static BookieSocketAddress getBookieAddress(ServerConfiguration conf) throws UnknownHostException Return the configured address of the bookie.- Throws:
UnknownHostException
-
getLedgerDirsManager
-
getIndexDirsManager
LedgerDirsManager getIndexDirsManager() -
getTotalDiskSpace
- Specified by:
getTotalDiskSpacein interfaceBookie- Throws:
IOException
-
getTotalFreeSpace
- Specified by:
getTotalFreeSpacein interfaceBookie- Throws:
IOException
-
getCurrentDirectory
-
getCurrentDirectories
-
mountLedgerStorageOffline
public static LedgerStorage mountLedgerStorageOffline(ServerConfiguration conf, LedgerStorage ledgerStorage) throws 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:
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, Supplier<BookieServiceInfo> bookieServiceInfoProvider) throws IOException, InterruptedException, BookieException -
initializeStateManager
- Throws:
IOException
-
readJournal
- Throws:
IOExceptionBookieException
-
start
public void start() -
join
- Specified by:
joinin interfaceBookie- Throws:
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.
-
isRunning
public boolean isRunning() -
run
public void run() -
triggerBookieShutdown
void triggerBookieShutdown(int exitCode) -
shutdown
public int shutdown() -
shutdown
int shutdown(int exitCode) -
getLedgerForEntry
LedgerDescriptor getLedgerForEntry(io.netty.buffer.ByteBuf entry, byte[] masterKey) throws 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 ledgerIOException
-
createMasterKeyEntry
public io.netty.buffer.ByteBuf createMasterKeyEntry(long ledgerId, byte[] masterKey) -
recoveryAddEntry
public void recoveryAddEntry(io.netty.buffer.ByteBuf entry, BookkeeperInternalCallbacks.WriteCallback cb, Object ctx, byte[] masterKey) throws IOException, BookieException, InterruptedException Add 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:
IOExceptionBookieExceptionInterruptedException
-
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, Object ctx, byte[] masterKey) throws IOException, InterruptedException, BookieException - Specified by:
setExplicitLacin interfaceBookie- Throws:
IOExceptionInterruptedExceptionBookieException
-
getExplicitLac
public io.netty.buffer.ByteBuf getExplicitLac(long ledgerId) throws IOException, Bookie.NoLedgerException, BookieException - Specified by:
getExplicitLacin interfaceBookie- Throws:
IOExceptionBookie.NoLedgerExceptionBookieException
-
forceLedger
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, Object ctx, byte[] masterKey) throws IOException, BookieException, InterruptedException Add entry to a ledger.- Specified by:
addEntryin interfaceBookie- Throws:
IOExceptionBookieExceptionInterruptedException
-
fenceLedger
public CompletableFuture<Boolean> fenceLedger(long ledgerId, byte[] masterKey) throws IOException, BookieException Fences 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:
IOExceptionBookieException
-
readEntry
public io.netty.buffer.ByteBuf readEntry(long ledgerId, long entryId) throws IOException, Bookie.NoLedgerException, BookieException - Specified by:
readEntryin interfaceBookie- Throws:
IOExceptionBookie.NoLedgerExceptionBookieException
-
readLastAddConfirmed
- Specified by:
readLastAddConfirmedin interfaceBookie- Throws:
IOExceptionBookieException
-
waitForLastAddConfirmedUpdate
public boolean waitForLastAddConfirmedUpdate(long ledgerId, long previousLAC, Watcher<LastAddConfirmedUpdateNotification> watcher) throws IOException - Specified by:
waitForLastAddConfirmedUpdatein interfaceBookie- Throws:
IOException
-
cancelWaitForLastAddConfirmedUpdate
public void cancelWaitForLastAddConfirmedUpdate(long ledgerId, Watcher<LastAddConfirmedUpdateNotification> watcher) throws IOException - Specified by:
cancelWaitForLastAddConfirmedUpdatein interfaceBookie- Throws:
IOException
-
getLedgerStorage
- Specified by:
getLedgerStoragein interfaceBookie
-
getStateManager
- Specified by:
getStateManagerin interfaceBookie
-
getAllocator
public io.netty.buffer.ByteBufAllocator getAllocator() -
format
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 PrimitiveIterator.OfLong getListOfEntriesOfLedger(long ledgerId) throws IOException, Bookie.NoLedgerException - Specified by:
getListOfEntriesOfLedgerin interfaceBookie- Throws:
IOExceptionBookie.NoLedgerException
-
getJournals
-