summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Shelton <ben.shelton@ni.com>2014-10-27 12:27:23 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-12-31 10:09:50 +0000
commit973ac2cc63323ca9c3e916effa4765747db3564c (patch)
tree894a9b58698f97ae09bae5772c482b4e8f51ec40
parentd412d3680f78eebe0517e4f933d853b8973df711 (diff)
downloadbitbake-973ac2cc63323ca9c3e916effa4765747db3564c.tar.gz
prserv: don't wait until exit to sync
In the commit 'prserv: Ensure data is committed', the PR server moved to only committing transactions to the database when the PR server is stopped. This improves performance, but it means that if the machine running the PR server loses power unexpectedly or if the PR server process gets SIGKILL, the uncommitted package revision data is lost. To fix this issue, sync the database periodically, once per 30 seconds by default, if it has been marked as dirty. To be safe, continue to sync the database at exit regardless of its status. Signed-off-by: Ben Shelton <ben.shelton@ni.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/prserv/db.py14
-rw-r--r--lib/prserv/serv.py7
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/prserv/db.py b/lib/prserv/db.py
index 49f36da1a..3bdc04692 100644
--- a/lib/prserv/db.py
+++ b/lib/prserv/db.py
@@ -19,6 +19,7 @@ class PRTable(object):
def __init__(self, conn, table, nohist):
self.conn = conn
self.nohist = nohist
+ self.dirty = False
if nohist:
self.table = "%s_nohist" % table
else:
@@ -47,6 +48,11 @@ class PRTable(object):
self.conn.commit()
self._execute("BEGIN EXCLUSIVE TRANSACTION")
+ def sync_if_dirty(self):
+ if self.dirty:
+ self.sync()
+ self.dirty = False
+
def _getValueHist(self, version, pkgarch, checksum):
data=self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
(version, pkgarch, checksum))
@@ -62,6 +68,8 @@ class PRTable(object):
except sqlite3.IntegrityError as exc:
logger.error(str(exc))
+ self.dirty = True
+
data=self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
(version, pkgarch, checksum))
row=data.fetchone()
@@ -89,6 +97,8 @@ class PRTable(object):
logger.error(str(exc))
self.conn.rollback()
+ self.dirty = True
+
data=self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
(version, pkgarch, checksum))
row=data.fetchone()
@@ -118,6 +128,8 @@ class PRTable(object):
except sqlite3.IntegrityError as exc:
logger.error(str(exc))
+ self.dirty = True
+
data = self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=?;" % self.table,
(version, pkgarch, checksum))
row = data.fetchone()
@@ -139,6 +151,8 @@ class PRTable(object):
except sqlite3.IntegrityError as exc:
logger.error(str(exc))
+ self.dirty = True
+
data = self._execute("SELECT value FROM %s WHERE version=? AND pkgarch=? AND checksum=? AND value>=?;" % self.table,
(version,pkgarch,checksum,value))
row=data.fetchone()
diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index 1b08d5913..6ab10972e 100644
--- a/lib/prserv/serv.py
+++ b/lib/prserv/serv.py
@@ -122,6 +122,10 @@ class PRServer(SimpleXMLRPCServer):
def work_forever(self,):
self.quit = False
self.timeout = 0.5
+ iter_count = 1
+ # With 60 iterations between syncs and a 0.5 second timeout between
+ # iterations, this will sync if dirty every ~30 seconds.
+ iterations_between_sync = 60
logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" %
(self.dbfile, self.host, self.port, str(os.getpid())))
@@ -129,6 +133,9 @@ class PRServer(SimpleXMLRPCServer):
self.handlerthread.start()
while not self.quit:
self.handle_request()
+ iter_count = (iter_count + 1) % iterations_between_sync
+ if iter_count == 0:
+ self.table.sync_if_dirty()
self.table.sync()
logger.info("PRServer: stopping...")