Remove race condition from bucardo_purge_q_table()
authorGreg Sabino Mullane <greg@endpoint.com>
Tue, 24 Aug 2010 16:10:02 +0000 (12:10 -0400)
committerGreg Sabino Mullane <greg@endpoint.com>
Tue, 24 Aug 2010 16:10:02 +0000 (12:10 -0400)
bucardo.schema

index 91059ff689a10e125a3d89b9ecb25970e6bfb253..fd749a1521b36a30b3df8a6b11267e5cc657572f 100644 (file)
@@ -552,7 +552,12 @@ BEGIN
   RAISE DEBUG 'Purging q table of finished items older than %', $1;
   INSERT INTO freezer.master_q SELECT * FROM bucardo.q
     WHERE (ended IS NOT NULL OR aborted IS NOT NULL) AND cdate <= now() - $1;
-  DELETE FROM bucardo.q WHERE (ended IS NOT NULL OR aborted IS NOT NULL) AND cdate <= now() - $1;
+  DELETE FROM bucardo.q WHERE cdate <= now() - $1
+    AND (
+         (ended IS NOT NULL AND ended < now())
+         OR
+         (aborted IS NOT NULL AND aborted < now())
+  );
   GET DIAGNOSTICS numrows := row_count;
   SELECT count(*) FROM q INTO qcount;
   RAISE NOTICE 'Rows left in q table: %', qcount;