You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Shai Erera <se...@gmail.com> on 2012/11/29 21:31:41 UTC

IndexWriter.ensureOpen and ensureOpen(boolean)

Hi

While working on LUCENE-4575 I noticed what I thought was an inconsistency
between prepareCommit() and prepareCommit(commitData).
The former called ensureOpen(true) and the latter ensureOpen(false). At
first I thought that this is a bug, so I fixed both to call
ensureOpen(true),
especially now that I consolidate the two prepCommit() versions into one,
but then all tests failed with AlreadyClosedException. How wonderful :).

Getting deeper into the meaning of the two ensureOpen versions i realize
that the boolean means something like "fail if IW has been closed, or is
in the process of closing). Some methods choose to not fail if IW is in the
process of closing, while others do (mostly internal methods).

My question is - why make the distinction? If IW is in the process of
closing, why not always fail?

Shai

Re: IndexWriter.ensureOpen and ensureOpen(boolean)

Posted by Robert Muir <rc...@gmail.com>.
On Fri, Nov 30, 2012 at 8:29 AM, Michael McCandless <
lucene@mikemccandless.com> wrote:

>
> > 2) Could you perhaps clarify the use of the second argument in the
> javadocs?
> > Maybe also rename it to something like "fail if closing"? The name
> > "includePendingClose" is vague perhaps consider*?)
>
> I agree that current name is no good!  failIfClosing seems good?
>
>
+1. a boolean for ensureOpen is intimidating: fixing up the param
name/documentation here makes it easier to understand.

I had no idea what this boolean was doing from the current
code/explanation: but shai's explanation makes sense.

Re: IndexWriter.ensureOpen and ensureOpen(boolean)

Posted by Michael McCandless <lu...@mikemccandless.com>.
On Fri, Nov 30, 2012 at 1:08 PM, Shai Erera <se...@gmail.com> wrote:
>> Hmm prepareCommit() really should somehow pass true: this API is only
>> invoked by the app, not by IW internally during close.
>
>
> Currently, the app can call prepareCommit() or prepareCommint(data), the
> former calls ensureOpen(true), the latter ensureOpen(false).
>
> The problem is that the latter is called by internalCommit(). So when I
> changed prepareCommit(data) to call ensureOpen(true), all TestIndexWriter
> tests failed (the only ones I tried).

OK I see.

> So I think that in that issue, I should create an internalPrepareCommit and
> leave prepCommit() to call ensureOpen(), while internalPrep will call
> ensureOpen(false). And also change IW code to call internalCommit. How's
> that sound?

That sounds good!  Thanks.

Mike McCandless

http://blog.mikemccandless.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Re: IndexWriter.ensureOpen and ensureOpen(boolean)

Posted by Shai Erera <se...@gmail.com>.
>
> Hmm prepareCommit() really should somehow pass true: this API is only
> invoked by the app, not by IW internally during close.


Currently, the app can call prepareCommit() or prepareCommint(data), the
former calls ensureOpen(true), the latter ensureOpen(false).

The problem is that the latter is called by internalCommit(). So when I
changed prepareCommit(data) to call ensureOpen(true), all TestIndexWriter
tests failed (the only ones I tried).

So I think that in that issue, I should create an internalPrepareCommit and
leave prepCommit() to call ensureOpen(), while internalPrep will call
ensureOpen(false). And also change IW code to call internalCommit. How's
that sound?

+1 for failIfClosing !

Shai

On Fri, Nov 30, 2012 at 3:29 PM, Michael McCandless <
lucene@mikemccandless.com> wrote:

> On Fri, Nov 30, 2012 at 7:13 AM, Shai Erera <se...@gmail.com> wrote:
> > I see. So two questions:
> >
> > 1) Is it ok for prepareCommit() to call ensureOpen(false)? In
> LUCENE-4575 I
> > consolidate the two prepCommit() and this is the only way it would work
> ...
>
> Hmm prepareCommit() really should somehow pass true: this API is only
> invoked by the app, not by IW internally during close.  Not sure how
> we can fix the patch to get that back ...
>
> > 2) Could you perhaps clarify the use of the second argument in the
> javadocs?
> > Maybe also rename it to something like "fail if closing"? The name
> > "includePendingClose" is vague perhaps consider*?)
>
> I agree that current name is no good!  failIfClosing seems good?
>
> Mike McCandless
>
> http://blog.mikemccandless.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>
>

Re: IndexWriter.ensureOpen and ensureOpen(boolean)

Posted by Michael McCandless <lu...@mikemccandless.com>.
On Fri, Nov 30, 2012 at 7:13 AM, Shai Erera <se...@gmail.com> wrote:
> I see. So two questions:
>
> 1) Is it ok for prepareCommit() to call ensureOpen(false)? In LUCENE-4575 I
> consolidate the two prepCommit() and this is the only way it would work ...

Hmm prepareCommit() really should somehow pass true: this API is only
invoked by the app, not by IW internally during close.  Not sure how
we can fix the patch to get that back ...

> 2) Could you perhaps clarify the use of the second argument in the javadocs?
> Maybe also rename it to something like "fail if closing"? The name
> "includePendingClose" is vague perhaps consider*?)

I agree that current name is no good!  failIfClosing seems good?

Mike McCandless

http://blog.mikemccandless.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Re: IndexWriter.ensureOpen and ensureOpen(boolean)

Posted by Shai Erera <se...@gmail.com>.
I see. So two questions:

1) Is it ok for prepareCommit() to call ensureOpen(false)? In LUCENE-4575 I
consolidate the two prepCommit() and this is the only way it would work ...

2) Could you perhaps clarify the use of the second argument in the
javadocs? Maybe also rename it to something like "fail if closing"? The
name "includePendingClose" is vague perhaps consider*?)

Thanks anyway for clarifying this !

Shai

On Fri, Nov 30, 2012 at 1:57 PM, Michael McCandless <
lucene@mikemccandless.com> wrote:

> On Thu, Nov 29, 2012 at 3:31 PM, Shai Erera <se...@gmail.com> wrote:
> >
> > Hi
> >
> > While working on LUCENE-4575 I noticed what I thought was an
> inconsistency between prepareCommit() and prepareCommit(commitData).
> > The former called ensureOpen(true) and the latter ensureOpen(false). At
> first I thought that this is a bug, so I fixed both to call
> ensureOpen(true),
> > especially now that I consolidate the two prepCommit() versions into
> one, but then all tests failed with AlreadyClosedException. How wonderful
> :).
> >
> > Getting deeper into the meaning of the two ensureOpen versions i realize
> that the boolean means something like "fail if IW has been closed, or is
> > in the process of closing). Some methods choose to not fail if IW is in
> the process of closing, while others do (mostly internal methods).
> >
> > My question is - why make the distinction? If IW is in the process of
> closing, why not always fail?
>
> Because IW will call some of these methods during close (eg it commits
> before closing)...
>
> If we fix close to not commit (there is an issue for this...) then we
> could likely remove this boolean.
>
> Mike McCandless
>
> http://blog.mikemccandless.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>
>

Re: IndexWriter.ensureOpen and ensureOpen(boolean)

Posted by Michael McCandless <lu...@mikemccandless.com>.
On Thu, Nov 29, 2012 at 3:31 PM, Shai Erera <se...@gmail.com> wrote:
>
> Hi
>
> While working on LUCENE-4575 I noticed what I thought was an inconsistency between prepareCommit() and prepareCommit(commitData).
> The former called ensureOpen(true) and the latter ensureOpen(false). At first I thought that this is a bug, so I fixed both to call ensureOpen(true),
> especially now that I consolidate the two prepCommit() versions into one, but then all tests failed with AlreadyClosedException. How wonderful :).
>
> Getting deeper into the meaning of the two ensureOpen versions i realize that the boolean means something like "fail if IW has been closed, or is
> in the process of closing). Some methods choose to not fail if IW is in the process of closing, while others do (mostly internal methods).
>
> My question is - why make the distinction? If IW is in the process of closing, why not always fail?

Because IW will call some of these methods during close (eg it commits
before closing)...

If we fix close to not commit (there is an issue for this...) then we
could likely remove this boolean.

Mike McCandless

http://blog.mikemccandless.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org