summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/prserv/db.py
diff options
context:
space:
mode:
authorHaris Okanovic <haris.okanovic@ni.com>2016-02-23 11:36:33 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-26 17:20:31 +0000
commit4a12865c7b8a534ac7f7c1380c549c5392eda5f5 (patch)
treead64bde4abc6136bf966418bb52551216764f829 /bitbake/lib/prserv/db.py
parentbdb51abb3ccedacb0c409b9ae702000170660f44 (diff)
downloadpoky-4a12865c7b8a534ac7f7c1380c549c5392eda5f5.tar.gz
bitbake: prserv: Add dump_db()
Returns a script (string) that reconstructs the state of the entire database at the time this function is called. The script language is defined by the backing database engine, which is a function of server configuration. Returns None if the database engine does not support dumping to script or if some other error is encountered in processing. The SQLite3 implementation in db.py calls iterdump() [1] to generate a script. iterdump() is the library equivalent of the `sqlite3 .dump` shell command, and the scripts are compatible. Execute the script in an empty SQLite3 database using the sqlite3 utility to restore a backup of prserv. Use case: Backup a live PR server database in a non-racy way, such that one could snapshot the entire database after a set of bitbake builds all using a shared server. I.e. All changes made prior to the start of a dump_db() operation should be committed and captured in the script. Subsequent changes made during the backup process are not guaranteed to be captured. Testing: ~7MB database backs up in ~1s while PR server is under load from 32 thread bitbake builds on two separate machines. [1] https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.iterdump (Bitbake rev: 004003daf6bd0f0233ce5c2d95f1d7d64ab91bb3) Signed-off-by: Haris Okanovic <haris.okanovic@ni.com> Reviewed-by: Ken Sharp <ken.sharp@ni.com> Reviewed-by: Bill Pittman <bill.pittman@ni.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/prserv/db.py')
-rw-r--r--bitbake/lib/prserv/db.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/bitbake/lib/prserv/db.py b/bitbake/lib/prserv/db.py
index 36c9f7b630..2a86184170 100644
--- a/bitbake/lib/prserv/db.py
+++ b/bitbake/lib/prserv/db.py
@@ -231,6 +231,14 @@ class PRTable(object):
231 datainfo.append(col) 231 datainfo.append(col)
232 return (metainfo, datainfo) 232 return (metainfo, datainfo)
233 233
234 def dump_db(self, fd):
235 writeCount = 0
236 for line in self.conn.iterdump():
237 writeCount = writeCount + len(line) + 1
238 fd.write(line)
239 fd.write('\n')
240 return writeCount
241
234class PRData(object): 242class PRData(object):
235 """Object representing the PR database""" 243 """Object representing the PR database"""
236 def __init__(self, filename, nohist=True): 244 def __init__(self, filename, nohist=True):