lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael McCandless (JIRA)" <>
Subject [jira] Commented: (LUCENE-743) IndexReader.reopen()
Date Sat, 20 Oct 2007 10:45:50 GMT


Michael McCandless commented on LUCENE-743:

If you do:
IndexReader reader1 =;  
IndexReader multiReader1 = new MultiReader(new IndexReader[] {reader1,});

then today multiReader1.close() also closes reader1. That's why I consciously omitted reader1.close().

Ahh, I missed that MultiReader is allowed to close all readers that
were passed into it, when it is closed.  OK, let's leave
reader1.close() out of the example.

It's somewhat "aggressive" of MultiReader/ParallelReader to do that?
If you go and use those same sub-readers in other MultiReaders then
they closing of the first MultiReader will then break the other ones?

I think we are forced to keep this semantics, for backwards
compatibility.  But I don't really think MultiReader/ParallelReader
should actually be this aggressive.  Maybe in the future we can add
ctors for MultiReader/ParallelReader that accept a "doClose" boolean
to turn this off.

Anyway, it's simple to preserve this semantics with reference
counting.  It just means that IndexReader / MultiReader do not incref
the readers they receive, and, when they are done with those readers,
they must call their close(), not decref.  Ie they "borrow the
reference" that was passed in, rather than incref'ing their own
reference, to the child readers.

With that change, plus the change below, your example works fine.

Consequently, if you do
IndexReader reader1 =;  
IndexReader multiReader1 = new MultiReader(new IndexReader[] {reader1,});
IndexReader multiReader2 = new MultiReader(new IndexReader[] {reader1,});
then multiReader2 is not usable anymore, because multiReader1.close() closes reader1. But
that can be explicitly avoided by the user because it's known that multiReader1 and multiReader2
share the same reader.

This is why I don't like the semantics we have today -- I don't think
it's right that the multiReader1.close() breaks multiReader2.

Now, with the reopen() code:
IndexReader reader1 =;  // optimized index, reader1 is a SegmentReader
IndexReader multiReader1 = new MultiReader(new IndexReader[] {reader1,});
... // modify index2
IndexReader multiReader2 = multiReader1.reopen();  
// only index2 changed, so multiReader2 uses reader1 and has to increment the refcount of
The user gets a new reader instance from multiReader.reopen(), but can't tell which of the
subreaders has been reopened and which are shared. That's why multiReader1.close() should
not close reader1 in this case and we need refcounting in order to make this work.

Both of these cases are easy to fix with reference counting: we just
have to change ensureOpen() to assert that RC > 0 instead of
closed==false.  Ie, a reader may still be used as long as its RC is
still non-zero.

> IndexReader.reopen()
> --------------------
>                 Key: LUCENE-743
>                 URL:
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: Index
>            Reporter: Otis Gospodnetic
>            Assignee: Michael Busch
>            Priority: Minor
>             Fix For: 2.3
>         Attachments:, lucene-743-take2.patch, lucene-743.patch,
lucene-743.patch, lucene-743.patch,,, varient-no-isCloneSupported.BROKEN.patch
> This is Robert Engels' implementation of IndexReader.reopen() functionality, as a set
of 3 new classes (this was easier for him to implement, but should probably be folded into
the core, if this looks good).

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