summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/hashserv/client.py
diff options
context:
space:
mode:
authorAlexandre Marques <c137.marques@gmail.com>2025-03-12 11:22:04 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-03-13 16:52:44 +0000
commita4f833698289da86138fd4a401331baa563b5eed (patch)
tree3bcdd9688aaa9dbec6d2002a351196bbcb4d58b0 /bitbake/lib/hashserv/client.py
parentcb9bff9eac3670253076d5d09c6893e372be40a8 (diff)
downloadpoky-a4f833698289da86138fd4a401331baa563b5eed.tar.gz
bitbake: hashserv: Add `gc-mark-stream` command for batch hash marking
Implements the `gc-mark-stream` command to allow for marking equivalence entries in batch, by making use of stream mode communication to the server. The aim of this is to improve efficiency by reducing the impact of latency when marking a high volume of hash entries. Example usage of the new `gc-mark-stream` command: ``` $ cat << HASHES | \ ./bin/bitbake-hashclient --address "ws://localhost:8688/ws" gc-mark-stream "alive" unihash f37918cc02eb5a520b1aff86faacbc0a38124646 unihash af36b199320e611fbb16f1f277d3ee1d619ca58b taskhash a1117c1f5a7c9ab2f5a39cc6fe5e6152169d09c0 method oe.sstatesig.OEOuthashBasic HASHES ``` (Bitbake rev: c84715f28cd36666ea07a179d91b8c32ea0df8e7) Signed-off-by: Alexander Marques <c137.marques@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/hashserv/client.py')
-rw-r--r--bitbake/lib/hashserv/client.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/bitbake/lib/hashserv/client.py b/bitbake/lib/hashserv/client.py
index a510f3284f..8cb18050a6 100644
--- a/bitbake/lib/hashserv/client.py
+++ b/bitbake/lib/hashserv/client.py
@@ -78,6 +78,7 @@ class AsyncClient(bb.asyncrpc.AsyncClient):
78 MODE_NORMAL = 0 78 MODE_NORMAL = 0
79 MODE_GET_STREAM = 1 79 MODE_GET_STREAM = 1
80 MODE_EXIST_STREAM = 2 80 MODE_EXIST_STREAM = 2
81 MODE_MARK_STREAM = 3
81 82
82 def __init__(self, username=None, password=None): 83 def __init__(self, username=None, password=None):
83 super().__init__("OEHASHEQUIV", "1.1", logger) 84 super().__init__("OEHASHEQUIV", "1.1", logger)
@@ -164,6 +165,8 @@ class AsyncClient(bb.asyncrpc.AsyncClient):
164 await normal_to_stream("get-stream") 165 await normal_to_stream("get-stream")
165 elif new_mode == self.MODE_EXIST_STREAM: 166 elif new_mode == self.MODE_EXIST_STREAM:
166 await normal_to_stream("exists-stream") 167 await normal_to_stream("exists-stream")
168 elif new_mode == self.MODE_MARK_STREAM:
169 await normal_to_stream("gc-mark-stream")
167 elif new_mode != self.MODE_NORMAL: 170 elif new_mode != self.MODE_NORMAL:
168 raise Exception("Undefined mode transition {self.mode!r} -> {new_mode!r}") 171 raise Exception("Undefined mode transition {self.mode!r} -> {new_mode!r}")
169 172
@@ -306,6 +309,24 @@ class AsyncClient(bb.asyncrpc.AsyncClient):
306 """ 309 """
307 return await self.invoke({"gc-mark": {"mark": mark, "where": where}}) 310 return await self.invoke({"gc-mark": {"mark": mark, "where": where}})
308 311
312 async def gc_mark_stream(self, mark, rows):
313 """
314 Similar to `gc-mark`, but accepts a list of "where" key-value pair
315 conditions. It utilizes stream mode to mark hashes, which helps reduce
316 the impact of latency when communicating with the hash equivalence
317 server.
318 """
319 def row_to_dict(row):
320 pairs = row.split()
321 return dict(zip(pairs[::2], pairs[1::2]))
322
323 responses = await self.send_stream_batch(
324 self.MODE_MARK_STREAM,
325 (json.dumps({"mark": mark, "where": row_to_dict(row)}) for row in rows),
326 )
327
328 return {"count": sum(int(json.loads(r)["count"]) for r in responses)}
329
309 async def gc_sweep(self, mark): 330 async def gc_sweep(self, mark):
310 """ 331 """
311 Finishes garbage collection for "mark". All unihash entries that have 332 Finishes garbage collection for "mark". All unihash entries that have
@@ -351,6 +372,7 @@ class Client(bb.asyncrpc.Client):
351 "get_db_query_columns", 372 "get_db_query_columns",
352 "gc_status", 373 "gc_status",
353 "gc_mark", 374 "gc_mark",
375 "gc_mark_stream",
354 "gc_sweep", 376 "gc_sweep",
355 ) 377 )
356 378