diff options
author | Paul Barker <pbarker@konsulko.com> | 2021-02-05 11:26:11 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-02-09 15:57:52 +0000 |
commit | 2be4f7f0d2ccb09917398289e8140e1467e84bb2 (patch) | |
tree | d9c682edcff7e2b82420adfbfb0ad3e9c39cda44 /lib/hashserv | |
parent | 921199a4923ce383b27e23c9b7e34eb785c8bae3 (diff) | |
download | bitbake-2be4f7f0d2ccb09917398289e8140e1467e84bb2.tar.gz |
hashserv: server: Support searching upstream for outhash
Use the new get-outhash message to perform a read-only query against an
upstream server (if present) when a reported taskhash/outhash
combination is not found in the current database. If a matching entry is
found upstream it is copied into the current database so it can be found
by future queries.
Signed-off-by: Paul Barker <pbarker@konsulko.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/hashserv')
-rw-r--r-- | lib/hashserv/server.py | 20 | ||||
-rw-r--r-- | lib/hashserv/tests.py | 12 |
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/hashserv/server.py b/lib/hashserv/server.py index 2770c2360..9ade988e5 100644 --- a/lib/hashserv/server.py +++ b/lib/hashserv/server.py @@ -130,6 +130,18 @@ async def copy_from_upstream(client, db, method, taskhash): d = {k: v for k, v in d.items() if k in TABLE_COLUMNS} keys = sorted(d.keys()) + with closing(db.cursor()) as cursor: + insert_task(cursor, d) + db.commit() + + return d + +async def copy_outhash_from_upstream(client, db, method, outhash, taskhash): + d = await client.get_outhash(method, outhash, taskhash) + if d is not None: + # Filter out unknown columns + d = {k: v for k, v in d.items() if k in TABLE_COLUMNS} + keys = sorted(d.keys()) with closing(db.cursor()) as cursor: insert_task(cursor, d) @@ -359,6 +371,14 @@ class ServerClient(object): row = cursor.fetchone() + if row is None and self.upstream_client: + # Try upstream + row = await copy_outhash_from_upstream(self.upstream_client, + self.db, + data['method'], + data['outhash'], + data['taskhash']) + # If no matching outhash was found, or one *was* found but it # wasn't an exact match on the taskhash, a new entry for this # taskhash should be added diff --git a/lib/hashserv/tests.py b/lib/hashserv/tests.py index 6f04e30d6..1a696481e 100644 --- a/lib/hashserv/tests.py +++ b/lib/hashserv/tests.py @@ -246,6 +246,18 @@ class HashEquivalenceCommonTests(object): self.assertClientGetHash(side_client, taskhash4, unihash4) self.assertClientGetHash(self.client, taskhash4, None) + # Test that reporting a unihash in the downstream is able to find a + # match which was previously reported to the upstream server + taskhash5 = '35788efcb8dfb0a02659d81cf2bfd695fb30faf9' + outhash5 = '2765d4a5884be49b28601445c2760c5f21e7e5c0ee2b7e3fce98fd7e5970796f' + unihash5 = 'f46d3fbb439bd9b921095da657a4de906510d2cd' + result = self.client.report_unihash(taskhash5, self.METHOD, outhash5, unihash5) + + taskhash6 = '35788efcb8dfb0a02659d81cf2bfd695fb30fafa' + unihash6 = 'f46d3fbb439bd9b921095da657a4de906510d2ce' + result = down_client.report_unihash(taskhash6, self.METHOD, outhash5, unihash6) + self.assertEqual(result['unihash'], unihash5, 'Server failed to copy unihash from upstream') + def test_ro_server(self): (ro_client, ro_server) = self.start_server(dbpath=self.server.dbpath, read_only=True) |