From 9d3c909486835f646c08a50e111b0a9882f5965f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 31 Oct 2017 17:00:50 +1300 Subject: [PATCH] scriptindex: Use DB_RETRY_LOCK to wait for lock It's better than sleeping for a second and retrying as we currently do - on most platforms it means we make a blocking request for the lock, and even on platforms where that's not supported, we can sleep and retry inside libxapian, and without having to throw and catch an exception each time. --- xapian-applications/omega/Makefile.am | 2 +- xapian-applications/omega/scriptindex.cc | 18 ++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/xapian-applications/omega/Makefile.am b/xapian-applications/omega/Makefile.am index 0dc9effcd..930e21c2d 100644 --- a/xapian-applications/omega/Makefile.am +++ b/xapian-applications/omega/Makefile.am @@ -196,7 +196,7 @@ omindex_LDADD = $(MAGIC_LIBS) $(XAPIAN_LIBS) $(ZLIB_LIBS) scriptindex_SOURCES = scriptindex.cc myhtmlparse.cc htmlparse.cc\ common/getopt.cc commonhelp.cc utils.cc hashterm.cc loadfile.cc\ - common/safe.cc utf8convert.cc utf8truncate.cc\ + utf8convert.cc utf8truncate.cc\ common/keyword.cc timegm.cc datetime.cc scriptindex_LDADD = $(XAPIAN_LIBS) diff --git a/xapian-applications/omega/scriptindex.cc b/xapian-applications/omega/scriptindex.cc index 9ec9579b3..1d8d7857c 100644 --- a/xapian-applications/omega/scriptindex.cc +++ b/xapian-applications/omega/scriptindex.cc @@ -38,7 +38,6 @@ #include "safeerrno.h" #include #include -#include "safeunistd.h" #include "commonhelp.h" #include "hashterm.h" @@ -769,19 +768,10 @@ try { parse_index_script(argv[1]); - // Open the database. - Xapian::WritableDatabase database; - while (true) { - try { - database = Xapian::WritableDatabase(argv[0], database_mode); - break; - } catch (const Xapian::DatabaseLockError &) { - // Sleep and retry if we get a Xapian::DatabaseLockError - this - // just means that another process is updating the database. - cout << "Database locked ... retrying" << endl; - sleep(1); - } - } + // Open the database. If another process is currently updating the + // database, wait for the lock to become available. + auto flags = database_mode | Xapian::DB_RETRY_LOCK; + Xapian::WritableDatabase database(argv[0], flags); Xapian::TermGenerator indexer; indexer.set_stemmer(stemmer); -- 2.11.4.GIT