comparison roundup/backends/back_sqlite.py @ 4415:3e35233ea93c

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.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Tue, 07 Sep 2010 15:42:04 +0000
parents 13b3155869e0
children 9655a1b65974
comparison
equal deleted inserted replaced
4414:399569ff4aed 4415:3e35233ea93c
73 hyperdb.Multilink : lambda x: x, # used in journal marshalling 73 hyperdb.Multilink : lambda x: x, # used in journal marshalling
74 } 74 }
75 75
76 def sqlite_busy_handler(self, data, table, count): 76 def sqlite_busy_handler(self, data, table, count):
77 """invoked whenever SQLite tries to access a database that is locked""" 77 """invoked whenever SQLite tries to access a database that is locked"""
78 now = time.time()
78 if count == 1: 79 if count == 1:
79 # use a 30 second timeout (extraordinarily generous) 80 # Timeout for handling locked database (default 30s)
80 # for handling locked database 81 self._busy_handler_endtime = now + self.config.RDBMS_SQLITE_TIMEOUT
81 self._busy_handler_endtime = time.time() + 30 82 elif now > self._busy_handler_endtime:
82 elif time.time() > self._busy_handler_endtime:
83 # timeout expired - no more retries 83 # timeout expired - no more retries
84 return 0 84 return 0
85 # sleep adaptively as retry count grows, 85 # sleep adaptively as retry count grows,
86 # starting from about half a second 86 # starting from about half a second
87 time_to_sleep = 0.01 * (2 << min(5, count)) 87 time_to_sleep = 0.01 * (2 << min(5, count))
98 if not os.path.isdir(self.config.DATABASE): 98 if not os.path.isdir(self.config.DATABASE):
99 os.makedirs(self.config.DATABASE) 99 os.makedirs(self.config.DATABASE)
100 100
101 db = os.path.join(self.config.DATABASE, 'db') 101 db = os.path.join(self.config.DATABASE, 'db')
102 logging.getLogger('hyperdb').info('open database %r'%db) 102 logging.getLogger('hyperdb').info('open database %r'%db)
103 # set a 30 second timeout (extraordinarily generous) for handling 103 # set timeout (30 second default is extraordinarily generous)
104 # locked database 104 # for handling locked database
105 if sqlite_version == 1: 105 if sqlite_version == 1:
106 conn = sqlite.connect(db=db) 106 conn = sqlite.connect(db=db)
107 conn.db.sqlite_busy_handler(self.sqlite_busy_handler) 107 conn.db.sqlite_busy_handler(self.sqlite_busy_handler)
108 else: 108 else:
109 conn = sqlite.connect(db, timeout=30) 109 conn = sqlite.connect(db, timeout=self.config.RDBMS_SQLITE_TIMEOUT)
110 conn.row_factory = sqlite.Row 110 conn.row_factory = sqlite.Row
111 111
112 # pysqlite2 / sqlite3 want us to store Unicode in the db but 112 # pysqlite2 / sqlite3 want us to store Unicode in the db but
113 # that's not what's been done historically and it's definitely 113 # that's not what's been done historically and it's definitely
114 # not what the other backends do, so we'll stick with UTF-8 114 # not what the other backends do, so we'll stick with UTF-8

Roundup Issue Tracker: http://roundup-tracker.org/