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

IndexReader.isCurrent fails when using two IndexReaders

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Invalid
    • Affects Version/s: 2.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: other

    • Lucene Fields:
      New

      Description

      there is a problem in IndexReader.isCurrent() if using two reader instances where one of them is based on a RAMDirectory. If there is an index and we open two IndexReaders where one is based on a FSDirectory and the other is based on a RAMDirectory, the IndexReader using the RAMDirectory does not recognize when the underlaying index has changed. The method IndexReader.isCurrent() always returns true. The testcase below shows the problem.

      I did not find an ideal solution to solve the problem. I think the best way would be to change the IndexReader.isCurrent() implementation from:
      public boolean isCurrent() throws IOException

      { return SegmentInfos.readCurrentVersion(directory) == segmentInfos.getVersion(); }

      to something like:
      public boolean isCurrent() throws IOException

      { return directory.readCurrentVersion() == segmentInfos.getVersion(); }

      As far as i can see this would work for FS- and RAMDirectory. But then the implementing Directory classes have to know about "segment" files and there formating details.
      What do others think ?

      /**

      • additional testcase for IndexReaderTest to show the problem when using two different Readers
        */
        public void testIsCurrentWithCombined() throws Exception { String tempDir = System.getProperty("tempDir"); if (tempDir == null) throw new IOException("tempDir undefined, cannot run test"); File indexDir = new File(tempDir, "lucenetestiscurrent"); Directory fsStore = FSDirectory.getDirectory(indexDir, true); IndexWriter writer = new IndexWriter(fsStore, new SimpleAnalyzer(), true); addDocumentWithFields(writer); writer.close(); IndexReader reader1 = IndexReader.open(fsStore); IndexReader reader2 = IndexReader.open(new RAMDirectory(fsStore)); assertTrue(reader1.isCurrent()); assertTrue(reader2.isCurrent()); reader1.deleteDocument(0); reader1.close(); // BUG: reader based on the RAMDirectory does not recognize the index change. assertFalse(reader2.isCurrent()); reader2.close(); }

        Activity

        Hide
        mikemccand Michael McCandless added a comment -

        Thank you for the full test case showing the issue!

        However, I believe this is by design. When you init a RAMDirectory off a current Directory, it makes a full copy of that original Directory and from then on the original & the copy are totally independent.

        So it's not expected that changes to the original Directory would be reflected in the copy?

        Show
        mikemccand Michael McCandless added a comment - Thank you for the full test case showing the issue! However, I believe this is by design. When you init a RAMDirectory off a current Directory, it makes a full copy of that original Directory and from then on the original & the copy are totally independent. So it's not expected that changes to the original Directory would be reflected in the copy?

          People

          • Assignee:
            Unassigned
            Reporter:
            bmesser Bernhard Messer
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development