mirror of
https://git.yoctoproject.org/poky
synced 2026-04-21 12:32:15 +02:00
bitbake: prserv: avoid possible race condition in database code
Remove a possible race condition by allowing a read-only server to create the PR table anyway. This avoids a failure if both a read-only and read-write server try to access an empty database at the same time. (Bitbake rev: b171caec5ebbe579bf4b8b2005930240ae5c8ce2) Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com> Suggested-by: Joshua Watt <jpewhacker@gmail.com> Cc: Tim Orling <ticotimo@gmail.com> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
65757c9e20
commit
0d6dd343de
@@ -30,21 +30,18 @@ class PRTable(object):
|
||||
self.read_only = read_only
|
||||
self.table = table
|
||||
|
||||
# Creating the table even if the server is read-only.
|
||||
# This avoids a race condition if a shared database
|
||||
# is accessed by a read-only server first.
|
||||
|
||||
with closing(self.conn.cursor()) as cursor:
|
||||
if self.read_only:
|
||||
table_exists = cursor.execute(
|
||||
"SELECT count(*) FROM sqlite_master \
|
||||
WHERE type='table' AND name='%s'" % (self.table))
|
||||
if not table_exists:
|
||||
raise prserv.NotFoundError
|
||||
else:
|
||||
cursor.execute("CREATE TABLE IF NOT EXISTS %s \
|
||||
(version TEXT NOT NULL, \
|
||||
pkgarch TEXT NOT NULL, \
|
||||
checksum TEXT NOT NULL, \
|
||||
value TEXT, \
|
||||
PRIMARY KEY (version, pkgarch, checksum, value));" % self.table)
|
||||
self.conn.commit()
|
||||
cursor.execute("CREATE TABLE IF NOT EXISTS %s \
|
||||
(version TEXT NOT NULL, \
|
||||
pkgarch TEXT NOT NULL, \
|
||||
checksum TEXT NOT NULL, \
|
||||
value TEXT, \
|
||||
PRIMARY KEY (version, pkgarch, checksum, value));" % self.table)
|
||||
self.conn.commit()
|
||||
|
||||
def _extremum_value(self, rows, is_max):
|
||||
value = None
|
||||
|
||||
Reference in New Issue
Block a user