All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hashserv: Fix read-only mode.
@ 2023-09-29 12:37 Karim Ben Houcine
  2023-09-29 13:14 ` Karim Ben Houcine
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Karim Ben Houcine @ 2023-09-29 12:37 UTC (permalink / raw)
  To: bitbake-devel; +Cc: Karim Ben Houcine

Signed-off-by: Karim Ben Houcine <karim.benhoucine@landisgyr.com>
---
 lib/hashserv/server.py | 55 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/lib/hashserv/server.py b/lib/hashserv/server.py
index d40a2ab8..56d76f1f 100644
--- a/lib/hashserv/server.py
+++ b/lib/hashserv/server.py
@@ -180,7 +180,11 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection):
             'get-stats': self.handle_get_stats,
         })
 
-        if not read_only:
+        if read_only:
+            self.handlers.update({    
+                'report': self.handle_readonly_report,
+            })
+        else:
             self.handlers.update({
                 'report': self.handle_report,
                 'report-equiv': self.handle_equivreport,
@@ -453,6 +457,55 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection):
 
         self.write_message(d)
 
+
+    async def handle_readonly_report(self, data):
+        with closing(self.db.cursor()) as cursor:
+            outhash_data = {
+                'method': data['method'],
+                'outhash': data['outhash'],
+                'taskhash': data['taskhash'],
+                'created': datetime.now()
+            }
+
+            for k in ('owner', 'PN', 'PV', 'PR', 'task', 'outhash_siginfo'):
+                if k in data:
+                    outhash_data[k] = data[k] 
+
+            # Check if outhash is known
+            cursor.execute(
+                '''
+                SELECT outhashes_v2.taskhash AS taskhash, unihashes_v2.unihash AS unihash FROM outhashes_v2
+                INNER JOIN unihashes_v2 ON unihashes_v2.method=outhashes_v2.method AND unihashes_v2.taskhash=outhashes_v2.taskhash
+                -- Select any matching output hash
+                WHERE outhashes_v2.method=:method AND outhashes_v2.outhash=:outhash
+                -- Pick the oldest hash
+                ORDER BY outhashes_v2.created ASC
+                LIMIT 1
+                ''',
+                {
+                    'method': data['method'],
+                    'outhash': data['outhash'],
+                    'taskhash': data['taskhash'],
+                }
+            )
+            row = cursor.fetchone()
+            if row is not None: 
+                # outhash is known => corrects unihash
+                unihash = row['unihash'] 
+            else:
+                # outhash is unknown => nothing to do
+                unihash = outhash_data['taskhash'] 
+            
+
+            d = {
+                'taskhash': data['taskhash'],
+                'method': data['method'],
+                'unihash': unihash,
+            }
+
+        self.write_message(d)
+        
+
     async def handle_equivreport(self, data):
         with closing(self.db.cursor()) as cursor:
             insert_data = {
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread
[parent not found: <178A47C70519CAC1.9230@lists.openembedded.org>]

end of thread, other threads:[~2023-10-05  5:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-29 12:37 [PATCH] hashserv: Fix read-only mode Karim Ben Houcine
2023-09-29 13:14 ` Karim Ben Houcine
2023-09-30 10:47   ` [bitbake-devel] " Alexandre Belloni
2023-10-02 11:45     ` Ben Houcine, Karim
2023-10-02 18:11       ` Alexandre Belloni
2023-10-02 20:49 ` Joshua Watt
2023-10-03  6:56   ` [PATCH v2] " Karim Ben Houcine
2023-10-03 15:56 ` [bitbake-devel] [PATCH] " Joshua Watt
2023-10-04  7:31   ` [PATCH v3] " Karim Ben Houcine
2023-10-05  5:30   ` [bitbake-devel] [PATCH] " Ben Houcine, Karim
     [not found] <178A47C70519CAC1.9230@lists.openembedded.org>
2023-10-02 11:56 ` Karim Ben Houcine
2023-10-02 18:46   ` [bitbake-devel] " Alexandre Belloni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.