[PATCH] Actually close the xapian database in notmuch_database_close

Olly Betts olly at survex.com
Wed Feb 29 13:19:22 PST 2012


On Wed, Feb 29, 2012 at 10:48:33AM -0500, Austin Clements wrote:
> Quoth Justus Winter on Feb 29 at 10:19 am:
> > Formerly the xapian database object was deleted and closed in its
> > destructor once the object was garbage collected. Explicitly call
> > close() so that the database and the associated lock is released
> > immediately.
> 
> Interesting.  Is this a bug in Xapian?  According to the docs,
> ~Database is supposed to close the database (if there are no other
> copies, which there shouldn't be), so this should be redundant with
> the delete notmuch->xapian_db a few lines down, but your experience
> obviously suggests that it isn't and I can't find the code path in
> Xapian that would close it in the destructor.

Most Xapian API classes (including Database and WritableDatabase) just
hold a reference-counted pointer, and so it's the destructor of the
reference-counted object which closes the database.  If "PIMPL" means
anything to you, that's what we have here.

Some other API classes objects (such as PostingIterator) internally hold
a reference to the database they are using, so calling close()
explicitly is useful if you don't want to have to worry about such
objects still existing and holding onto references which keep the
database open.

The main motivation for adding close() was the bindings though - e.g. in
Python the wrapped Database object gets destroyed when the GC gets run,
which is at some essentially arbitrary time after you remove the last
reference to it.

It is hard to say if calling close() is actually useful here from just
seeing the patch.

Cheers,
    Olly


More information about the notmuch mailing list