lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shai Erera (JIRA)" <>
Subject [jira] Commented: (LUCENE-2386) IndexWriter commits unnecessarily on fresh Directory
Date Fri, 09 Apr 2010 05:31:51 GMT


Shai Erera commented on LUCENE-2386:

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

  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.
    assertEquals("expected 1 commits!", 0, IndexReader.listCommits(dir).size());

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} no segments* file found in
files: []
	at org.apache.lucene.index.SegmentInfos$
	at org.apache.lucene.index.SegmentInfos$
	at org.apache.lucene.index.DirectoryReader.listCommits(
	at org.apache.lucene.index.DirectoryReader.listCommits(
	at org.apache.lucene.index.IndexReader.listCommits(
	at org.apache.lucene.index.TestIndexWriter.testNoCommits(

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?

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

> IndexWriter commits unnecessarily on fresh Directory
> ----------------------------------------------------
>                 Key: LUCENE-2386
>                 URL:
>             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:
For additional commands, e-mail:

View raw message