Class 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.

    • Field Detail

      • LOG

        static final org.slf4j.Logger LOG
    • Constructor Detail

      • MetadataUpdateLoop

        MetadataUpdateLoop​(org.apache.bookkeeper.meta.LedgerManager lm,
                           long ledgerId,
                           java.util.function.Supplier<org.apache.bookkeeper.versioning.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 metadata
        ledgerId - the id of the ledger we will be operating on
        currentLocalValue - should return the current local value of the metadata
        needsTransformation - 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 original
        updateLocalValue - 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<org.apache.bookkeeper.versioning.Versioned<LedgerMetadata>> run()