[Xapian-discuss] get_lastdocid, multiple connections

Richard Boulton richard at tartarus.org
Fri Mar 11 12:31:37 GMT 2005

On Fri, 2005-03-11 at 13:14 +0100, Ivar Bratberg wrote:
> After adding a document to a writable db, I use get_lastdocid to get the
> id of the last document added.  If I have several threads accessing the
> db through different db connections, how can I now that this is the
> correct ID I get, and not the one which was added through another
> connection ?  

Xapian doesn't support concurrent access to any of its objects.
Therefore, you _must_ prevent concurrent access to your database object.
This is usually done with a mutex (or something equivalent), which must
be locked by a thread before that thread accesses the database object.

If you ensure that you lock this mutex before calling get_lastdocid, you
can assume the result is correct until you unlock the mutex.

Note that get_lastdocid() will always return the last document ID in the
database - not the last document ID added to the database by the current
thread, or anything along those lines.

Richard Boulton <richard at tartarus.org>

More information about the Xapian-discuss mailing list