add build architecture to schema of depstate table
authorHelmut Grohne <helmut@subdivi.de>
Thu, 8 Oct 2020 15:16:06 +0000 (17:16 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Thu, 8 Oct 2020 15:16:06 +0000 (17:16 +0200)
build.py
depcheck.py
schema.sql
webapp.py

index 5e2ee85..9bfa52c 100755 (executable)
--- a/build.py
+++ b/build.py
@@ -59,29 +59,30 @@ def main():
     with contextlib.closing(db.cursor()) as cur:
         cur.execute("BEGIN IMMEDIATE;")
         cur.execute("""
-            SELECT d.source, d.version, d.architecture, r.id
+            SELECT d.source, d.version, d.hostarch, r.id
                 FROM depstate AS d
                     JOIN buildrequests AS r
-                        ON ? = ifnull(r.buildarch, 'amd64')
-                            AND d.architecture = ifnull(r.hostarch, d.architecture)
+                        ON ? = ifnull(r.buildarch, d.buildarch)
+                            AND d.hostarch = ifnull(r.hostarch, d.hostarch)
                             AND d.source = r.source
                     JOIN depcheck
-                        ON d.architecture = depcheck.architecture
+                        ON d.hostarch = depcheck.architecture
                 WHERE d.satisfiable = 1 AND depcheck.giveback = 0
                     AND NOT EXISTS (SELECT 1 FROM building
                         WHERE d.source = building.source
                             OR (? = building.buildarch AND
-                                d.architecture = building.hostarch))
+                                d.hostarch = building.hostarch))
                 ORDER BY r.priority DESC, r.requesttime ASC, random()
                 LIMIT 1;""", (buildarch, buildarch))
         row = cur.fetchone()
         if not row:
             cur.execute("""
-                SELECT source, version, depstate.architecture, NULL
+                SELECT source, version, depstate.hostarch, NULL
                     FROM depstate JOIN depcheck
-                        ON depstate.architecture = depcheck.architecture
-                    WHERE satisfiable = 1 AND giveback = 0
-                    ORDER BY random() LIMIT 1;""")
+                        ON depstate.hostarch = depcheck.architecture
+                    WHERE depstate.buildarch = ? AND satisfiable = 1
+                        AND giveback = 0
+                    ORDER BY random() LIMIT 1;""", (buildarch,))
             row = cur.fetchone()
         if not row:
             cur.execute("ROLLBACK;")
index ad0a18d..b1f7458 100755 (executable)
@@ -415,24 +415,34 @@ def check_bdsat(mirror, buildarch, hostarch):
     return result
 
 
-def update_depcheck(mirror, db, updatetime, architecture, state):
+def update_depcheck(mirror, db, updatetime, buildarch, hostarch, state):
     with contextlib.closing(db.cursor()) as cur:
         cur.execute("BEGIN;")
-        cur.execute("SELECT source, version, satisfiable, reason FROM depstate WHERE architecture = ?;",
-                    (architecture,))
+        cur.execute("""
+            SELECT source, version, satisfiable, reason FROM depstate
+                WHERE buildarch = ? AND hostarch = ?;""",
+                    (buildarch, hostarch,))
         for source, version, satisfiable, reason in list(cur.fetchall()):
             if satisfiable == (reason is None) and \
                state.get(source) == (version, reason):
                 del state[source]
             else:
-                cur.execute("DELETE FROM depstate WHERE source = ? AND version = ? AND architecture = ?;",
-                            (source, version, architecture))
-        cur.executemany("INSERT INTO depstate (source, architecture, version, satisfiable, reason) VALUES (?, ?, ?, ?, ?);",
-                        ((source, architecture, version, reason is None,
+                cur.execute("""
+                    DELETE FROM depstate
+                        WHERE source = ? AND version = ? AND buildarch = ?
+                            AND hostarch = ?;""",
+                            (source, version, buildarch, hostarch))
+        cur.executemany("""
+            INSERT INTO depstate (source, buildarch, hostarch, version,
+                                  satisfiable, reason)
+                VALUES (?, ?, ?, ?, ?, ?);""",
+                        ((source, buildarch, hostarch, version, reason is None,
                           reason)
                          for source, (version, reason) in state.items()))
-        cur.execute("UPDATE depcheck SET releasetime = ?, updatetime = ?, giveback = 0 WHERE architecture = ?",
-                    (mirror.releasetime, updatetime, architecture))
+        cur.execute("""
+            UPDATE depcheck SET releasetime = ?, updatetime = ?, giveback = 0
+                WHERE architecture = ?""",
+                    (mirror.releasetime, updatetime, hostarch))
     db.commit()
 
 
@@ -476,7 +486,8 @@ def main():
         try:
             for architecture, state in pool.imap_unordered(docheck, archs):
                 print("update %s" % architecture)
-                update_depcheck(mirror, db, now, architecture, state)
+                update_depcheck(mirror, db, now, BUILD_ARCH, architecture,
+                                state)
         finally:
             pool.close()
             pool.join()
index 1c2a2ec..7c591c9 100644 (file)
@@ -3,10 +3,11 @@
 CREATE TABLE depstate (
        source TEXT NOT NULL,
        version TEXT NOT NULL,
-       architecture TEXT NOT NULL,
+       buildarch TEXT NOT NULL,
+       hostarch TEXT NOT NULL,
        satisfiable BOOLEAN NOT NULL CHECK (satisfiable in (0, 1)),
        reason TEXT,
-       UNIQUE (source, architecture, version));
+       UNIQUE (source, buildarch, hostarch, version));
 
 CREATE TABLE depcheck (
        architecture TEXT NOT NULL UNIQUE,
index 794af29..03d37b3 100644 (file)
--- a/webapp.py
+++ b/webapp.py
@@ -350,8 +350,7 @@ def collect_depstate(conn, source):
     version = None
     depstate = None
     query = sqlalchemy.text("""
-        SELECT version, 'amd64' AS buildarch, architecture AS hostarch,
-               satisfiable, reason
+        SELECT version, buildarch, hostarch, satisfiable, reason
             FROM depstate WHERE source = :source;""")
     for row in conn.execute(query, source=source):
         if version is None or version_compare(version, row.version) > 0: