Package org.apache.bookkeeper.client
Class BookKeeperAdmin
java.lang.Object
org.apache.bookkeeper.client.BookKeeperAdmin
- All Implemented Interfaces:
AutoCloseable
Admin client for BookKeeper clusters.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class(package private) classstatic classThis is the class for getting the replication result.(package private) static class -
Constructor Summary
ConstructorsConstructorDescriptionBookKeeperAdmin(String zkServers) Constructor that takes in a ZooKeeper servers connect string so we know how to connect to ZooKeeper to retrieve information about the BookKeeper cluster.BookKeeperAdmin(BookKeeper bkc, ClientConfiguration conf) BookKeeperAdmin(BookKeeper bkc, StatsLogger statsLogger, ClientConfiguration conf) Constructor that takes in a BookKeeper instance .Constructor that takes in a configuration object so we know how to connect to ZooKeeper to retrieve information about the BookKeeper cluster. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareEntriesOfLedgerStoredInTheBookie(long ledgerId, BookieId bookieAddress, LedgerMetadata ledgerMetadata) static booleanareEntriesOfLedgerStoredInTheBookie(long ledgerId, BookieId bookieAddress, LedgerManager ledgerManager) voidasyncGetLedgersContainBookies(Set<BookieId> bookies, BookkeeperInternalCallbacks.GenericCallback<SortedMap<Long, LedgerMetadata>> callback) asyncGetListOfEntriesOfLedger(BookieId address, long ledgerId) Makes async request for getting list of entries of ledger from a bookie and returns Future for the result.voidasyncOpenLedger(long lId, AsyncCallback.OpenCallback cb, Object ctx) Open a ledger as an administrator.voidasyncOpenLedgerNoRecovery(long lId, AsyncCallback.OpenCallback cb, Object ctx) Open a ledger as an administrator without recovering the ledger.voidasyncRecoverBookieData(long lid, Set<BookieId> bookieSrc, boolean dryrun, boolean skipOpenLedgers, AsyncCallback.RecoverCallback callback, Object context) Recover a specific ledger.voidasyncRecoverBookieData(Set<BookieId> bookieSrc, boolean dryrun, boolean skipOpenLedgers, boolean skipUnrecoverableLedgers, AsyncCallback.RecoverCallback cb, Object context) voidasyncRecoverBookieData(Set<BookieId> bookieSrc, AsyncCallback.RecoverCallback cb, Object context) voidasyncRecoverBookieData(BookieId bookieSrc, AsyncCallback.RecoverCallback cb, Object context) Async method to rebuild and recover the ledger fragments data that was stored on the source bookie.voidclose()Gracefully release resources that this client uses.voiddecommissionBookie(BookieId bookieAddress) Triggers AuditTask by resetting lostBookieRecoveryDelay and then make sure the ledgers stored in the given decommissioning bookie are properly replicated and they are not underreplicated because of the given bookie.static booleanformat(ServerConfiguration conf, boolean isInteractive, boolean force) Format the BookKeeper metadata in zookeeper.(package private) static StringformatEnsemble(List<BookieId> ensemble, Set<BookieId> bookiesSrc, char marker) Get a list of all bookies including the not available ones.Get a list of the available bookies.getBookieServiceInfo(BookieId bookiedId) getConf()getLedgersContainBookies(Set<BookieId> bookies) intReturns the current LostBookieRecoveryDelay value (in seconds) in Zookeeper.Get a list of readonly bookies synchronously.static booleanInitializes bookie, by making sure that the journalDir, ledgerDirs and indexDirs are empty and there is no registered Bookie with this BookieId.static booleanInitializes new cluster by creating required znodes for the cluster.isEnsembleAdheringToPlacementPolicy(List<BookieId> ensembleBookiesList, int writeQuorumSize, int ackQuorumSize) returns boolean value specifying if the ensemble of the segment is adhering to the ensemble placement policy for the given writeQuorumSize and ackQuorumSize.This method returns an iterable object for the list of ledger identifiers of the ledgers currently available.static BookKeeperAdminstatic booleannukeExistingCluster(ServerConfiguration conf, String ledgersRootPath, String instanceId, boolean force) Nukes existing cluster metadata.openLedger(long lId) Open a ledger as an administrator.openLedgerNoRecovery(long lId) Open a ledger as an administrator without recovering the ledger.readEntries(long ledgerId, long firstEntry, long lastEntry) Read entries from a ledger synchronously.voidrecoverBookieData(long lid, Set<BookieId> bookiesSrc, boolean dryrun, boolean skipOpenLedgers) voidrecoverBookieData(Set<BookieId> bookiesSrc) voidrecoverBookieData(Set<BookieId> bookiesSrc, boolean dryrun, boolean skipOpenLedgers) voidrecoverBookieData(Set<BookieId> bookiesSrc, boolean dryrun, boolean skipOpenLedgers, boolean skipUnrecoverableLedgers) voidrecoverBookieData(BookieId bookieSrc) Synchronous method to rebuild and recover the ledger fragments data that was stored on the source bookie.replaceNotAdheringPlacementPolicyBookie(List<BookieId> ensembleBookiesList, int writeQuorumSize, int ackQuorumSize) voidreplicateLedgerFragment(LedgerHandle lh, LedgerFragment ledgerFragment, BiConsumer<Long, Long> onReadEntryFailureCallback) Replicate the Ledger fragment to target Bookie passed.voidsetLostBookieRecoveryDelay(int lostBookieRecoveryDelay) Setter for LostBookieRecoveryDelay value (in seconds) in Zookeeper.voidTrigger AuditTask by resetting lostBookieRecoveryDelay to its current value.voidNotify when the available list of read only bookies changes.voidNotify when the available list of bookies changes.
-
Constructor Details
-
BookKeeperAdmin
Constructor that takes in a ZooKeeper servers connect string so we know how to connect to ZooKeeper to retrieve information about the BookKeeper cluster. We need this before we can do any type of admin operations on the BookKeeper cluster.- Parameters:
zkServers- Comma separated list of hostname:port pairs for the ZooKeeper servers cluster.- Throws:
IOException- throws this exception if there is an error instantiating the ZooKeeper client.InterruptedException- Throws this exception if there is an error instantiating the BookKeeper client.BKException- Throws this exception if there is an error instantiating the BookKeeper client.
-
BookKeeperAdmin
public BookKeeperAdmin(ClientConfiguration conf) throws IOException, InterruptedException, BKException Constructor that takes in a configuration object so we know how to connect to ZooKeeper to retrieve information about the BookKeeper cluster. We need this before we can do any type of admin operations on the BookKeeper cluster.- Parameters:
conf- Client Configuration Object- Throws:
IOException- throws this exception if there is an error instantiating the ZooKeeper client.InterruptedException- Throws this exception if there is an error instantiating the BookKeeper client.BKException- Throws this exception if there is an error instantiating the BookKeeper client.
-
BookKeeperAdmin
Constructor that takes in a BookKeeper instance . This will be useful, when user already has bk instance ready.- Parameters:
bkc- - bookkeeper instancestatsLogger- - stats logger
-
BookKeeperAdmin
-
BookKeeperAdmin
-
-
Method Details
-
newBookKeeperAdmin
public static BookKeeperAdmin newBookKeeperAdmin(ClientConfiguration conf) throws IOException, InterruptedException, BKException -
getConf
-
close
Gracefully release resources that this client uses.- Specified by:
closein interfaceAutoCloseable- Throws:
InterruptedException- if there is an error shutting down the clients that this class uses.BKException
-
getAvailableBookies
Get a list of the available bookies.- Returns:
- a collection of bookie addresses
- Throws:
BKException
-
getAllBookies
Get a list of all bookies including the not available ones.- Returns:
- a collection of bookie addresses
- Throws:
BKException
-
getBookieAddressResolver
-
getBookieServiceInfo
- Throws:
BKException
-
getReadOnlyBookies
Get a list of readonly bookies synchronously.- Returns:
- a collection of bookie addresses
- Throws:
BKException- if there are issues trying to read the list.
-
watchWritableBookiesChanged
public void watchWritableBookiesChanged(RegistrationClient.RegistrationListener listener) throws BKException Notify when the available list of bookies changes. Once registered, the listener will be notified when the list of available bookies changes.- Parameters:
listener- the listener to notify- Throws:
BKException
-
watchReadOnlyBookiesChanged
public void watchReadOnlyBookiesChanged(RegistrationClient.RegistrationListener listener) throws BKException Notify when the available list of read only bookies changes. Once registered, the listener will be notified when the list of available bookies changes.- Parameters:
listener- the listener to notify- Throws:
BKException
-
asyncOpenLedger
Open a ledger as an administrator. This means that no digest password checks are done. Otherwise, the call is identical to BookKeeper#asyncOpenLedger- Parameters:
lId- ledger identifiercb- Callback which will receive a LedgerHandle objectctx- optional context object, to be passwd to the callback (can be null)- See Also:
-
openLedger
Open a ledger as an administrator. This means that no digest password checks are done. Otherwise, the call is identical to BookKeeper#openLedger- Parameters:
lId- - ledger identifier- Throws:
InterruptedExceptionBKException- See Also:
-
asyncOpenLedgerNoRecovery
Open a ledger as an administrator without recovering the ledger. This means that no digest password checks are done. Otherwise, the call is identical to BookKeeper#asyncOpenLedgerNoRecovery- Parameters:
lId- ledger identifiercb- Callback which will receive a LedgerHandle objectctx- optional context object, to be passwd to the callback (can be null)- See Also:
-
openLedgerNoRecovery
Open a ledger as an administrator without recovering the ledger. This means that no digest password checks are done. Otherwise, the call is identical to BookKeeper#openLedgerNoRecovery- Parameters:
lId- ledger identifier- Throws:
InterruptedExceptionBKException- See Also:
-
readEntries
public Iterable<LedgerEntry> readEntries(long ledgerId, long firstEntry, long lastEntry) throws InterruptedException, BKException Read entries from a ledger synchronously. If the lastEntry is -1, it will read all the entries in the ledger from the firstEntry.- Parameters:
ledgerId-firstEntry-lastEntry-- Returns:
- Throws:
InterruptedExceptionBKException
-
getLedgersContainBookies
public SortedMap<Long,LedgerMetadata> getLedgersContainBookies(Set<BookieId> bookies) throws InterruptedException, BKException - Throws:
InterruptedExceptionBKException
-
asyncGetLedgersContainBookies
public void asyncGetLedgersContainBookies(Set<BookieId> bookies, BookkeeperInternalCallbacks.GenericCallback<SortedMap<Long, LedgerMetadata>> callback) -
recoverBookieData
Synchronous method to rebuild and recover the ledger fragments data that was stored on the source bookie. That bookie could have failed completely and now the ledger data that was stored on it is under replicated. An optional destination bookie server could be given if we want to copy all of the ledger fragments data on the failed source bookie to it. Otherwise, we will just randomly distribute the ledger fragments to the active set of bookies, perhaps based on load. All ZooKeeper ledger metadata will be updated to point to the new bookie(s) that contain the replicated ledger fragments.- Parameters:
bookieSrc- Source bookie that had a failure. We want to replicate the ledger fragments that were stored there.- Throws:
InterruptedExceptionBKException
-
recoverBookieData
- Throws:
InterruptedExceptionBKException
-
recoverBookieData
public void recoverBookieData(Set<BookieId> bookiesSrc, boolean dryrun, boolean skipOpenLedgers) throws InterruptedException, BKException - Throws:
InterruptedExceptionBKException
-
recoverBookieData
public void recoverBookieData(Set<BookieId> bookiesSrc, boolean dryrun, boolean skipOpenLedgers, boolean skipUnrecoverableLedgers) throws InterruptedException, BKException - Throws:
InterruptedExceptionBKException
-
recoverBookieData
public void recoverBookieData(long lid, Set<BookieId> bookiesSrc, boolean dryrun, boolean skipOpenLedgers) throws InterruptedException, BKException - Throws:
InterruptedExceptionBKException
-
asyncRecoverBookieData
public void asyncRecoverBookieData(BookieId bookieSrc, AsyncCallback.RecoverCallback cb, Object context) Async method to rebuild and recover the ledger fragments data that was stored on the source bookie. That bookie could have failed completely and now the ledger data that was stored on it is under replicated. An optional destination bookie server could be given if we want to copy all of the ledger fragments data on the failed source bookie to it. Otherwise, we will just randomly distribute the ledger fragments to the active set of bookies, perhaps based on load. All ZooKeeper ledger metadata will be updated to point to the new bookie(s) that contain the replicated ledger fragments.- Parameters:
bookieSrc- Source bookie that had a failure. We want to replicate the ledger fragments that were stored there.cb- RecoverCallback to invoke once all of the data on the dead bookie has been recovered and replicated.context- Context for the RecoverCallback to call.
-
asyncRecoverBookieData
public void asyncRecoverBookieData(Set<BookieId> bookieSrc, AsyncCallback.RecoverCallback cb, Object context) -
asyncRecoverBookieData
public void asyncRecoverBookieData(Set<BookieId> bookieSrc, boolean dryrun, boolean skipOpenLedgers, boolean skipUnrecoverableLedgers, AsyncCallback.RecoverCallback cb, Object context) -
asyncRecoverBookieData
public void asyncRecoverBookieData(long lid, Set<BookieId> bookieSrc, boolean dryrun, boolean skipOpenLedgers, AsyncCallback.RecoverCallback callback, Object context) Recover a specific ledger.- Parameters:
lid- ledger to recoverbookieSrc- Source bookies that had a failure. We want to replicate the ledger fragments that were stored there.dryrun- dryrun the recover procedure.skipOpenLedgers- Skip recovering open ledgers.callback- RecoverCallback to invoke once all of the data on the dead bookie has been recovered and replicated.context- Context for the RecoverCallback to call.
-
formatEnsemble
-
replicateLedgerFragment
public void replicateLedgerFragment(LedgerHandle lh, LedgerFragment ledgerFragment, BiConsumer<Long, Long> onReadEntryFailureCallback) throws InterruptedException, BKExceptionReplicate the Ledger fragment to target Bookie passed.- Parameters:
lh- - ledgerHandleledgerFragment- - LedgerFragment to replicate- Throws:
InterruptedExceptionBKException
-
format
public static boolean format(ServerConfiguration conf, boolean isInteractive, boolean force) throws Exception Format the BookKeeper metadata in zookeeper.- Parameters:
isInteractive- 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 prompt.- Returns:
- Returns true if format succeeds else false.
- Throws:
Exception
-
initNewCluster
Initializes new cluster by creating required znodes for the cluster. If ledgersrootpath is already existing then it will error out.- Parameters:
conf-- Returns:
- Throws:
Exception
-
nukeExistingCluster
public static boolean nukeExistingCluster(ServerConfiguration conf, String ledgersRootPath, String instanceId, boolean force) throws Exception Nukes existing cluster metadata. But it does only if the provided ledgersRootPath matches with configuration's zkLedgersRootPath and provided instanceid matches with the cluster metadata. If force is mentioned then instanceid will not be validated.- Parameters:
conf-ledgersRootPath-instanceId-force-- Returns:
- Throws:
Exception
-
initBookie
Initializes bookie, by making sure that the journalDir, ledgerDirs and indexDirs are empty and there is no registered Bookie with this BookieId.- Parameters:
conf-- Returns:
- Throws:
Exception
-
listLedgers
This method returns an iterable object for the list of ledger identifiers of the ledgers currently available.- Returns:
- an iterable object for the list of ledger identifiers
- Throws:
IOException- if the list of ledger identifiers cannot be read from the metadata store
-
getLedgerMetadata
- Returns:
- the metadata for the passed ledger handle
-
setLostBookieRecoveryDelay
public void setLostBookieRecoveryDelay(int lostBookieRecoveryDelay) throws ReplicationException.CompatibilityException, org.apache.zookeeper.KeeperException, InterruptedException, ReplicationException.UnavailableException Setter for LostBookieRecoveryDelay value (in seconds) in Zookeeper.- Parameters:
lostBookieRecoveryDelay- lostBookieRecoveryDelay value (in seconds) to set- Throws:
ReplicationException.CompatibilityExceptionorg.apache.zookeeper.KeeperExceptionInterruptedExceptionReplicationException.UnavailableException
-
getLostBookieRecoveryDelay
public int getLostBookieRecoveryDelay() throws ReplicationException.CompatibilityException, org.apache.zookeeper.KeeperException, InterruptedException, ReplicationException.UnavailableExceptionReturns the current LostBookieRecoveryDelay value (in seconds) in Zookeeper.- Returns:
- current lostBookieRecoveryDelay value (in seconds)
- Throws:
ReplicationException.CompatibilityExceptionorg.apache.zookeeper.KeeperExceptionInterruptedExceptionReplicationException.UnavailableException
-
triggerAudit
public void triggerAudit() throws ReplicationException.CompatibilityException, org.apache.zookeeper.KeeperException, InterruptedException, ReplicationException.UnavailableException, IOExceptionTrigger AuditTask by resetting lostBookieRecoveryDelay to its current value. If Autorecovery is not enabled or if there is no Auditor then this method will throw UnavailableException.- Throws:
ReplicationException.CompatibilityExceptionorg.apache.zookeeper.KeeperExceptionInterruptedExceptionReplicationException.UnavailableExceptionIOException
-
decommissionBookie
public void decommissionBookie(BookieId bookieAddress) throws ReplicationException.CompatibilityException, ReplicationException.UnavailableException, org.apache.zookeeper.KeeperException, InterruptedException, IOException, ReplicationException.BKAuditException, TimeoutException, BKException Triggers AuditTask by resetting lostBookieRecoveryDelay and then make sure the ledgers stored in the given decommissioning bookie are properly replicated and they are not underreplicated because of the given bookie. This method waits until there are no underreplicatedledgers because of this bookie. If the given Bookie is not shutdown yet, then it will throw BKIllegalOpException.- Parameters:
bookieAddress- address of the decommissioning bookie- Throws:
ReplicationException.CompatibilityExceptionReplicationException.UnavailableExceptionorg.apache.zookeeper.KeeperExceptionInterruptedExceptionIOExceptionReplicationException.BKAuditExceptionTimeoutExceptionBKException
-
areEntriesOfLedgerStoredInTheBookie
public static boolean areEntriesOfLedgerStoredInTheBookie(long ledgerId, BookieId bookieAddress, LedgerManager ledgerManager) -
areEntriesOfLedgerStoredInTheBookie
public static boolean areEntriesOfLedgerStoredInTheBookie(long ledgerId, BookieId bookieAddress, LedgerMetadata ledgerMetadata) -
isEnsembleAdheringToPlacementPolicy
public EnsemblePlacementPolicy.PlacementPolicyAdherence isEnsembleAdheringToPlacementPolicy(List<BookieId> ensembleBookiesList, int writeQuorumSize, int ackQuorumSize) returns boolean value specifying if the ensemble of the segment is adhering to the ensemble placement policy for the given writeQuorumSize and ackQuorumSize.- Parameters:
ensembleBookiesList- ensemble of the segmentwriteQuorumSize- writeQuorumSize of the ledgerackQuorumSize- ackQuorumSize of the ledger- Returns:
- true if the ledger is adhering to EnsemblePlacementPolicy
-
replaceNotAdheringPlacementPolicyBookie
-
asyncGetListOfEntriesOfLedger
public CompletableFuture<AvailabilityOfEntriesOfLedger> asyncGetListOfEntriesOfLedger(BookieId address, long ledgerId) Makes async request for getting list of entries of ledger from a bookie and returns Future for the result.- Parameters:
address- BookieId of the bookieledgerId- ledgerId- Returns:
- returns Future
-
getCurrentAuditor
- Throws:
IOExceptionInterruptedException
-