Revert ill-fated patch to release exclusive lock early after vacuum
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 20 Sep 2007 21:43:27 +0000 (21:43 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 20 Sep 2007 21:43:27 +0000 (21:43 +0000)
truncates a table.  Introduces race condition, as shown by buildfarm
failures.

src/backend/commands/vacuumlazy.c

index 7d9e3fb421edc700eab06371b60a91f7d3c83c7a..73b10df17d51ca31af7bcd01bb080c6e7fa38f66 100644 (file)
@@ -855,8 +855,13 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
         */
        RelationTruncate(onerel, new_rel_pages);
 
-       /* Now we're OK to release the lock. */
-       UnlockRelation(onerel, AccessExclusiveLock);
+       /*
+        * Note: once we have truncated, we *must* keep the exclusive lock
+        * until commit.  The sinval message that will be sent at commit
+        * (as a result of vac_update_relstats()) must be received by other
+        * backends, to cause them to reset their rd_targblock values, before
+        * they can safely access the table again.
+        */
 
        /*
         * Drop free-space info for removed blocks; these must not get entered