Skip to contentSkip to conversation

hashserv: sqlite: Ensure sync propagates to database connections

PATCH New Joshua Watt 1 participant 1 message Dec 4, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hashserv: sqlite: Ensure sync propagates to database connections

When the sqlite database backend was restructured, the code to make the databases run in WAL mode and to control if sync() is called was accidentally dropped. This caused terrible database performance to the point that server timeouts were occurring causing really slow builds.

Fix this by properly enabling WAL mode and setting the synchronous flag as requested

---
 bitbake/lib/hashserv/sqlite.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
bitbake/lib/hashserv/sqlite.py +7 -2
index f65036be939..f93cb2c1dd9 100644
@@ -109,11 +109,11 @@ class DatabaseEngine(object):
             )
 
     def connect(self, logger):
-        return Database(logger, self.dbname)
+        return Database(logger, self.dbname, self.sync)
 
 
 class Database(object):
-    def __init__(self, logger, dbname, sync=True):
+    def __init__(self, logger, dbname, sync):
         self.dbname = dbname
         self.logger = logger
 
@@ -121,6 +121,11 @@ class Database(object):
         self.db.row_factory = sqlite3.Row
 
         with closing(self.db.cursor()) as cursor:
+            cursor.execute("PRAGMA journal_mode = WAL")
+            cursor.execute(
+                "PRAGMA synchronous = %s" % ("NORMAL" if sync else "OFF")
+            )
+
             cursor.execute("SELECT sqlite_version()")
 
             version = []
Signature · 1 line
2.34.1