From b42b8482b191f4f509d5418242e7a8c00e3418f9 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Sat, 14 May 2011 17:49:10 +0000 Subject: Retry opening the Xapian database if another process still has the lock This should help with situations where the new gdatastore process is already starting up (on a new session bus) while the old one is still busy shutting down (see also: SL#1257). --- diff --git a/gdatastore/index.py b/gdatastore/index.py index c93f5b3..35491bf 100644 --- a/gdatastore/index.py +++ b/gdatastore/index.py @@ -19,6 +19,7 @@ Gdatastore metadata index interface import logging import os import sys +import time import xapian from xapian import Document, Enquire, Query, WritableDatabase @@ -320,8 +321,17 @@ class Index(object): database.close() def _migrate(self): - self._database = WritableDatabase(self._base_dir, - xapian.DB_CREATE_OR_OPEN) + for try_count in range(10): + try: + self._database = WritableDatabase(self._base_dir, + xapian.DB_CREATE_OR_OPEN) + except xapian.DatabaseLockError: + logging.error("Couldn't lock Xapian database (try #%d)", + try_count) + time.sleep(1) + else: + break + version = int(self._database.get_metadata('gdatastore_version')) if version > _CURRENT_VERSION: -- cgit v0.9.1