org.apache.lucene.store

## Class NativeFSLockFactory

- java.lang.Object
- - org.apache.lucene.store.LockFactory
  - - org.apache.lucene.store.FSLockFactory
    - - org.apache.lucene.store.NativeFSLockFactory

-     public final class NativeFSLockFactory
      extends FSLockFactory

  Implements `LockFactory` using native OS file locks. Note that because this LockFactory relies on java.nio.* APIs for locking, any problems with those APIs will cause locking to fail. Specifically, on certain NFS environments the java.nio.* locks will fail (the lock can incorrectly be double acquired) whereas `SimpleFSLockFactory` worked perfectly in those same environments. For NFS based access to an index, it's recommended that you try `SimpleFSLockFactory` first and work around the one limitation that a lock file could be left when the JVM exits abnormally.

  The primary benefit of `NativeFSLockFactory` is that locks (not the lock file itself) will be properly removed (by the OS) if the JVM has an abnormal exit.

  Note that, unlike `SimpleFSLockFactory`, the existence of leftover lock files in the filesystem is fine because the OS will free the locks held against these files even though the files still remain. Lucene will never actively remove the lock files, so although you see them, the index may not be locked.

  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 on 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 and Description
    --- | ---
    `static NativeFSLockFactory` | `INSTANCE` Singleton instance

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and 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 Detail

    - #### INSTANCE

          public static final NativeFSLockFactory INSTANCE

      Singleton instance

  - ### Method Detail

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

Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.