| OLD | NEW |
| 1 # This file is part of Buildbot. Buildbot is free software: you can | 1 # This file is part of Buildbot. Buildbot is free software: you can |
| 2 # redistribute it and/or modify it under the terms of the GNU General Public | 2 # redistribute it and/or modify it under the terms of the GNU General Public |
| 3 # License as published by the Free Software Foundation, version 2. | 3 # License as published by the Free Software Foundation, version 2. |
| 4 # | 4 # |
| 5 # This program is distributed in the hope that it will be useful, but WITHOUT | 5 # This program is distributed in the hope that it will be useful, but WITHOUT |
| 6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 8 # details. | 8 # details. |
| 9 # | 9 # |
| 10 # You should have received a copy of the GNU General Public License along with | 10 # You should have received a copy of the GNU General Public License along with |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 def __init__(self, engine): | 62 def __init__(self, engine): |
| 63 pool_size = 5 | 63 pool_size = 5 |
| 64 if hasattr(engine, 'optimal_thread_pool_size'): | 64 if hasattr(engine, 'optimal_thread_pool_size'): |
| 65 pool_size = engine.optimal_thread_pool_size | 65 pool_size = engine.optimal_thread_pool_size |
| 66 threadpool.ThreadPool.__init__(self, | 66 threadpool.ThreadPool.__init__(self, |
| 67 minthreads=1, | 67 minthreads=1, |
| 68 maxthreads=pool_size, | 68 maxthreads=pool_size, |
| 69 name='DBThreadPool') | 69 name='DBThreadPool') |
| 70 self.engine = engine | 70 self.engine = engine |
| 71 if engine.dialect.name == 'sqlite': | 71 if engine.dialect.name == 'sqlite': |
| 72 log.msg("applying SQLite workaround from Buildbot bug #1810") | 72 vers = self.get_sqlite_version() |
| 73 self.__broken_sqlite = self.detect_bug1810() | 73 log.msg("Using SQLite Version %s" % (vers,)) |
| 74 if vers < (3,3,17): |
| 75 log.msg("NOTE: this old version of SQLite does not support " |
| 76 "multiple simultaneous accesses to the database; " |
| 77 "add the 'pool_size=1' argument to your db url") |
| 78 brkn = self.__broken_sqlite = self.detect_bug1810() |
| 79 if brkn: |
| 80 log.msg("Applying SQLite workaround from Buildbot bug #1810") |
| 74 self._start_evt = reactor.callWhenRunning(self._start) | 81 self._start_evt = reactor.callWhenRunning(self._start) |
| 75 | 82 |
| 76 def _start(self): | 83 def _start(self): |
| 77 self._start_evt = None | 84 self._start_evt = None |
| 78 if not self.running: | 85 if not self.running: |
| 79 self.start() | 86 self.start() |
| 80 self._stop_evt = reactor.addSystemEventTrigger( | 87 self._stop_evt = reactor.addSystemEventTrigger( |
| 81 'during', 'shutdown', self._stop) | 88 'during', 'shutdown', self._stop) |
| 82 self.running = True | 89 self.running = True |
| 83 | 90 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 215 |
| 209 try: | 216 try: |
| 210 test() | 217 test() |
| 211 except sqlite.OperationalError: | 218 except sqlite.OperationalError: |
| 212 # this is the expected error indicating it's broken | 219 # this is the expected error indicating it's broken |
| 213 return True | 220 return True |
| 214 | 221 |
| 215 # but this version should not fail.. | 222 # but this version should not fail.. |
| 216 test(select_from_sqlite_master=True) | 223 test(select_from_sqlite_master=True) |
| 217 return False # not broken - no workaround required | 224 return False # not broken - no workaround required |
| 225 |
| 226 def get_sqlite_version(self): |
| 227 engine = sa.create_engine('sqlite://') |
| 228 conn = engine.contextual_connect() |
| 229 |
| 230 try: |
| 231 r = conn.execute("SELECT sqlite_version()") |
| 232 vers_row = r.fetchone() |
| 233 r.close() |
| 234 except: |
| 235 return (0,) |
| 236 |
| 237 if vers_row: |
| 238 try: |
| 239 return tuple(map(int, vers_row[0].split('.'))) |
| 240 except (TypeError, ValueError): |
| 241 return (0,) |
| 242 else: |
| 243 return (0,) |
| OLD | NEW |