Package org.apache.bookkeeper.client
Class MetadataUpdateLoop
java.lang.Object
org.apache.bookkeeper.client.MetadataUpdateLoop
Mechanism to safely update the metadata of a ledger.
The loop takes the following steps: 1. Check if the metadata needs to be changed. 2. Make a copy of the metadata and modify it. 3. Write the modified copy to zookeeper. 3.1 If the write succeeds, go to 6. 3.2 If the write fails because of a failed compare and swap, go to 4. 4. Read the metadata back from the store 5. Update the local copy of the metadata with the metadata read in 4, go to 1. 6. Update the local copy of the metadata with the metadata which has just been written.
All mutating operations are compare and swap operation. If the compare fails, another iteration of the loop begins.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interface(package private) static interface(package private) static interface -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMetadataUpdateLoop(LedgerManager lm, long ledgerId, Supplier<Versioned<LedgerMetadata>> currentLocalValue, MetadataUpdateLoop.NeedsUpdatePredicate needsTransformation, MetadataUpdateLoop.MetadataTransform transform, MetadataUpdateLoop.LocalValueUpdater updateLocalValue) MetadataUpdateLoop(LedgerManager lm, long ledgerId, Supplier<Versioned<LedgerMetadata>> currentLocalValue, MetadataUpdateLoop.NeedsUpdatePredicate needsTransformation, MetadataUpdateLoop.MetadataTransform transform, MetadataUpdateLoop.LocalValueUpdater updateLocalValue, com.google.common.util.concurrent.RateLimiter throttler) Construct the loop. -
Method Summary
Modifier and TypeMethodDescription(package private) CompletableFuture<Versioned<LedgerMetadata>>run()
-
Field Details
-
LOG
static final org.slf4j.Logger LOG
-
-
Constructor Details
-
MetadataUpdateLoop
MetadataUpdateLoop(LedgerManager lm, long ledgerId, Supplier<Versioned<LedgerMetadata>> currentLocalValue, MetadataUpdateLoop.NeedsUpdatePredicate needsTransformation, MetadataUpdateLoop.MetadataTransform transform, MetadataUpdateLoop.LocalValueUpdater updateLocalValue) -
MetadataUpdateLoop
MetadataUpdateLoop(LedgerManager lm, long ledgerId, Supplier<Versioned<LedgerMetadata>> currentLocalValue, MetadataUpdateLoop.NeedsUpdatePredicate needsTransformation, MetadataUpdateLoop.MetadataTransform transform, MetadataUpdateLoop.LocalValueUpdater updateLocalValue, com.google.common.util.concurrent.RateLimiter throttler) Construct the loop. This takes a set of functions which may be called multiple times during the loop.- Parameters:
lm- the ledger manager used for reading and writing metadataledgerId- the id of the ledger we will be operating oncurrentLocalValue- should return the current local value of the metadataneedsTransformation- should return true, if the metadata needs to be modified. should throw an exception, if this update doesn't make sense.transform- takes a metadata objects, transforms, and returns it, without modifying the originalupdateLocalValue- if the local value matches the first parameter, update it to the second parameter and return true, return false otherwise
-
-
Method Details
-
run
CompletableFuture<Versioned<LedgerMetadata>> run()
-