[Xapian-discuss] Reopening database

Olly Betts olly at survex.com
Wed Apr 30 10:39:54 BST 2008


On Wed, Apr 30, 2008 at 10:13:38AM +0100, Francis Irving wrote:
> When I alter the database, the readers don't see the changes until the
> webserver is next restarted - I'm caching the database connection so
> it doesn't reopen each query.
> 
> Which of the following is the best fix...
> 
> - Is there some way of getting Xapian to detect that the database has
>   been written to? So I can reopen it exactly when needed. e.g. 
>   I looked for a way of programmatically reading the revision number
>   or similar, but got nowhere (maybe can use filesystem time stamps?).

There's no built-in way.  You could look at timestamps, but you're
relying on implementation details.

> - Should I just reopen it every request, will that have much
>   performance cost? That is what seems to happen in PHP, and it's OK.

This is what I'd do.  I had a quick look at the code, and this currently
does more work than is really necessary in the "no change" case, but it
would be easy to short cut here (just reopen the record table and
compare its revision to the currently open one which we can find very
cheaply).  I'll address that for 1.1.0.

> - Something else :)

You can catch DatabaseModifiedError and call reopen() then, then retry
the search.  But you will probably end up searching the database at
least one revision behind the latest a lot of the time.

Cheers,
    Olly



More information about the Xapian-discuss mailing list