Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-481

IndexReader.getCurrentVersion() and isCurrent should use commit lock.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.9
    • Component/s: core/index
    • Labels:
      None
    • Environment:

      Windows platform, all Lucene versions

      Description

      There is a race condition if one machine is checking the current version of an index while another wants to update the segments file in IndexWriter.close().

      java.io.IOException: Cannot delete segments
      at org.apache.lucene.store.FSDirectory.renameFile(FSDirectory.java:213)
      at org.apache.lucene.index.SegmentInfos.write(SegmentInfos.java:90)
      at org.apache.lucene.index.IndexWriter$3.doBody(IndexWriter.java:503)
      at org.apache.lucene.store.Lock$With.run(Lock.java:109)
      at org.apache.lucene.index.IndexWriter.mergeSegments(IndexWriter.java:501)
      at org.apache.lucene.index.IndexWriter.flushRamSegments(IndexWriter.java:440)
      at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:242)

      On the windows platform reading the contents of a file disallows deleting the file.

      I use Lucene to maintain an index of +-700.000 documents, one server adds documents, while other servers handle the searches.
      The search servers poll the index version regularly to check if they have to reopen their IndexSearcher.
      Once in a while (about once every two days on average), IndexWriter.close() fails because it cannot delete the previous segments file, even though it hold the commit lock.
      The reason is probably that search servers are reading the segments file to check the version without using the commit lock.

      1. LUCENE-481.patch
        2 kB
        Luc Vanlerberghe

        Activity

        Hide
        lvl Luc Vanlerberghe added a comment -

        This should fix the problem.

        I didn't use the Lock.With helper class to avoid having to wrap the long or boolean result in a Long or Boolean first.
        The try ... finally block should be at least as clear to read as the Lock.With construct in this case...

        The problem is not limited to Windows Platforms:
        The search servers also threw "java.io.FileNotFoundException: ...\segments (The system cannot find the file specified)" once every few days....

        This is because the new segments data is first written to the file "segments.new" which is then renamed to "segments".
        The javadoc for Directory says renameTo() should be atomic, but the current implementation in FSDirectory isn't.
        If the searcher happens to try to read the segments file in the (admittedly very small) time between the "nu.delete()" and the "old.renameTo(nu)" it gets the FileNotFoundException

        Show
        lvl Luc Vanlerberghe added a comment - This should fix the problem. I didn't use the Lock.With helper class to avoid having to wrap the long or boolean result in a Long or Boolean first. The try ... finally block should be at least as clear to read as the Lock.With construct in this case... The problem is not limited to Windows Platforms: The search servers also threw "java.io.FileNotFoundException: ...\segments (The system cannot find the file specified)" once every few days.... This is because the new segments data is first written to the file "segments.new" which is then renamed to "segments". The javadoc for Directory says renameTo() should be atomic, but the current implementation in FSDirectory isn't. If the searcher happens to try to read the segments file in the (admittedly very small) time between the "nu.delete()" and the "old.renameTo(nu)" it gets the FileNotFoundException
        Hide
        yseeley@gmail.com Yonik Seeley added a comment -

        Thanks Luc, i've commited this!

        Show
        yseeley@gmail.com Yonik Seeley added a comment - Thanks Luc, i've commited this!

          People

          • Assignee:
            Unassigned
            Reporter:
            lvl Luc Vanlerberghe
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development