[ 
https://issues.apache.org/jira/browse/LUCENE-2386?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12855277#action_12855277
 ] 

Shai Erera commented on LUCENE-2386:
------------------------------------

Apparently, there are more tests that fail ... lost count but easy fixing. I 
tried writing the following test:

{code}
  public void testNoCommits() throws Exception {
    // Tests that if we don't call commit(), the directory has 0 commits. This 
has
    // changed since LUCENE-2386, where before IW would always commit on a fresh
    // new index.
    Directory dir = new RAMDirectory();
    IndexWriter writer = new IndexWriter(dir, new 
IndexWriterConfig(TEST_VERSION_CURRENT, new 
WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
    assertEquals("expected 0 commits!", 0, IndexReader.listCommits(dir).size());
    // No changes still should generate a commit, because it's a new index.
    writer.close();
    assertEquals("expected 1 commits!", 0, IndexReader.listCommits(dir).size());
  }
{code}

Simple test - validates that no commits are present following a freshly new 
index creation, w/o closing or committing. However, IndexReader.listCommits 
fails w/ the following exception:

{code}
java.io.FileNotFoundException: no segments* file found in 
org.apache.lucene.store.ramdirect...@2d262d26: files: []
        at 
org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:652)
        at 
org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:535)
        at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:323)
        at 
org.apache.lucene.index.DirectoryReader.listCommits(DirectoryReader.java:1033)
        at 
org.apache.lucene.index.DirectoryReader.listCommits(DirectoryReader.java:1023)
        at 
org.apache.lucene.index.IndexReader.listCommits(IndexReader.java:1341)
        at 
org.apache.lucene.index.TestIndexWriter.testNoCommits(TestIndexWriter.java:4966)
       ....
{code}

The failure occurs when SegmentInfos attempts to find segments.gen and fails. 
So I wonder if I should fix DirectoryReader to catch that exception and simply 
return an empty Collection .. or I should fix SegmentInfos at this point -- 
notice the "files: []" at the end - I think that by adding a check to the 
following code (SegmentInfos, line 652) which validates that there were any 
files before throwing the exception, it'll still work properly and safely (i.e. 
to detect a problematic Directory). Will need probably to break away from the 
while loop and I guess fix some other things in upper layers ... therefore I'm 
not sure if I should not simply catch that exception in 
DirectoryReader.listCommits w/ proper documentation and be done w/ it. After 
all, it's not supposed to be called ... ever? or hardly ever?

{code}
          if (gen == -1) {
            // Neither approach found a generation
            throw new FileNotFoundException("no segments* file found in " + 
directory + ": files: " + Arrays.toString(files));
          }
{code}

> IndexWriter commits unnecessarily on fresh Directory
> ----------------------------------------------------
>
>                 Key: LUCENE-2386
>                 URL: https://issues.apache.org/jira/browse/LUCENE-2386
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Index
>            Reporter: Shai Erera
>            Assignee: Shai Erera
>             Fix For: 3.1
>
>         Attachments: LUCENE-2386.patch
>
>
> I've noticed IndexWriter's ctor commits a first commit (empty one) if a fresh 
> Directory is passed, w/ OpenMode.CREATE or CREATE_OR_APPEND. This seems 
> unnecessarily, and kind of brings back an autoCommit mode, in a strange way 
> ... why do we need that commit? Do we really expect people to open an 
> IndexReader on an empty Directory which they just passed to an IW w/ 
> create=true? If they want, they can simply call commit() right away on the IW 
> they created.
> I ran into this when writing a test which committed N times, then compared 
> the number of commits (via IndexReader.listCommits) and was surprised to see 
> N+1 commits.
> Tried to change doCommit to false in IW ctor, but it got IndexFileDeleter 
> jumping on me .. so the change might not be that simple. But I think it's 
> manageable, so I'll try to attack it (and IFD specifically !) back :).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-dev-h...@lucene.apache.org

Reply via email to