Class DistributedSegmentReadLocker

  • All Implemented Interfaces:
    SegmentReadLocker

    public class DistributedSegmentReadLocker
    extends Object
    implements SegmentReadLocker

    DistributedSegmentReadLocker stores reference counters in the cache to keep track of the number of clients still needing to be able to read a segment. It makes extensive usage of Infinispan's atomic operations.

    Locks stored this way are not optimally performing as it might spin on remote invocations, and might fail to cleanup some garbage in case a node is disconnected without having released the readlock.

    Since:
    4.1
    Author:
    Sanne Grinovero
    • Constructor Detail

      • DistributedSegmentReadLocker

        public DistributedSegmentReadLocker​(Cache<Object,​Integer> locksCache,
                                            Cache<?,​?> chunksCache,
                                            Cache<?,​?> metadataCache,
                                            String indexName,
                                            int affinitySegmentId)
      • DistributedSegmentReadLocker

        public DistributedSegmentReadLocker​(Cache<Object,​Integer> locksCache,
                                            Cache<?,​?> chunksCache,
                                            Cache<?,​?> metadataCache,
                                            String indexName,
                                            int affinitySegmentId,
                                            boolean forceSynchronousDeletes)
      • DistributedSegmentReadLocker

        public DistributedSegmentReadLocker​(Cache<?,​?> cache,
                                            String indexName,
                                            int affinitySegmentId)
    • Method Detail

      • deleteOrReleaseReadLock

        public void deleteOrReleaseReadLock​(String filename)
        Deletes or releases a read-lock for the specified filename, so that if it was marked as deleted and no other InfinispanIndexInput instances are reading from it, then it will be effectively deleted.
        Specified by:
        deleteOrReleaseReadLock in interface SegmentReadLocker
        Parameters:
        filename - of the file to release or delete
        See Also:
        acquireReadLock(String), Directory.deleteFile(String)
      • acquireReadLock

        public boolean acquireReadLock​(String filename)
        Acquires a readlock on all chunks for this file, to make sure chunks are not deleted while iterating on the group. This is needed to avoid an eager lock on all elements. If no value is found in the cache, a disambiguation procedure is needed: not value might mean both "existing, no readlocks, no deletions in progress", but also "not existent file". The first possibility is coded as no value to avoid storing readlocks in a permanent store, which would unnecessarily slow down and provide unwanted long term storage of the lock; so the value is treated as one if not found, but obviously it's also not found for non-existent or concurrently deleted files.
        Specified by:
        acquireReadLock in interface SegmentReadLocker
        Parameters:
        filename - the name of the "file" for which a readlock is requested
        Returns:
        true if the lock was acquired, false if the implementation detects the file does not exist, or that it's being deleted by some other thread.
        See Also:
        deleteOrReleaseReadLock(String)