lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: Is close() correct?
Date Thu, 25 Jun 2009 19:47:00 GMT
This came up a while back and we decided (then) that double-closing
should be allowed:

  http://issues.apache.org/jira/browse/LUCENE-818?focusedCommentId=12477399&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_12477399

I think if we changed this ("every close counts") we'd break a number
of apps.

Since close() is just a protected ("only once") call to decRef(), you
could simply always call decRef() and never close()?

Mike

On Thu, Jun 25, 2009 at 3:09 PM, Yonik Seeley<yonik@lucidimagination.com> wrote:
> Are the semantics of close() really correct when reopen() is used?
>
>  public final synchronized void close() throws IOException {
>    if (!closed) {
>      decRef();
>      closed = true;
>    }
>  }
>
> Solr has the following code:
>        IndexReader newReader = currentReader.reopen();
>        if (newReader == currentReader) {
>          currentReader.incRef();
>        }
>
> reopen() used to return the same instance if no changes had been made
> - that makes sense.
> But then of you do a close on both the currentReader and newReader,
> only one decRef() will be called!
>
> The reopen() javadoc suggests this has not changed:
>   * If the index has not changed since this instance was (re)opened, then this
>   * call is a NOOP and returns this instance.
>
> Seems like the "closed" variable just be eliminated completely?
> Throwing an exception on too many closes (rather than silently
> ignoring) would probably be doing people a favor.
>
> -Yonik
> http://www.lucidimagination.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-dev-help@lucene.apache.org
>
>

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