[Xapian-discuss] flush() definitely required before close()
Olly Betts
olly at survex.com
Wed Dec 23 13:50:57 GMT 2009
On Wed, Dec 23, 2009 at 01:21:23PM +0200, henka at cityweb.co.za wrote:
> WRT this discussion:
> http://lists.xapian.org/pipermail/xapian-discuss/2009-November/007300.html
>
> Richard recommends calling flush() before closing a index database
> segment, etc.
He's talking about the case where the destructor is called, since that calls
flush() implicitly and swallows any exception produced (it has to really -
in C++, you can't throw an exception from a destructor called because an
active exception is causing the stack to be unwound, and for sanity it's
recommended not to behave differently depending if another exception is
active or not).
So if you want to see if there was an error, and what it was, you need to
call flush() yourself first so there are no unflushed changes for the
destructor to deal with.
> Well, I can confirm that calling flush() is *required*
> before calling close() since close() on it's own does not commit/flush any
> pending writes/whatever unless the Perl script terminates, etc.
Hmm, since the destructor of WritableDatabase calls flush() implicitly, I
think for consistency that close() should too (but without the error
swallowing) to avoid a trap causing possible data loss. In 1.0.x, you have
to use "cancel_transaction()" (or crash!) to discard unflushed changes,
which is pretty obviously going to discard data.
And this only affects 1.1.x, so it's certainly reasonable to change behaviour
here.
Anyone disagree?
Cheers,
Olly
More information about the Xapian-discuss
mailing list