Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2a8e1ac

Browse files
committed
Set the all-visible flag on heap page before writing WAL record, not after.
If we set the all-visible flag after writing WAL record, and XLogInsert takes a full-page image of the page, the image would not include the flag. We will then proceed to set the VM bit, which would then be set without the corresponding all-visible flag on the heap page. Found by comparing page images on master and standby, after writing/replaying each WAL record. (There is still a discrepancy: the all-visible flag won't be set after replaying the HEAP_CLEAN record, even though it is set in the master. However, it will be set when replaying the HEAP2_VISIBLE record and setting the VM bit, so the all-visible flag and VM bit are always consistent on the standby, even though they are momentarily out-of-sync with master) Backpatch to 9.3 where this code was introduced.
1 parent 5f86cbd commit 2a8e1ac

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/backend/commands/vacuumlazy.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,13 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer,
12131213

12141214
PageRepairFragmentation(page);
12151215

1216+
/*
1217+
* Now that we have removed the dead tuples from the page, once again
1218+
* check if the page has become all-visible.
1219+
*/
1220+
if (heap_page_is_all_visible(onerel, buffer, &visibility_cutoff_xid))
1221+
PageSetAllVisible(page);
1222+
12161223
/*
12171224
* Mark buffer dirty before we write WAL.
12181225
*/
@@ -1231,14 +1238,13 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer,
12311238
}
12321239

12331240
/*
1234-
* Now that we have removed the dead tuples from the page, once again
1235-
* check if the page has become all-visible.
1241+
* All the changes to the heap page have been done. If the all-visible
1242+
* flag is now set, also set the VM bit.
12361243
*/
1237-
if (!visibilitymap_test(onerel, blkno, vmbuffer) &&
1238-
heap_page_is_all_visible(onerel, buffer, &visibility_cutoff_xid))
1244+
if (PageIsAllVisible(page) &&
1245+
!visibilitymap_test(onerel, blkno, vmbuffer))
12391246
{
12401247
Assert(BufferIsValid(*vmbuffer));
1241-
PageSetAllVisible(page);
12421248
visibilitymap_set(onerel, blkno, buffer, InvalidXLogRecPtr, *vmbuffer,
12431249
visibility_cutoff_xid);
12441250
}

0 commit comments

Comments
 (0)