[jira] Created: (LUCENE-758) IndexReader.isCurrent fails when using two IndexReaders

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (LUCENE-758) IndexReader.isCurrent fails when using two IndexReaders

JIRA jira@apache.org
IndexReader.isCurrent fails when using two IndexReaders
-------------------------------------------------------

                 Key: LUCENE-758
                 URL: http://issues.apache.org/jira/browse/LUCENE-758
             Project: Lucene - Java
          Issue Type: Bug
    Affects Versions: 2.0.1
         Environment: Operating System: other
Platform: other
            Reporter: Bernhard Messer
            Priority: Minor


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();
    }



--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LUCENE-758) IndexReader.isCurrent fails when using two IndexReaders

JIRA jira@apache.org
    [ http://issues.apache.org/jira/browse/LUCENE-758?page=comments#action_12460555 ]
           
Michael McCandless commented on LUCENE-758:
-------------------------------------------

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?

> IndexReader.isCurrent fails when using two IndexReaders
> -------------------------------------------------------
>
>                 Key: LUCENE-758
>                 URL: http://issues.apache.org/jira/browse/LUCENE-758
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.0.1
>         Environment: Operating System: other
> Platform: other
>            Reporter: Bernhard Messer
>            Priority: Minor
>
> 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();
>     }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (LUCENE-758) IndexReader.isCurrent fails when using two IndexReaders

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ http://issues.apache.org/jira/browse/LUCENE-758?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael McCandless resolved LUCENE-758.
---------------------------------------

    Resolution: Invalid

> IndexReader.isCurrent fails when using two IndexReaders
> -------------------------------------------------------
>
>                 Key: LUCENE-758
>                 URL: http://issues.apache.org/jira/browse/LUCENE-758
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.0.1
>         Environment: Operating System: other
> Platform: other
>            Reporter: Bernhard Messer
>            Priority: Minor
>
> 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();
>     }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]