diff options
| author | Joshua Watt <JPEWhacker@gmail.com> | 2023-10-06 09:36:41 -0600 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-10-09 15:48:44 +0100 |
| commit | 61f5c323082d814df8a19aa08300f3c47b0a6b1a (patch) | |
| tree | 005077bdd97f924f8ad562b7c341880b435584bc /bitbake/lib | |
| parent | 561c63e94710a755227357e90004aafa63ec9c7e (diff) | |
| download | poky-61f5c323082d814df8a19aa08300f3c47b0a6b1a.tar.gz | |
bitbake: hashserv: Add remove API
Adds a `remove` API to the client and server that can be used to remove
hash equivalence entries that match a particular critera
(Bitbake rev: 861d068b3a9fb5e91a01dbec54996a5a6f93ef29)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
| -rw-r--r-- | bitbake/lib/hashserv/client.py | 5 | ||||
| -rw-r--r-- | bitbake/lib/hashserv/server.py | 28 | ||||
| -rw-r--r-- | bitbake/lib/hashserv/tests.py | 33 |
3 files changed, 66 insertions, 0 deletions
diff --git a/bitbake/lib/hashserv/client.py b/bitbake/lib/hashserv/client.py index b2aa1026ac..7446e4c9f6 100644 --- a/bitbake/lib/hashserv/client.py +++ b/bitbake/lib/hashserv/client.py | |||
| @@ -101,6 +101,10 @@ class AsyncClient(bb.asyncrpc.AsyncClient): | |||
| 101 | await self._set_mode(self.MODE_NORMAL) | 101 | await self._set_mode(self.MODE_NORMAL) |
| 102 | return (await self.send_message({"backfill-wait": None}))["tasks"] | 102 | return (await self.send_message({"backfill-wait": None}))["tasks"] |
| 103 | 103 | ||
| 104 | async def remove(self, where): | ||
| 105 | await self._set_mode(self.MODE_NORMAL) | ||
| 106 | return await self.send_message({"remove": {"where": where}}) | ||
| 107 | |||
| 104 | 108 | ||
| 105 | class Client(bb.asyncrpc.Client): | 109 | class Client(bb.asyncrpc.Client): |
| 106 | def __init__(self): | 110 | def __init__(self): |
| @@ -115,6 +119,7 @@ class Client(bb.asyncrpc.Client): | |||
| 115 | "get_stats", | 119 | "get_stats", |
| 116 | "reset_stats", | 120 | "reset_stats", |
| 117 | "backfill_wait", | 121 | "backfill_wait", |
| 122 | "remove", | ||
| 118 | ) | 123 | ) |
| 119 | 124 | ||
| 120 | def _get_async_client(self): | 125 | def _get_async_client(self): |
diff --git a/bitbake/lib/hashserv/server.py b/bitbake/lib/hashserv/server.py index d40a2ab8f8..daf1ffacbb 100644 --- a/bitbake/lib/hashserv/server.py +++ b/bitbake/lib/hashserv/server.py | |||
| @@ -186,6 +186,7 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection): | |||
| 186 | 'report-equiv': self.handle_equivreport, | 186 | 'report-equiv': self.handle_equivreport, |
| 187 | 'reset-stats': self.handle_reset_stats, | 187 | 'reset-stats': self.handle_reset_stats, |
| 188 | 'backfill-wait': self.handle_backfill_wait, | 188 | 'backfill-wait': self.handle_backfill_wait, |
| 189 | 'remove': self.handle_remove, | ||
| 189 | }) | 190 | }) |
| 190 | 191 | ||
| 191 | def validate_proto_version(self): | 192 | def validate_proto_version(self): |
| @@ -499,6 +500,33 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection): | |||
| 499 | await self.backfill_queue.join() | 500 | await self.backfill_queue.join() |
| 500 | self.write_message(d) | 501 | self.write_message(d) |
| 501 | 502 | ||
| 503 | async def handle_remove(self, request): | ||
| 504 | condition = request["where"] | ||
| 505 | if not isinstance(condition, dict): | ||
| 506 | raise TypeError("Bad condition type %s" % type(condition)) | ||
| 507 | |||
| 508 | def do_remove(columns, table_name, cursor): | ||
| 509 | nonlocal condition | ||
| 510 | where = {} | ||
| 511 | for c in columns: | ||
| 512 | if c in condition and condition[c] is not None: | ||
| 513 | where[c] = condition[c] | ||
| 514 | |||
| 515 | if where: | ||
| 516 | query = ('DELETE FROM %s WHERE ' % table_name) + ' AND '.join("%s=:%s" % (k, k) for k in where.keys()) | ||
| 517 | cursor.execute(query, where) | ||
| 518 | return cursor.rowcount | ||
| 519 | |||
| 520 | return 0 | ||
| 521 | |||
| 522 | count = 0 | ||
| 523 | with closing(self.db.cursor()) as cursor: | ||
| 524 | count += do_remove(OUTHASH_TABLE_COLUMNS, "outhashes_v2", cursor) | ||
| 525 | count += do_remove(UNIHASH_TABLE_COLUMNS, "unihashes_v2", cursor) | ||
| 526 | self.db.commit() | ||
| 527 | |||
| 528 | self.write_message({"count": count}) | ||
| 529 | |||
| 502 | def query_equivalent(self, cursor, method, taskhash): | 530 | def query_equivalent(self, cursor, method, taskhash): |
| 503 | # This is part of the inner loop and must be as fast as possible | 531 | # This is part of the inner loop and must be as fast as possible |
| 504 | cursor.execute( | 532 | cursor.execute( |
diff --git a/bitbake/lib/hashserv/tests.py b/bitbake/lib/hashserv/tests.py index f6b85aed85..a3e066406e 100644 --- a/bitbake/lib/hashserv/tests.py +++ b/bitbake/lib/hashserv/tests.py | |||
| @@ -84,6 +84,7 @@ class HashEquivalenceCommonTests(object): | |||
| 84 | 84 | ||
| 85 | result = self.client.report_unihash(taskhash, self.METHOD, outhash, unihash) | 85 | result = self.client.report_unihash(taskhash, self.METHOD, outhash, unihash) |
| 86 | self.assertEqual(result['unihash'], unihash, 'Server returned bad unihash') | 86 | self.assertEqual(result['unihash'], unihash, 'Server returned bad unihash') |
| 87 | return taskhash, outhash, unihash | ||
| 87 | 88 | ||
| 88 | def test_create_equivalent(self): | 89 | def test_create_equivalent(self): |
| 89 | # Tests that a second reported task with the same outhash will be | 90 | # Tests that a second reported task with the same outhash will be |
| @@ -125,6 +126,38 @@ class HashEquivalenceCommonTests(object): | |||
| 125 | 126 | ||
| 126 | self.assertClientGetHash(self.client, taskhash, unihash) | 127 | self.assertClientGetHash(self.client, taskhash, unihash) |
| 127 | 128 | ||
| 129 | def test_remove_taskhash(self): | ||
| 130 | taskhash, outhash, unihash = self.test_create_hash() | ||
| 131 | result = self.client.remove({"taskhash": taskhash}) | ||
| 132 | self.assertGreater(result["count"], 0) | ||
| 133 | self.assertClientGetHash(self.client, taskhash, None) | ||
| 134 | |||
| 135 | result_outhash = self.client.get_outhash(self.METHOD, outhash, taskhash) | ||
| 136 | self.assertIsNone(result_outhash) | ||
| 137 | |||
| 138 | def test_remove_unihash(self): | ||
| 139 | taskhash, outhash, unihash = self.test_create_hash() | ||
| 140 | result = self.client.remove({"unihash": unihash}) | ||
| 141 | self.assertGreater(result["count"], 0) | ||
| 142 | self.assertClientGetHash(self.client, taskhash, None) | ||
| 143 | |||
| 144 | def test_remove_outhash(self): | ||
| 145 | taskhash, outhash, unihash = self.test_create_hash() | ||
| 146 | result = self.client.remove({"outhash": outhash}) | ||
| 147 | self.assertGreater(result["count"], 0) | ||
| 148 | |||
| 149 | result_outhash = self.client.get_outhash(self.METHOD, outhash, taskhash) | ||
| 150 | self.assertIsNone(result_outhash) | ||
| 151 | |||
| 152 | def test_remove_method(self): | ||
| 153 | taskhash, outhash, unihash = self.test_create_hash() | ||
| 154 | result = self.client.remove({"method": self.METHOD}) | ||
| 155 | self.assertGreater(result["count"], 0) | ||
| 156 | self.assertClientGetHash(self.client, taskhash, None) | ||
| 157 | |||
| 158 | result_outhash = self.client.get_outhash(self.METHOD, outhash, taskhash) | ||
| 159 | self.assertIsNone(result_outhash) | ||
| 160 | |||
| 128 | def test_huge_message(self): | 161 | def test_huge_message(self): |
| 129 | # Simple test that hashes can be created | 162 | # Simple test that hashes can be created |
| 130 | taskhash = 'c665584ee6817aa99edfc77a44dd853828279370' | 163 | taskhash = 'c665584ee6817aa99edfc77a44dd853828279370' |
