diff options
author | Michael Opdenacker <michael.opdenacker@bootlin.com> | 2024-05-11 16:31:32 +0530 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-05-21 14:23:43 +0100 |
commit | 0d6dd343dee916c9d446e7c3e43aeca3c466f22c (patch) | |
tree | d0c1c974629dcb804448a551625aebf821d165f0 /bitbake | |
parent | 65757c9e200cb34b39a87f3a8c2a8f8665a81677 (diff) | |
download | poky-0d6dd343dee916c9d446e7c3e43aeca3c466f22c.tar.gz |
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>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/prserv/db.py | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/bitbake/lib/prserv/db.py b/bitbake/lib/prserv/db.py index f430586d73..79c9001bf5 100644 --- a/bitbake/lib/prserv/db.py +++ b/bitbake/lib/prserv/db.py | |||
@@ -30,21 +30,18 @@ class PRTable(object): | |||
30 | self.read_only = read_only | 30 | self.read_only = read_only |
31 | self.table = table | 31 | self.table = table |
32 | 32 | ||
33 | # Creating the table even if the server is read-only. | ||
34 | # This avoids a race condition if a shared database | ||
35 | # is accessed by a read-only server first. | ||
36 | |||
33 | with closing(self.conn.cursor()) as cursor: | 37 | with closing(self.conn.cursor()) as cursor: |
34 | if self.read_only: | 38 | cursor.execute("CREATE TABLE IF NOT EXISTS %s \ |
35 | table_exists = cursor.execute( | 39 | (version TEXT NOT NULL, \ |
36 | "SELECT count(*) FROM sqlite_master \ | 40 | pkgarch TEXT NOT NULL, \ |
37 | WHERE type='table' AND name='%s'" % (self.table)) | 41 | checksum TEXT NOT NULL, \ |
38 | if not table_exists: | 42 | value TEXT, \ |
39 | raise prserv.NotFoundError | 43 | PRIMARY KEY (version, pkgarch, checksum, value));" % self.table) |
40 | else: | 44 | self.conn.commit() |
41 | cursor.execute("CREATE TABLE IF NOT EXISTS %s \ | ||
42 | (version TEXT NOT NULL, \ | ||
43 | pkgarch TEXT NOT NULL, \ | ||
44 | checksum TEXT NOT NULL, \ | ||
45 | value TEXT, \ | ||
46 | PRIMARY KEY (version, pkgarch, checksum, value));" % self.table) | ||
47 | self.conn.commit() | ||
48 | 45 | ||
49 | def _extremum_value(self, rows, is_max): | 46 | def _extremum_value(self, rows, is_max): |
50 | value = None | 47 | value = None |