DatabaseModifiedError, how to handle it correctly when searching?

Yuan Fu casouri at gmail.com
Tue Aug 31 02:36:17 BST 2021



> On Aug 30, 2021, at 2:48 AM, Eric Wong <e at 80x24.org> wrote:
> 
> Yuan Fu <casouri at gmail.com> wrote:
>> The starter guide [1] mentioned that searching could result in DatabaseModifiedError, and I need to reopen the database should it happen. However, I couldn’t figure out which functions throw that error, I looked at Enquire.get_mset(), etc, and none of them says they throw this error. How should I correctly handle this?
>> 
>> [1] https://getting-started-with-xapian.readthedocs.io/en/latest/practical_example/searching/database_modified.html
> 
> I think pretty much all Xapian functions which read the database
> can throw DatabaseModifiedError.  I've been wrapping all
> accesses with `eval {}' (Perl's standard exception trapping
> mechanism).

Ah, I see, so for C++ it would look something like this, I assume?

      for (int i = 0; i < 2; i++)
        {
          try
            {
              database.replace_document (termID, new_doc);
              break;
            }
          catch (Xapian::DatabaseModifiedError &e)
            {
              database.reopen();
            }
        }


Yuan




More information about the Xapian-discuss mailing list