| 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 30 matching lines...) Expand all Loading... |
| 41 # connection (and thus thread) should be used. | 41 # connection (and thus thread) should be used. |
| 42 if hasattr(engine, 'optimal_thread_pool_size'): | 42 if hasattr(engine, 'optimal_thread_pool_size'): |
| 43 pool_size = engine.optimal_thread_pool_size | 43 pool_size = engine.optimal_thread_pool_size |
| 44 | 44 |
| 45 threadpool.ThreadPool.__init__(self, | 45 threadpool.ThreadPool.__init__(self, |
| 46 minthreads=1, | 46 minthreads=1, |
| 47 maxthreads=pool_size, | 47 maxthreads=pool_size, |
| 48 name='DBThreadPool') | 48 name='DBThreadPool') |
| 49 self.engine = engine | 49 self.engine = engine |
| 50 if engine.dialect.name == 'sqlite': | 50 if engine.dialect.name == 'sqlite': |
| 51 log.msg("applying SQLite workaround from Buildbot bug #1810") | 51 vers = self.get_sqlite_version() |
| 52 self.__broken_sqlite = self.detect_bug1810() | 52 log.msg("Using SQLite Version %s" % (vers,)) |
| 53 if vers < (3,3,17): |
| 54 log.msg("NOTE: this old version of SQLite does not support " |
| 55 "multiple simultaneous accesses to the database; " |
| 56 "add the 'pool_size=1' argument to your db url") |
| 57 brkn = self.__broken_sqlite = self.detect_bug1810() |
| 58 if brkn: |
| 59 log.msg("Applying SQLite workaround from Buildbot bug #1810") |
| 53 self._start_evt = reactor.callWhenRunning(self._start) | 60 self._start_evt = reactor.callWhenRunning(self._start) |
| 54 | 61 |
| 55 def _start(self): | 62 def _start(self): |
| 56 self._start_evt = None | 63 self._start_evt = None |
| 57 if not self.running: | 64 if not self.running: |
| 58 self.start() | 65 self.start() |
| 59 self._stop_evt = reactor.addSystemEventTrigger( | 66 self._stop_evt = reactor.addSystemEventTrigger( |
| 60 'during', 'shutdown', self._stop) | 67 'during', 'shutdown', self._stop) |
| 61 self.running = True | 68 self.running = True |
| 62 | 69 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 179 |
| 173 try: | 180 try: |
| 174 test() | 181 test() |
| 175 except sqlite.OperationalError: | 182 except sqlite.OperationalError: |
| 176 # this is the expected error indicating it's broken | 183 # this is the expected error indicating it's broken |
| 177 return True | 184 return True |
| 178 | 185 |
| 179 # but this version should not fail.. | 186 # but this version should not fail.. |
| 180 test(select_from_sqlite_master=True) | 187 test(select_from_sqlite_master=True) |
| 181 return False # not broken - no workaround required | 188 return False # not broken - no workaround required |
| 189 |
| 190 def get_sqlite_version(self): |
| 191 engine = sa.create_engine('sqlite://') |
| 192 conn = engine.contextual_connect() |
| 193 |
| 194 try: |
| 195 r = conn.execute("SELECT sqlite_version()") |
| 196 vers_row = r.fetchone() |
| 197 r.close() |
| 198 except: |
| 199 return (0,) |
| 200 |
| 201 if vers_row: |
| 202 try: |
| 203 return tuple(map(int, vers_row[0].split('.'))) |
| 204 except (TypeError, ValueError): |
| 205 return (0,) |
| 206 else: |
| 207 return (0,) |
| OLD | NEW |