[Xapian-discuss] Re: Closing a DB
richard at lemurconsulting.com
Fri Aug 10 10:14:52 BST 2007
David Morris wrote:
>> 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.
No - because if you have the DB object around, you have a reference to
it, so it won't be closed...
> 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.
Yes - however, some of the accesses are performed very frequently in
performance critical situations: eg, access to posting lists is
performed very frequently when doing a match. It may not make much of
an impact to add a check, but I'm wary of doing so without first
measuring the effect...
> 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?
Xapian doesn't provide any guarantees about what happens if the database
directory is fiddled with by an external process, or by disk corruption
In practice, on unix, if the files are deleted, xapian will cope fine
for a while, because the filehandles are kept open as long as the xapian
database is, and the unix file semantics mean that the file contents are
accessible until the file handles are closed. (However, if you delete
the database directory, and then try and do a commit() or flush(),
you'll get an error because those operations create new files.)
On windows, I believe you'll get an exception thrown when xapian next
tries to read something from a file. It does something sensible, anyway.
More information about the Xapian-discuss