Xapian concurrency

Dirk-Jan C. Binnema djcb.bulk at gmail.com
Mon Apr 29 05:20:44 BST 2024


On Monday Apr 29 2024, Olly Betts wrote:

> On Sun, Apr 28, 2024 at 11:10:12PM +0300, Dirk-Jan C. Binnema wrote:
>> I'm trying to use Xapian in a multi-threaded environment; and generally
>> be carefully that database is not accessed concurrently (as per [1])
>> 
>> However, during indexing I want to create Xapian documents in multiple
>> threads (without referencing the database in any way). Actually adding
>> them to the database is done in a single thread (and with locks etc.)
>> 
>> Is this is a safe way to implement this?
>
> It should be if you're careful about how the object is handed off from
> one tread to another - you want to make sure that two different threads
> won't try to modify the internal reference count simultaneously.
>
> I'd suggest looking at using C++11 std::move() to safely transfer the
> Xapian::Document object between the two threads.  I've not tried it
> myself, but German M.  Bravo reported using this approach in the (sadly
> apparently now defunct) xapiand project.
>
> We should probably document this approach in the page you linked to so
> if you try it, some feedback would be useful.

Ah, thank you!

Hadn't noticed that Xapian::Document and others gained move-ctors /
assignment operators, and they have been there for a while! Seems
the docs don't mention that yet[1].

In any case, that seems very useful, I'll try that.

Kind regards,
Dirk.

[1] https://xapian.org/docs/apidoc/html/classXapian_1_1Document.html
-- 
Dirk-Jan C. Binnema                  Helsinki, Finland
e:djcb at djcbsoftware.nl           w:www.djcbsoftware.nl
gpg: 6987 9CED 1745 9375 0F14 DA98 11DD FEA9 DCC4 A036



More information about the Xapian-discuss mailing list