changeset 1518:09476d758b59

maps: handle sqlite lock error triggered by PRAGMA statements "self._db.execute('PRAGMA cache_size=%d' % (-cachesize))" could raise "OperationalError: database is locked". Therefore move PRAGMA statements inside "self._transaction" which handles the "locked" error automatically.
author Jun Wu <quark@fb.com>
date Fri, 11 Aug 2017 09:24:29 -0700
parents b3e41b0d50a2
children aec176db232c
files hgsubversion/maps.py
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/maps.py
+++ b/hgsubversion/maps.py
@@ -726,18 +726,19 @@ class SqliteRevMap(collections.MutableMa
         for path, ratio in [(self._filepath, 1.7), (self._dbpath, 1)]:
             if os.path.exists(path):
                 cachesize += os.stat(path).st_size * ratio // 1000
-        self._db.execute('PRAGMA cache_size=%d' % (-cachesize))
-
-        # PRAGMA statements provided by the user
-        for pragma in (self._sqlitepragmas or []):
-            # drop malicious ones
-            if re.match(r'\A\w+=\w+\Z', pragma):
-                self._db.execute('PRAGMA %s' % pragma)
 
         # disable auto-commit. everything is inside a transaction
         self._db.isolation_level = 'DEFERRED'
 
         with self._transaction('EXCLUSIVE'):
+            self._db.execute('PRAGMA cache_size=%d' % (-cachesize))
+
+            # PRAGMA statements provided by the user
+            for pragma in (self._sqlitepragmas or []):
+                # drop malicious ones
+                if re.match(r'\A\w+=\w+\Z', pragma):
+                    self._db.execute('PRAGMA %s' % pragma)
+
             map(self._db.execute, self.TABLESCHEMA)
             if version == RevMap.VERSION:
                 self.rowcount = 0