Skip to content

Commit 8333fee

Browse files
author
Ralf Schlatterbeck
committed
new rdbms config item sqlite_timeout...
...makes the previously hard-coded timeout of 30 seconds configurable. This is the time a client waits for the locked database to become free before giving up. Used only for SQLite backend.
1 parent c93d12c commit 8333fee

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Features:
1313
title with the changed subject. Thanks to Arkadiusz Kita and Peter
1414
Funk for requesting the feature and discussing the implementation.
1515
http://thread.gmane.org/gmane.comp.bug-tracking.roundup.user/10169
16+
- new rdbms config item sqlite_timeout makes the previously hard-coded
17+
timeout of 30 seconds configurable. This is the time a client waits
18+
for the locked database to become free before giving up. Used only for
19+
SQLite backend.
1620

1721
Fixed:
1822

roundup/backends/back_sqlite.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ class Database(rdbms_common.Database):
7575

7676
def sqlite_busy_handler(self, data, table, count):
7777
"""invoked whenever SQLite tries to access a database that is locked"""
78+
now = time.time()
7879
if count == 1:
79-
# use a 30 second timeout (extraordinarily generous)
80-
# for handling locked database
81-
self._busy_handler_endtime = time.time() + 30
82-
elif time.time() > self._busy_handler_endtime:
80+
# Timeout for handling locked database (default 30s)
81+
self._busy_handler_endtime = now + self.config.RDBMS_SQLITE_TIMEOUT
82+
elif now > self._busy_handler_endtime:
8383
# timeout expired - no more retries
8484
return 0
8585
# sleep adaptively as retry count grows,
@@ -100,13 +100,13 @@ def sql_open_connection(self):
100100

101101
db = os.path.join(self.config.DATABASE, 'db')
102102
logging.getLogger('hyperdb').info('open database %r'%db)
103-
# set a 30 second timeout (extraordinarily generous) for handling
104-
# locked database
103+
# set timeout (30 second default is extraordinarily generous)
104+
# for handling locked database
105105
if sqlite_version == 1:
106106
conn = sqlite.connect(db=db)
107107
conn.db.sqlite_busy_handler(self.sqlite_busy_handler)
108108
else:
109-
conn = sqlite.connect(db, timeout=30)
109+
conn = sqlite.connect(db, timeout=self.config.RDBMS_SQLITE_TIMEOUT)
110110
conn.row_factory = sqlite.Row
111111

112112
# pysqlite2 / sqlite3 want us to store Unicode in the db but

roundup/configuration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ def str2value(self, value):
604604
(NullableOption, 'read_default_group', 'roundup',
605605
"Name of the group to use in the MySQL defaults file (.my.cnf).\n"
606606
"Only used in MySQL connections."),
607+
(IntegerNumberOption, 'sqlite_timeout', '30',
608+
"Number of seconds to wait when the SQLite database is locked\n"
609+
"Default: use a 30 second timeout (extraordinarily generous)\n"
610+
"Only used in SQLite connections."),
607611
(IntegerNumberOption, 'cache_size', '100',
608612
"Size of the node cache (in elements)"),
609613
), "Settings in this section are used"

0 commit comments

Comments
 (0)