[
https://issues.apache.org/jira/browse/LUCENE-743?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Michael Busch updated LUCENE-743:
---------------------------------
Attachment: lucene-743-take2.patch
I'm attaching a new version of the patch that has a lot of changes compared to
the last patch:
- I factored most of the reopen logic into the subclasses of IndexReader. Now
that we're having the DirectoryIndexReader layer this was possible in a more
elegant way.
- IndexReader.reopen() now does not close the old readers by default. This was
somewhat tricky, because now the IndexReaders must be cloneable. I changed
IndexReader to implement the Cloneable interface and implemented clone() for
all Lucene built-in IndexReaders. However, there are probably custom
IndexReader implementations out there that do not implement clone() and
reopen() should throw an exception when an attempt is made to reopen such a
reader. But I don't want to throw an exception in IndexReader.clone() itself,
because then it would not be possible anymore for subclasses to recursively
call the native Object.clone() via super.clone(). To solve this conflict I
added the method
{code:java}
/**
* Returns true, if this IndexReader instance supports the clone() operation.
*/
protected boolean isCloneSupported();
{code}
to IndexReader which returns false by default. IndexReader.clone() checks if
the actual implementation supports clone() (i. e. the above method returns
true). If not, it throws an UnsupportedOperationException, if yes, it returns
super.clone().
I was not sure about whether to throw an (unchecked)
UnsupportedOperationException or a CloneNotSupportedException in this case. I
decided to throw UnsupportedOperationException even though it's not really
following the clone() guidelines, because it avoids the necessity to catch the
CloneNotSupportedException every time clone() is called (in the reopen()
methods of all IndexReader implementations).
As an example for how the clone() method is used let me describe how
MultiReader.reopen() works: it tries to reopen every of its subreaders. If at
least one subreader could be reopened successfully, then a new MultiReader
instance is created and the reopened subreaders are added to it. Every of the
old MultiReader's subreaders, that was not reopened (because of no index
changes) is now cloned() and added to the new MultiReader.
- I also added the new method
{code:java}
/**
* In addition to [EMAIL PROTECTED] #reopen()} this methods offers the
ability to close
* the old IndexReader instance. This speeds up the reopening process for
* certain IndexReader implementations and reduces memory consumption, because
* resources of the old instance can be reused for the reopened IndexReader
* as it avoids the need of copying the resources.
* <p>
* The reopen performance especially benefits if IndexReader instances
returned
* by one of the <code>open()</code> methods are reopened with
* <code>closeOldReader==true</code>.
* <p>
* Certain IndexReader implementations ([EMAIL PROTECTED] MultiReader},
[EMAIL PROTECTED] ParallelReader})
* require that the subreaders support the clone() operation (see [EMAIL
PROTECTED] #isCloneSupported()}
* in order to perform reopen with <code>closeOldReader==false</code>.
*/
public synchronized IndexReader reopen(boolean closeOldReader);
{code}
As the javadoc says it has two benefits: 1) it speeds up reopening and reduces
ressources, and 2) it allows to reopen readers, that use non-cloneable
subreaders.
Please let me know what you think about these changes, especially about the
clone() implementation.
> IndexReader.reopen()
> --------------------
>
> Key: LUCENE-743
> URL: https://issues.apache.org/jira/browse/LUCENE-743
> Project: Lucene - Java
> Issue Type: Improvement
> Components: Index
> Reporter: Otis Gospodnetic
> Assignee: Michael Busch
> Priority: Minor
> Fix For: 2.3
>
> Attachments: IndexReaderUtils.java, lucene-743-take2.patch,
> lucene-743.patch, lucene-743.patch, lucene-743.patch, MyMultiReader.java,
> MySegmentReader.java
>
>
> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]