From: schlatterbeck Date: Tue, 7 Sep 2010 15:42:04 +0000 (+0000) Subject: new rdbms config item sqlite_timeout makes the previously hard-coded X-Git-Url: https://git.tokkee.org/?p=roundup.git;a=commitdiff_plain;h=6ddfa30821c90f4a2646269e5b3b301dec05bbfc 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. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4521 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index d0a8950..fc38e5e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -13,6 +13,10 @@ Features: title with the changed subject. Thanks to Arkadiusz Kita and Peter Funk for requesting the feature and discussing the implementation. http://thread.gmane.org/gmane.comp.bug-tracking.roundup.user/10169 +- 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. Fixed: diff --git a/roundup/backends/back_sqlite.py b/roundup/backends/back_sqlite.py index c947eb3..5d6be01 100644 --- a/roundup/backends/back_sqlite.py +++ b/roundup/backends/back_sqlite.py @@ -75,11 +75,11 @@ class Database(rdbms_common.Database): def sqlite_busy_handler(self, data, table, count): """invoked whenever SQLite tries to access a database that is locked""" + now = time.time() if count == 1: - # use a 30 second timeout (extraordinarily generous) - # for handling locked database - self._busy_handler_endtime = time.time() + 30 - elif time.time() > self._busy_handler_endtime: + # Timeout for handling locked database (default 30s) + self._busy_handler_endtime = now + self.config.RDBMS_SQLITE_TIMEOUT + elif now > self._busy_handler_endtime: # timeout expired - no more retries return 0 # sleep adaptively as retry count grows, @@ -100,13 +100,13 @@ class Database(rdbms_common.Database): db = os.path.join(self.config.DATABASE, 'db') logging.getLogger('hyperdb').info('open database %r'%db) - # set a 30 second timeout (extraordinarily generous) for handling - # locked database + # set timeout (30 second default is extraordinarily generous) + # for handling locked database if sqlite_version == 1: conn = sqlite.connect(db=db) conn.db.sqlite_busy_handler(self.sqlite_busy_handler) else: - conn = sqlite.connect(db, timeout=30) + conn = sqlite.connect(db, timeout=self.config.RDBMS_SQLITE_TIMEOUT) conn.row_factory = sqlite.Row # pysqlite2 / sqlite3 want us to store Unicode in the db but diff --git a/roundup/configuration.py b/roundup/configuration.py index dbbac6f..60b4190 100644 --- a/roundup/configuration.py +++ b/roundup/configuration.py @@ -604,6 +604,10 @@ SETTINGS = ( (NullableOption, 'read_default_group', 'roundup', "Name of the group to use in the MySQL defaults file (.my.cnf).\n" "Only used in MySQL connections."), + (IntegerNumberOption, 'sqlite_timeout', '30', + "Number of seconds to wait when the SQLite database is locked\n" + "Default: use a 30 second timeout (extraordinarily generous)\n" + "Only used in SQLite connections."), (IntegerNumberOption, 'cache_size', '100', "Size of the node cache (in elements)"), ), "Settings in this section are used"