From d66020b80db2bd8bc7bca2d313005d31780e28a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20K=C3=A1cha?= <ph@cesnet.cz> Date: Wed, 18 Feb 2015 19:46:08 +0100 Subject: [PATCH] Bugfix - when using transactions (InnoDB), ALL insert sets must get correctly committed or rolled back. insertLastReceivedId was not committed, and as we reuse the cursor, reader client kept getting stale data until next event insert on the same connection, possibly from completely different client at completely unrelated time (which unintentionally closed even the previous transaction), or until server restart. Whew, tricky beast to hunt. --- warden3/warden_server/warden_server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/warden3/warden_server/warden_server.py b/warden3/warden_server/warden_server.py index 1caa425..2c38a36 100755 --- a/warden3/warden_server/warden_server.py +++ b/warden3/warden_server/warden_server.py @@ -561,12 +561,13 @@ class MySQL(ObjectReq): def insertLastReceivedId(self, client, id): logging.debug("insertLastReceivedId: id %i for client %i(%s)" % (id, client.id, client.hostname)) self.crs.execute("INSERT INTO last_events(client_id, event_id, timestamp) VALUES(%s, %s, NOW())", (client.id, id)) + self.con.commit() def getLastEventId(self): self.crs.execute("SELECT MAX(id) as id FROM events") row = self.crs.fetchone() - return row['id'] if row['id'] is not None else 0 + return row['id'] or 0 def getLastReceivedId(self, client): self.crs.execute("SELECT MAX(event_id) as id FROM last_events WHERE client_id = %s", client.id) -- GitLab