Class SimpleFSLockFactory


  • public class SimpleFSLockFactory
    extends FSLockFactory

    Implements LockFactory using File.createNewFile().

    NOTE: the javadocs for File.createNewFile() contain a vague yet spooky warning about not using the API for file locking. This warning was added due to this bug, and in fact the only known problem with using this API for locking is that the Lucene write lock may not be released when the JVM exits abnormally.

    When this happens, a LockObtainFailedException is hit when trying to create a writer, in which case you need to explicitly clear the lock file first. You can either manually remove the file, or use the IndexWriter.unlock(Directory) API. But, first be certain that no writer is in fact writing to the index otherwise you can easily corrupt your index.

    If you suspect that this or any other LockFactory is not working properly in your environment, you can easily test it by using VerifyingLockFactory, LockVerifyServer and LockStressTest.

    See Also:
    LockFactory
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleFSLockFactory()
      Create a SimpleFSLockFactory instance, with null (unset) lock directory.
      SimpleFSLockFactory​(java.io.File lockDir)
      Instantiate using the provided directory (as a File instance).
      SimpleFSLockFactory​(java.lang.String lockDirName)
      Instantiate using the provided directory name (String).
    • Constructor Detail

      • SimpleFSLockFactory

        public SimpleFSLockFactory()
        Create a SimpleFSLockFactory instance, with null (unset) lock directory. When you pass this factory to a FSDirectory subclass, the lock directory is automatically set to the directory itself. Be sure to create one instance for each directory your create!
      • SimpleFSLockFactory

        public SimpleFSLockFactory​(java.io.File lockDir)
        Instantiate using the provided directory (as a File instance).
        Parameters:
        lockDir - where lock files should be created.
      • SimpleFSLockFactory

        public SimpleFSLockFactory​(java.lang.String lockDirName)
        Instantiate using the provided directory name (String).
        Parameters:
        lockDirName - where lock files should be created.
    • Method Detail

      • makeLock

        public Lock makeLock​(java.lang.String lockName)
        Description copied from class: LockFactory
        Return a new Lock instance identified by lockName.
        Specified by:
        makeLock in class LockFactory
        Parameters:
        lockName - name of the lock to be created.
      • clearLock

        public void clearLock​(java.lang.String lockName)
                       throws java.io.IOException
        Description copied from class: LockFactory
        Attempt to clear (forcefully unlock and remove) the specified lock. Only call this at a time when you are certain this lock is no longer in use.
        Specified by:
        clearLock in class LockFactory
        Parameters:
        lockName - name of the lock to be cleared.
        Throws:
        java.io.IOException