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

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

Took a look at IndexFileDeleter, and located to offending code segment which is 
responsible for the IndexCorruptException:
{code}
    if (currentCommitPoint == null) {
      // We did not in fact see the segments_N file
      // corresponding to the segmentInfos that was passed
      // in.  Yet, it must exist, because our caller holds
      // the write lock.  This can happen when the directory
      // listing was stale (eg when index accessed via NFS
      // client with stale directory listing cache).  So we
      // try now to explicitly open this commit point:
      SegmentInfos sis = new SegmentInfos();
      try {
        sis.read(directory, segmentInfos.getCurrentSegmentFileName(), codecs);
      } catch (IOException e) {
        throw new CorruptIndexException("failed to locate current segments_N 
file");
      }
{code}

Looks like this code protects against a real problem, which was raised on the 
list a couple of times already - stale NFS cache. So I'm reluctant to remove 
that check ... thought I still think we should differentiate between a newly 
created index on a fresh Directory, to a stale NFS problem. Maybe we can pass a 
boolean isNew or something like that to the ctor, and if it's a new index and 
the last commit point is missing, IFD will not throw the exception, but 
silently ignore that? So the code would become something like this:
{code}
    if (currentCommitPoint == null && !isNew) {
       ....
    }
{code}

Does this make sense, or am I missing something?

> 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
>
>
> 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