The proper way to close IndexWriter should be: writer.close()
But I don't like the trap this sets up on apps that upgrade ... so if
there are pending uncommitted changes, IW.close should throw an exc
(IllegalStateExc?). Ie, the app must be explicit about discarding or
committing those changes, before calling close.
Separately, if there are running merges then we should throw a similar
exception, otherwise we set up a denial-of-service on biggish merges
trap: for apps that open a writer, index a batch of docs, and close
the writer, a given biggish merge would forever kick off when the
writer is opened and then be aborted when it's closed, wasting CPU/IO
and never finishing the merge.
If we handle those two traps then I'm OK with making close "just
close". The "proper" shutdown sequence for IW would then be:
w.waitForMerges() OR w.abortMerges()
w.commit() OR w.rollback()
(And we'd fix rollback to not close).
Shai objected to how verbose this is for "normal" usage, and I agree,
so I proposed adding a sugar mehod "commitAndClose" that would just
call waitForMerges(), commit(), close(). I was hoping to hear from
Shai whether that's an OK compromise...
Although close() may do more than just closing (if autocommit is enabled, it may also commit), they decided to add Closeable (e.g., see http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html) - but the discussion here was similar.
That's an interesting precedent. Uwe do you a pointer to the
So I think another option here is to leave close as is (it waits for
merges, commits) except, if an exception is thrown, it suppresses that
exception, finishes closing, and then throws it. Like IOUtils.close
This way on calling IW.close(), if an exception is thrown, the IW will
in fact have been closed / relased its lock / etc., and then the app
sees the first exception that was hit while closing.
Hmm... does java.io.Closeable document semantics on exception? Ie if
I call RAF.close and hit an exception, is it "really closed"? It does
document that calling it more than once is fine ...