Interface LockManager<T>

All Superinterfaces:
AutoCloseable

public interface LockManager<T> extends AutoCloseable
Controller for acquiring distributed lock on resources.
  • Method Details

    • readLock

      CompletableFuture<Optional<T>> readLock(String path)
      Read the content of an existing lock. If the lock is already taken, this operation will fail immediately. Warning: because of the distributed nature of the lock, having acquired a lock will never provide a strong guarantee that no one else also think it owns the same resource. The caller will have to deal with these race conditions when using the resource itself (eg. using compareAndSet() or fencing mechanisms).
      Parameters:
      path - the path of the resource on which to acquire the lock
      Returns:
      a future that will track the completion of the operation
      Throws:
      MetadataStoreException.NotFoundException - if the lock is not taken
      MetadataStoreException - if there's a failure in reading the lock
    • acquireLock

      CompletableFuture<ResourceLock<T>> acquireLock(String path, T value)
      Acquire a lock on a shared resource. If the lock is already taken, this operation will fail immediately. Warning: because of the distributed nature of the lock, having acquired a lock will never provide a strong guarantee that no one else also think it owns the same resource. The caller will have to deal with these race conditions when using the resource itself (eg. using compareAndSet() or fencing mechanisms).
      Parameters:
      path - the path of the resource on which to acquire the lock
      value - the value of the lock
      Returns:
      a future that will track the completion of the operation
      Throws:
      MetadataStoreException.LockBusyException - if the lock is already taken
      MetadataStoreException - if there's a failure in acquiring the lock
    • listLocks

      CompletableFuture<List<String>> listLocks(String path)
      List all the locks that are children of a specific path. For example, given locks: /a/b/lock-1 and /a/b/lock-2, the listLocks("/a/b") will return a list of ["lock-1", "lock-2"].
      Parameters:
      path - the prefix path to get the list of locks
      Returns:
      a future that will track the completion of the operation
      Throws:
      MetadataStoreException - if there's a failure in getting the list of locks
    • asyncClose

      CompletableFuture<Void> asyncClose()
      Close the LockManager and release all the locks.
      Returns:
      a future that will track the completion of the operation
      Throws:
      MetadataStoreException - if there's a failure in closing the LockManager