Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitecac0e2

Browse files
committed
Do all-visible handling in lazy_vacuum_page() outside its critical section.
Sincefdf9e21 lazy_vacuum_page() rechecks the all-visible statusof pages in the second pass over the heap. It does so inside acritical section, but both visibilitymap_test() andheap_page_is_all_visible() perform operations that should not happeninside one. The former potentially performs IO and both potentially domemory allocations.To fix, simply move all the all-visible handling outside the criticalsection. Doing so means that the PD_ALL_VISIBLE on the page won't beincluded in the full page image of the HEAP2_CLEAN record anymore. Butthat's fine, the flag will be set by the HEAP2_VISIBLE logged later.Backpatch to 9.3 where the problem was introduced. The bug only cameto light due to the assertion added in4a170ee and isn't likely tocause problems in production scenarios. The worst outcome is aavoidable PANIC restart.This also gets rid of the difference in the order of operationsbetween master and standby mentioned in2a8e1ac.Per reports from David Leverton and Keith Fiske in bug #10533.
1 parent3bdcf6a commitecac0e2

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

‎src/backend/commands/vacuumlazy.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,13 +1213,6 @@ 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-
12231216
/*
12241217
* Mark buffer dirty before we write WAL.
12251218
*/
@@ -1237,6 +1230,23 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer,
12371230
PageSetLSN(page,recptr);
12381231
}
12391232

1233+
/*
1234+
* End critical section, so we safely can do visibility tests (which
1235+
* possibly need to perform IO and allocate memory!). If we crash now the
1236+
* page (including the corresponding vm bit) might not be marked all
1237+
* visible, but that's fine. A later vacuum will fix that.
1238+
*/
1239+
END_CRIT_SECTION();
1240+
1241+
/*
1242+
* Now that we have removed the dead tuples from the page, once again
1243+
* check if the page has become all-visible. The page is already marked
1244+
* dirty, exclusively locked, and, if needed, a full page image has been
1245+
* emitted in the log_heap_clean() above.
1246+
*/
1247+
if (heap_page_is_all_visible(onerel,buffer,&visibility_cutoff_xid))
1248+
PageSetAllVisible(page);
1249+
12401250
/*
12411251
* All the changes to the heap page have been done. If the all-visible
12421252
* flag is now set, also set the VM bit.
@@ -1249,8 +1259,6 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer,
12491259
visibility_cutoff_xid);
12501260
}
12511261

1252-
END_CRIT_SECTION();
1253-
12541262
returntupindex;
12551263
}
12561264

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp