Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-8069

Clustered Locks Embedded Mode

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Done
    • Major
    • 9.2.0.Beta1, 9.2.0.Final
    • None
    • None
    • None

    Description

      This issue will only supply an implementation for a Node Level Ownership and Non rentrant lock

      ClusteredLockManager and configuration

      package org.infinispan.lock.api;
      
      public class ClusteredLockManager {
         boolean defineLock(String name);
      
         ClusteredLock get(String name);
      
         boolean isDefined(String name);
      
         CompletableFuture<Boolean> remove(String name);
      
         CompletableFuture<Void> reset(String name);
      }
      
      
      public class ClusteredLockConfiguration {
         private final OwnershipLevel ownershipLevel; // default NODE
         private final boolean rentrant; // default false
      }
      
      public enum OwnershipLevel {
         NODE, // Node can lock if it owns the lock without blocking, only the owner node can unlock
         INSTANCE, // Instance can lock multiple times if it owns the lock without blocking, only the owner instance can unlock
      }
      
      

      ClusteredLock defineLock(String name, LockConfiguration configuration)

      Defines a lock with the specific name and LockConfiguration. It does not overwrite existing configurations.

      Returns true if successfully defined or false if the lock is already defined or any other failure. If silentFailover is false, then InfinispanLockException will be raised.

      ClusteredLock get(String name)

      Get’s a InfinipanLock by it’s name and throws InfinispanLockException if the lock is not not defined. User must call defineLock before this method.

      boolean isDefined(String name)

      True if the lock exists, false if it doesn’t

      CompletableFuture<Boolean> remove(String name)

      Removes a Lock from the system. Returns true when it was removed, false when the lock does not exist. If any other Runtime problems appear, InfinispanLockException will be raised withe the reason. As Locks are not removed automatically, so this has to be done programatically when the Lock is no longer needed. Otherwise, OutOfMemoryException could happen.

      Remove must be executed when the lock is locked, because running that without exclusive access should result in an exception. Internally, the implementation should contain generation number so that attempts to acquire a lock of a removed generation will result it exceptions in the other callers, too.

      CompletableFuture<Void> reset(String name)

      Resets the lock to its initial state. If any parties are currently waiting at the lock, they will return with failure on the CompletableFuture

      ClusteredLock

      When a cluster node holding a Lock dies, this lock is released and available for the others.

      public interface ClusteredLock {
      
         CompletableFuture<Void>	lock();
      
         CompletableFuture<Boolean>	tryLock();
      
         CompletableFuture<Boolean>	tryLock(long time, TimeUnit unit);
      
         CompletableFuture<Void>	unlock();
      }
      

      CompletableFuture<Void> lock();

      CompletableFuture is completed successfully when the lock is acquired When a lock is aquired by a client, it will be automatically released after the maxLeaseTime specified. RenewalLeaseTime is the interval time is the time a client can aquire a lock consecutively User should set the timeouts to non-positive value The initial embedded implementation does not have to support positive values

      CompletableFuture<Boolean> tryLock();

      Acquires the lock only if it is free at the time of invocation. Acquires the lock if it is available and returns with the value true. If the lock is not available then this method with the value false.

      CompletableFuture<Boolean> tryLock(long time, TimeUnit unit);

      Acquires the lock if it is free within the given waiting time. If the lock is available this method returns with the value true.

      Parameters: time - the maximum time to wait for the lock unit - the time unit of the time argument Returns: true if the lock was acquired and false if the waiting time elapsed before the lock was acquired

      CompletableFuture fails with InfinispanLockException in case of error (InterruptedException, or any other non checked exceptions)

      CompletableFuture<Boolean> unlock();

      If the lock is rentrant (Node or Instance), only the instance or node holding the lock will be able to unlock, otherwise, anybody can unlock and it will behave as a Semaphore with one permit. True answer will say that the operation was succesul and the lock has been released, false the lock has not been relased

      Attachments

        Issue Links

          Activity

            People

              karestig@redhat.com Katia Aresti
              karestig@redhat.com Katia Aresti
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: