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

Earwin Burrfoot commented on LUCENE-1453:
-----------------------------------------

Two suggestions:

Factor out RefCount class and use it everywhere through Lucene. I see at least 
one identical to yours in SegmentReader. Would be easier to replace all these 
uses with AtomicInteger later.

Looking at the new unsightly loop in doClose(), what if we change all Lucene 
closeable classes to implement java.io.Closeable and create a static utility 
method(-s) that receives a bunch of Closeables (an array, iterable, vararg in 
1.5) and tries to close them all?
The method should be nullsafe (so you can skip != null checks) and will 
handle/rethrow exceptions. The most proper way to handle exceptions is probably 
this - rethrow original exception if it is the only one (be it Runtime or IO), 
if there's more - gather all exceptions and wrap them into a special 
IOException subclass that concatenates their messages and keeps them around, so 
they are inspectable at debug-time or if you implement special treatment for 
that exception in your code.
This method can be reused in a heap of places later, SR.doClose() comes first 
to mind.

I can do the latter one in a separate patch to close this issue faster.

> When reopen returns a new IndexReader, both IndexReaders may now control the 
> lifecycle of the underlying Directory which is managed by reference counting
> ---------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: LUCENE-1453
>                 URL: https://issues.apache.org/jira/browse/LUCENE-1453
>             Project: Lucene - Java
>          Issue Type: Bug
>    Affects Versions: 2.4
>            Reporter: Mark Miller
>            Assignee: Michael McCandless
>            Priority: Minor
>             Fix For: 2.4.1, 2.9
>
>         Attachments: Failing-testcase-LUCENE-1453.patch, 
> LUCENE-1453-with-FSDir-open.patch, LUCENE-1453.patch, LUCENE-1453.patch, 
> LUCENE-1453.patch, LUCENE-1453.patch, LUCENE-1453.patch
>
>
> Rough summary. Basically, FSDirectory tracks references to FSDirectory and 
> when IndexReader.reopen shares a Directory with a created IndexReader and 
> closeDirectory is true, FSDirectory's ref management will see two decrements 
> for one increment. You can end up getting an AlreadyClosed exception on the 
> Directory when the IndexReader is open.
> I have a test I'll put up. A solution seems fairly straightforward (at least 
> in what needs to be accomplished).

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