Skip to content

Commit 9ed3d9b

Browse files
committed
issue2550839: Xapian, DatabaseLockError: Unable to get write lock on
db/text-index: already locked I put in a retry loop that will attempt to get the lock. 10 tries with a delaythatvaries from .02 seconds to .64 seconds. Total delay over 10 cycles approx. 4.5 seconds. I can't figure out how to make pytest run two parallel processes to test this code. I did try running: ./run_tests.py -k Xapian test/test_indexer.py & ./run_tests.py -k Xapian test/test_indexer.py and confirmed that one of the processes seemed to hang on a test and then threw a lock failure error. So at least the code path is being exercised. If anybody knows how to correctly test this I would love to do a real test.
1 parent a5ad726 commit 9ed3d9b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ Fixed:
277277
module added to ``doc/installation.txt``.
278278
- issue2550776: imapServer.py problem. Fixed a missing initialization of the
279279
logging level if no logging level option is supplied. (John Rouillard)
280+
- issue2550839: Xapian, DatabaseLockError: Unable to get write lock on
281+
db/text-index: already locked. Put in a retry loop that will attempt
282+
to get the lock. Total delay approx 4.5 seconds. (John Rouillard)
280283

281284
2016-01-11: 1.5.1
282285

roundup/backends/indexer_xapian.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
''' This implements the full-text indexer using the Xapian indexer.
22
'''
3-
import re, os
3+
import re, os, time
44

55
import xapian
66

@@ -17,7 +17,18 @@ def __init__(self, db):
1717

1818
def _get_database(self):
1919
index = os.path.join(self.db_path, 'text-index')
20-
return xapian.WritableDatabase(index, xapian.DB_CREATE_OR_OPEN)
20+
for n in range(10):
21+
try:
22+
# if successful return
23+
return xapian.WritableDatabase(index, xapian.DB_CREATE_OR_OPEN)
24+
except xapian.DatabaseLockError:
25+
# adaptive sleep. Get longer as count increases.
26+
time_to_sleep = 0.01 * (2 << min(5, n))
27+
time.sleep(time_to_sleep)
28+
# we are back to the for loop
29+
30+
# Get here only if we dropped out of the for loop.
31+
raise xapian.DatabaseLockError("Unable to get lock after 10 retries on %s."%index)
2132

2233
def save_index(self):
2334
'''Save the changes to the index.'''

0 commit comments

Comments
 (0)