lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael McCandless (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LUCENE-818) IndexWriter should detect when it's used after being closed
Date Sat, 03 Mar 2007 23:58:50 GMT

    [ https://issues.apache.org/jira/browse/LUCENE-818?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12477713
] 

Michael McCandless commented on LUCENE-818:
-------------------------------------------

>> On the thread safety issue: are you saying if one thread closes the
>> reader while another thread is using it, there is uncertainty excactly
>> when the 2nd thread will hit the AlreadyClosedException (because of
>> how the JVM schedules the threads)?
>
> Yes, but it's not just thread scheduling, it's also lack of memory
> barriers. The 2nd thread may *never* see the close(), depending on
> the exact architecture of machine and the JVM.

Yikes.  Is this the Java memory model issue?  Ie, there is no hard
guarantee on when a "write" from one thread will be visible to other
threads, unless you use "volatile"?

>> I think this kind of thread behavior is normal/expected?
>
> For a class that isn't thread safe, yes. IndexReader is advertised
> as being thread safe though. If we guarantee an exception accessing
> a closed reader, then that should work 100% of the time. I don't
> think we should make that guarantee.

OK I think we shouldn't "guarantee" it.  I think listing as "@throws
AlreadyClosedException if this IndexReader is closed" is OK?

> We can still throw meaningful errors in more cases and make it
> easier for the user to debug that, but it should not be deemed an
> error if we don't throw an exception. Users should never rely on
> getting this exception for flow-control purposes anyway.

Agreed.

>> OK how about we do not call ensureOpen() in these IndexReader methods?:
>> numDoc()
>> maxDoc()
>> isDeleted()
>
> +1
> 
> hasDeletions() too?

OK I will change to not call ensureOpen() for hasDeletions too.  I
will roll a new patch with this.

>> > what about setting more things to null when a reader is closed?
>> Well ... I would prefer not to increase the frequency of getting "undefined" NPEs
out of the reader
>
> Yes, but not all bugs will be user bugs. Some will be internal
> Lucene stuff that bypass public methods.  It's still better that
> these fail quicker too. Anyway, that can be handled on a
> case-by-case basis later.

OK, I agree.  Better to throw a "fail-fast" NPE than do something
strange later.

> IndexWriter should detect when it's used after being closed
> -----------------------------------------------------------
>
>                 Key: LUCENE-818
>                 URL: https://issues.apache.org/jira/browse/LUCENE-818
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Index
>    Affects Versions: 2.1
>            Reporter: Michael McCandless
>         Assigned To: Michael McCandless
>            Priority: Minor
>         Attachments: LUCENE-818.patch, LUCENE-818.take2.patch
>
>
> Spinoff from this thread on java-user:
>     http://www.gossamer-threads.com/lists/lucene/java-user/45986
> If you call addDocument on IndexWriter after it's closed you'll hit a
> hard-to-explain NullPointerException (because the RAMDirectory was
> closed).  Before 2.1, apparently you won't hit any exception and the
> IndexWrite will keep running but will have released it's write lock (I
> think).
> I plan to fix IndexWriter methods to throw an IllegalStateException if
> it has been closed.

-- 
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-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message