Package org.apache.bookkeeper.client
Class MetadataUpdateLoop
- java.lang.Object
-
- org.apache.bookkeeper.client.MetadataUpdateLoop
-
class MetadataUpdateLoop extends java.lang.Object
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 Classes Modifier and Type Class Description (package private) static interface
MetadataUpdateLoop.LocalValueUpdater
(package private) static interface
MetadataUpdateLoop.MetadataTransform
(package private) static interface
MetadataUpdateLoop.NeedsUpdatePredicate
-
Field Summary
Fields Modifier and Type Field Description (package private) static org.slf4j.Logger
LOG
-
Constructor Summary
Constructors Constructor Description MetadataUpdateLoop(LedgerManager lm, long ledgerId, java.util.function.Supplier<Versioned<LedgerMetadata>> currentLocalValue, MetadataUpdateLoop.NeedsUpdatePredicate needsTransformation, MetadataUpdateLoop.MetadataTransform transform, MetadataUpdateLoop.LocalValueUpdater updateLocalValue)
MetadataUpdateLoop(LedgerManager lm, long ledgerId, java.util.function.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>>
run()
-
-
-
Constructor Detail
-
MetadataUpdateLoop
MetadataUpdateLoop(LedgerManager lm, long ledgerId, java.util.function.Supplier<Versioned<LedgerMetadata>> currentLocalValue, MetadataUpdateLoop.NeedsUpdatePredicate needsTransformation, MetadataUpdateLoop.MetadataTransform transform, MetadataUpdateLoop.LocalValueUpdater updateLocalValue)
-
MetadataUpdateLoop
MetadataUpdateLoop(LedgerManager lm, long ledgerId, java.util.function.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 Detail
-
run
java.util.concurrent.CompletableFuture<Versioned<LedgerMetadata>> run()
-
-