mu-store/indexer: consume messages from workers

Add store::consume_message, which is like add message but std::move from
the caller such that the messages longer has copies (with
Xapian::Document) on the caller side; this is to avoid threading issues.
This commit is contained in:
Dirk-Jan C. Binnema
2024-05-08 19:11:40 +03:00
parent ceed832cb9
commit aeb6d44172
3 changed files with 20 additions and 8 deletions

View File

@ -204,8 +204,22 @@ public:
*
* @return the doc id of the added message or an error.
*/
Result<Id> add_message(Message& msg, bool is_new = false);
Result<Id> add_message(const std::string& path, bool is_new = false);
Result<Id> add_message(Message &msg, bool is_new = false);
Result<Id> add_message(const std::string &path, bool is_new = false);
/**
* Like add_message(), however, this consumes the message and disposes
* of it when the function ends. This can be useful when injecting
* messages from a worker thread, to ensure no Xapian::Documents
* live in different threads.
*
* @param msg a message
* @param is_new whether this is a completely new message
*/
Result<Id> consume_message(Message&& msg, bool is_new = false) {
Message consumed{std::move(msg)};
return add_message(consumed, is_new);
}
/**
* Remove a message from the store. It will _not_ remove the message