Interface SegmentReadLocker

  • All Known Implementing Classes:
    DistributedSegmentReadLocker, LocalLockMergingSegmentReadLocker, NoopSegmentReadLocker

    public interface SegmentReadLocker

    SegmentReadLocker implementations have to make sure that segments are not deleted while they are being used by an IndexReader.

    When an InfinispanIndexInput is opened on a file which is split in smaller chunks, acquireReadLock(String) is invoked; then the deleteOrReleaseReadLock(String) is invoked when the stream is closed.

    The same deleteOrReleaseReadLock(String) is invoked when a file is deleted, so if this invocation is not balancing a lock acquire this implementation must delete all segment chunks and the associated metadata.

    Note that if you can use and tune the LogByteSizeMergePolicy you could avoid the need for readlocks by setting a maximum segment size to equal the chunk size used by the InfinispanDirectory; readlocks will be skipped automatically when not needed, so it's advisable to still configure an appropriate SegmentReadLocker for the cases you might want to tune the chunk size.

    Since:
    4.1
    Author:
    Sanne Grinovero
    • Method Detail

      • deleteOrReleaseReadLock

        void deleteOrReleaseReadLock​(String fileName)
        It will release a previously acquired readLock, or if no readLock was acquired it will mark the file to be deleted as soon as all pending locks are releases. If it's invoked on a file without pending locks the file is deleted.
        Parameters:
        fileName - of the file to release or delete
        See Also:
        Directory.deleteFile(String)
      • acquireReadLock

        boolean acquireReadLock​(String filename)
        Acquires a readlock, in order to prevent other invocations to deleteOrReleaseReadLock(String) from deleting the file.
        Parameters:
        filename - of the file to acquire the lock at
        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:
        Directory.openInput(java.lang.String, org.apache.lucene.store.IOContext)