summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorPaul Barker <pbarker@konsulko.com>2021-02-05 11:26:10 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-02-10 23:48:16 +0000
commit40ecec326effeb1f4dd647849293f18118d4dd21 (patch)
tree6ee2bee7cce76dcafa3cb03c557ffa8dcc93c613 /bitbake
parent73160aac0608cc186be1ec991b08ff8f130cdb8f (diff)
downloadpoky-40ecec326effeb1f4dd647849293f18118d4dd21.tar.gz
bitbake: hashserv: Add get-outhash message
The get-outhash message can be sent via the get_outhash client method. This works in a similar way to the get message but looks up a db entry by outhash rather than by taskhash. It is intended to be used as a read-only form of the report message. As both handle_get_outhash and handle_report use the same query string we can factor this out. (Bitbake rev: dc19606ada29a4d8afde4fcecd8ec986b47b867e) Signed-off-by: Paul Barker <pbarker@konsulko.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/hashserv/client.py6
-rw-r--r--bitbake/lib/hashserv/server.py46
2 files changed, 38 insertions, 14 deletions
diff --git a/bitbake/lib/hashserv/client.py b/bitbake/lib/hashserv/client.py
index 0b7f4e42e9..e05c1eb568 100644
--- a/bitbake/lib/hashserv/client.py
+++ b/bitbake/lib/hashserv/client.py
@@ -170,6 +170,12 @@ class AsyncClient(object):
170 {"get": {"taskhash": taskhash, "method": method, "all": all_properties}} 170 {"get": {"taskhash": taskhash, "method": method, "all": all_properties}}
171 ) 171 )
172 172
173 async def get_outhash(self, method, outhash, taskhash):
174 await self._set_mode(self.MODE_NORMAL)
175 return await self.send_message(
176 {"get-outhash": {"outhash": outhash, "taskhash": taskhash, "method": method}}
177 )
178
173 async def get_stats(self): 179 async def get_stats(self):
174 await self._set_mode(self.MODE_NORMAL) 180 await self._set_mode(self.MODE_NORMAL)
175 return await self.send_message({"get-stats": None}) 181 return await self.send_message({"get-stats": None})
diff --git a/bitbake/lib/hashserv/server.py b/bitbake/lib/hashserv/server.py
index 9ade988e56..a0dc0c170f 100644
--- a/bitbake/lib/hashserv/server.py
+++ b/bitbake/lib/hashserv/server.py
@@ -152,6 +152,20 @@ async def copy_outhash_from_upstream(client, db, method, outhash, taskhash):
152class ServerClient(object): 152class ServerClient(object):
153 FAST_QUERY = 'SELECT taskhash, method, unihash FROM tasks_v2 WHERE method=:method AND taskhash=:taskhash ORDER BY created ASC LIMIT 1' 153 FAST_QUERY = 'SELECT taskhash, method, unihash FROM tasks_v2 WHERE method=:method AND taskhash=:taskhash ORDER BY created ASC LIMIT 1'
154 ALL_QUERY = 'SELECT * FROM tasks_v2 WHERE method=:method AND taskhash=:taskhash ORDER BY created ASC LIMIT 1' 154 ALL_QUERY = 'SELECT * FROM tasks_v2 WHERE method=:method AND taskhash=:taskhash ORDER BY created ASC LIMIT 1'
155 OUTHASH_QUERY = '''
156 -- Find tasks with a matching outhash (that is, tasks that
157 -- are equivalent)
158 SELECT * FROM tasks_v2 WHERE method=:method AND outhash=:outhash
159
160 -- If there is an exact match on the taskhash, return it.
161 -- Otherwise return the oldest matching outhash of any
162 -- taskhash
163 ORDER BY CASE WHEN taskhash=:taskhash THEN 1 ELSE 2 END,
164 created ASC
165
166 -- Only return one row
167 LIMIT 1
168 '''
155 169
156 def __init__(self, reader, writer, db, request_stats, backfill_queue, upstream, read_only): 170 def __init__(self, reader, writer, db, request_stats, backfill_queue, upstream, read_only):
157 self.reader = reader 171 self.reader = reader
@@ -164,6 +178,7 @@ class ServerClient(object):
164 178
165 self.handlers = { 179 self.handlers = {
166 'get': self.handle_get, 180 'get': self.handle_get,
181 'get-outhash': self.handle_get_outhash,
167 'get-stream': self.handle_get_stream, 182 'get-stream': self.handle_get_stream,
168 'get-stats': self.handle_get_stats, 183 'get-stats': self.handle_get_stats,
169 'chunk-stream': self.handle_chunk, 184 'chunk-stream': self.handle_chunk,
@@ -301,6 +316,21 @@ class ServerClient(object):
301 316
302 self.write_message(d) 317 self.write_message(d)
303 318
319 async def handle_get_outhash(self, request):
320 with closing(self.db.cursor()) as cursor:
321 cursor.execute(self.OUTHASH_QUERY,
322 {k: request[k] for k in ('method', 'outhash', 'taskhash')})
323
324 row = cursor.fetchone()
325
326 if row is not None:
327 logger.debug('Found equivalent outhash %s -> %s', (row['outhash'], row['unihash']))
328 d = {k: row[k] for k in row.keys()}
329 else:
330 d = None
331
332 self.write_message(d)
333
304 async def handle_get_stream(self, request): 334 async def handle_get_stream(self, request):
305 self.write_message('ok') 335 self.write_message('ok')
306 336
@@ -354,20 +384,8 @@ class ServerClient(object):
354 384
355 async def handle_report(self, data): 385 async def handle_report(self, data):
356 with closing(self.db.cursor()) as cursor: 386 with closing(self.db.cursor()) as cursor:
357 cursor.execute(''' 387 cursor.execute(self.OUTHASH_QUERY,
358 -- Find tasks with a matching outhash (that is, tasks that 388 {k: data[k] for k in ('method', 'outhash', 'taskhash')})
359 -- are equivalent)
360 SELECT taskhash, method, unihash FROM tasks_v2 WHERE method=:method AND outhash=:outhash
361
362 -- If there is an exact match on the taskhash, return it.
363 -- Otherwise return the oldest matching outhash of any
364 -- taskhash
365 ORDER BY CASE WHEN taskhash=:taskhash THEN 1 ELSE 2 END,
366 created ASC
367
368 -- Only return one row
369 LIMIT 1
370 ''', {k: data[k] for k in ('method', 'outhash', 'taskhash')})
371 389
372 row = cursor.fetchone() 390 row = cursor.fetchone()
373 391