pgq.maint_operations: re-check the need for step2
authorMarko Kreen <markokr@gmail.com>
Tue, 10 Jan 2012 21:38:30 +0000 (22:38 +0100)
committerMarko Kreen <markokr@gmail.com>
Tue, 10 Jan 2012 21:38:30 +0000 (22:38 +0100)
Previously the need for step2 was decided by need for step1.

But if pgqd stops/crashed after step1 but before step2,
the step2 will not be run anymore.

Fix this by rechecking if no step1 was needed.

sql/pgq/functions/pgq.maint_operations.sql

index bb72b12fb31b1501afcc1867c865c2192cd26492..31c44ba3567b871b005c3334008492eaacdac223 100644 (file)
@@ -34,6 +34,12 @@ begin
     end loop;
 
     -- rotate step 2
+    if nrot = 0 then
+        select count(1) from pgq.queue
+            where queue_rotation_period is not null
+                and queue_switch_step2 is null
+            into nrot;
+    end if;
     if nrot > 0 then
         func_name := 'pgq.maint_rotate_tables_step2';
         func_arg := NULL;