stablerange: clarify sql transaction logic
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 21 Dec 2017 03:42:54 +0100
changeset 3347 ab5172ba3c81
parent 3346 f4e28b781143
child 3348 895e16385a4f
stablerange: clarify sql transaction logic This should help concurrent access.
hgext3rd/evolve/stablerangecache.py
--- a/hgext3rd/evolve/stablerangecache.py	Thu Dec 21 03:30:13 2017 +0100
+++ b/hgext3rd/evolve/stablerangecache.py	Thu Dec 21 03:42:54 2017 +0100
@@ -193,6 +193,7 @@
             con = self._db()
             if con is None:
                 return
+            con.execute('BEGIN IMMEDIATE;')
             with con:
                 for req in _sqliteschema:
                     con.execute(req)
@@ -204,6 +205,7 @@
                 con.execute(_newmeta, meta)
         else:
             con = self._con
+            con.execute('BEGIN IMMEDIATE;')
             meta = con.execute(_querymeta).fetchone()
             if meta[2] != self._ondisktipnode or meta[1] != self._ondisktiprev:
                 # drifting is currently an issue because this means another
@@ -215,6 +217,7 @@
                 data = (meta[2], meta[1], self._ondisktiprev, self._ondisktipnode)
                 repo.ui.warn(msg)
                 repo.ui.warn(hint % data)
+                con.execute('ROLLBACK;')
                 return
             meta = [self._tiprev,
                     self._tipnode,