diff mbox series

[bitbake-devel,RFC,3/5] bitbake-hashclient: Add remove subcommand

Message ID 20230928170551.4193224-4-JPEWhacker@gmail.com
State New
Headers show
Series Bitbake Hash Server WebSockets Implementation | expand

Commit Message

Joshua Watt Sept. 28, 2023, 5:05 p.m. UTC
Adds a subcommand to invoke the remove API on the server

[YOCTO #15064]

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
 bitbake/bin/bitbake-hashclient | 13 +++++++++++++
 bitbake/lib/hashserv/server.py | 10 +++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/bitbake/bin/bitbake-hashclient b/bitbake/bin/bitbake-hashclient
index 494f17592ac..d09104336ab 100755
--- a/bitbake/bin/bitbake-hashclient
+++ b/bitbake/bin/bitbake-hashclient
@@ -113,6 +113,14 @@  def main():
                     with lock:
                         pbar.update()
 
+    def handle_remove(args, client):
+        where = {k: v for k, v in args.where}
+        if where:
+            result = client.remove(where)
+            print("Removed %d row(s)" % (result["count"]))
+        else:
+            print("No query specified")
+
     parser = argparse.ArgumentParser(description='Hash Equivalence Client')
     parser.add_argument('--address', default=DEFAULT_ADDRESS, help='Server address (default "%(default)s")')
     parser.add_argument('--log', default='WARNING', help='Set logging level')
@@ -137,6 +145,11 @@  def main():
                                help='Include string in outhash')
     stress_parser.set_defaults(func=handle_stress)
 
+    remove_parser = subparsers.add_parser('remove', help="Remove hash entries")
+    remove_parser.add_argument("--where", "-w", metavar="KEY VALUE", nargs=2, action="append", default=[],
+                               help="Remove entries from table where KEY == VALUE")
+    remove_parser.set_defaults(func=handle_remove)
+
     args = parser.parse_args()
 
     logger = logging.getLogger('hashserv')
diff --git a/bitbake/lib/hashserv/server.py b/bitbake/lib/hashserv/server.py
index 7e8aeefef30..99ba904b1f0 100644
--- a/bitbake/lib/hashserv/server.py
+++ b/bitbake/lib/hashserv/server.py
@@ -516,13 +516,17 @@  class ServerClient(bb.asyncrpc.AsyncServerConnection):
                 query = ('DELETE FROM %s WHERE ' % table_name) + ' AND '.join("%s=:%s" % (k, k) for k in where.keys())
                 print(query)
                 cursor.execute(query, where)
+                return cursor.rowcount
 
+            return 0
+
+        count = 0
         with closing(self.db.cursor()) as cursor:
-            do_remove(OUTHASH_TABLE_COLUMNS, "outhashes_v2", cursor)
-            do_remove(UNIHASH_TABLE_COLUMNS, "unihashes_v2", cursor)
+            count += do_remove(OUTHASH_TABLE_COLUMNS, "outhashes_v2", cursor)
+            count += do_remove(UNIHASH_TABLE_COLUMNS, "unihashes_v2", cursor)
             self.db.commit()
 
-        self.write_message({})
+        self.write_message({"count": count})
 
     def query_equivalent(self, cursor, method, taskhash):
         # This is part of the inner loop and must be as fast as possible