diff mbox series

[bitbake-devel,RFC] prserv: Enable database sharing

Message ID 20240423182543.226113-1-JPEWhacker@gmail.com
State New
Headers show
Series [bitbake-devel,RFC] prserv: Enable database sharing | expand

Commit Message

Joshua Watt April 23, 2024, 6:25 p.m. UTC
sqlite3 can allow multiple processes to access the database
simultaneously, but it must be opened correctly. The key change is that
the database is no longer opened in "exclusive" mode (defaulting to
shared mode). In addition, the journal is set to "WAL" mode, as this is
the most efficient for dealing with simultaneous access between
different processes. In order to keep the database performance,
synchronous mode is set to "off". The WAL journal will protect against
incomplete transactions in any given client, however the database will
not be protected against unexpected power loss from the OS (which is a
fine trade off for performance, and also the same as the previous

Finally, the _execute() API now uses a database cursor. The cursor
automatically makes sure that the query happens in an atomic transaction
and commits when finished.

NOTE: THIS MAY BE INCOMPLETE; All APIs need to be evaluated to see if
the transaction (cursor) needs to cover mode than one "execute"

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
 bitbake/lib/prserv/db.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff mbox series


diff --git a/bitbake/lib/prserv/db.py b/bitbake/lib/prserv/db.py
index b4bda7078cd..e7a2d27e950 100644
--- a/bitbake/lib/prserv/db.py
+++ b/bitbake/lib/prserv/db.py
@@ -292,11 +292,10 @@  class PRData(object):
                 raise e
         uri = "file:%s%s" % (self.filename, "?mode=ro" if self.read_only else "")
         logger.debug("Opening PRServ database '%s'" % (uri))
-        self.connection=sqlite3.connect(uri, uri=True, isolation_level="EXCLUSIVE", check_same_thread = False)
+        self.connection=sqlite3.connect(uri, uri=True)
-        if not self.read_only:
-            self.connection.execute("pragma synchronous = off;")
-            self.connection.execute("PRAGMA journal_mode = MEMORY;")
+        self.connection.execute("pragma synchronous = off;")
+        self.connection.execute("PRAGMA journal_mode = WAL;")
     def disconnect(self):