[Xapian-discuss] Re: Closing a DB

David Morris dmorris at sirca.org.au
Fri Aug 10 01:03:37 BST 2007


Richard Boulton <richard <at> lemurconsulting.com> writes:

> 
> David Morris wrote:
> > As part of my whole indexing thing, I want to move the databases 
> > around, from within the code. So, I figured that the safest bet 
> > would be to close the DB before attempting to move it. 
> > 
> > But there's no Xapian::Database::close() or even 
> > Xapian::WritableDatabase::close().
> ...
> > g_Xap = Xapian::WritableDatabase();
> > 
> > But that doesn't force a close, it just does the whole refcount 
> > thing, which could potentially leave it open if someone still 
> > has it laying around.
> 
> It's worse that that - in fact, if there is any xapian object _derived_ 
> from the WritableDatabase (like a PostingIterator) still around, the 
> database won't get closed (though you won't be able to access it).

Hot damm... Hmm... So, theoretically, if there are no more references laying
around, I can "assume" that the DB has been closed? Is there a method to get
information from the DB object? As in, is it open, etc, etc. That way I can
assert for it in my tests.

> 
> > Why is there no close() method? What's the "official" way to 
> > close a DB?
> 
> It would definitely be good to add a close() method.  There is an open 
> bug about this issue: see 
> http://www.xapian.org/cgi-bin/bugzilla/show_bug.cgi?id=173
> 
> Unfortunately, it's not that easy to add a close() method, because it 
> would also require all the objects which use a database to cope with the 
> database being closed underneath them.  It'll get implemented at some 
> stage, but we've been trying to think of a neat way of doing so...

Thing is, if the database has been explicitly closed, any access to it can throw
an exception, and none of the objects will have cope with anything, right?

(I haven't actually looked at the internals, but) this would mean that every
call would have a little bit of overhead to check to see if the DB has been
closed, but that's about it.

Because, how does everything else cope if the database files suddenly disappear
from under xapian's noses? As in, a filesystem error where the OS just "looses"
the files?

> 
> [Actually, bug #173 only discusses adding a close() method to the 
> bindings, but I think the only plausible way of doing that would be to 
> add a close() method to the C++ interface, and wrap it.]
> 
> Feel free to comment on #173 if you have any thoughts.
> 







More information about the Xapian-discuss mailing list