SimpleFSLockFactory (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.store, class: SimpleFSLockFactory

Package org.apache.lucene.store

# Class SimpleFSLockFactory

java.lang.Object
org.apache.lucene.store.LockFactory
org.apache.lucene.store.FSLockFactory
org.apache.lucene.store.SimpleFSLockFactory

public final class SimpleFSLockFactory extends FSLockFactory
Implements `LockFactory` using `Files.createFile(java.nio.file.Path, java.nio.file.attribute.FileAttribute<?>...)`.

The main downside with using this API for locking is that the Lucene write lock may not be released when the JVM exits abnormally.

When this happens, an `LockObtainFailedException` is hit when trying to create a writer, in which case you may need to explicitly clear the lock file first by manually removing the file. But, first be certain that no writer is in fact writing to the index otherwise you can easily corrupt your index.

Special care needs to be taken if you change the locking implementation: First be certain that no writer is in fact writing to the index otherwise you can easily corrupt your index. Be sure to do the LockFactory change all Lucene instances and clean up all leftover lock files before starting the new configuration for the first time. Different implementations can not work together!

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`.

This is a singleton, you have to use `INSTANCE`.

See Also:
  - `LockFactory`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final SimpleFSLockFactory`
  `INSTANCE`
  Singleton instance

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected Lock`
  `obtainFSLock(FSDirectory dir, String lockName)`
  Implement this method to obtain a lock for a FSDirectory instance.

  ### Methods inherited from class org.apache.lucene.store.FSLockFactory

  `getDefault, obtainLock`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### INSTANCE

    public static final SimpleFSLockFactory INSTANCE
    Singleton instance

- ## Method Details

  - ### obtainFSLock

    protected Lock obtainFSLock(FSDirectory dir, String lockName) throws IOException
    Description copied from class: `FSLockFactory`
    Implement this method to obtain a lock for a FSDirectory instance.
    Specified by:
      `obtainFSLock` in class `FSLockFactory`
    Throws:
      `IOException` - if the lock could not be obtained.