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

Commit 4f7bb4b

Browse files
committed
Protect against torn pages when deleting GIN list pages.
To-be-deleted list pages contain no useful information, as they are being deleted, but we must still protect the writes from being torn by a crash after a partial write. To do that, re-initialize the pages on WAL replay. Jeff Janes caught this with a test program to test partial writes. Backpatch to all supported versions.
1 parent 02c9a93 commit 4f7bb4b

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/backend/access/gin/ginxlog.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -884,25 +884,25 @@ ginRedoDeleteListPages(XLogRecPtr lsn, XLogRecord *record)
884884
* cannot get past a reader that is on, or due to visit, any page we are
885885
* going to delete. New incoming readers will block behind our metapage
886886
* lock and then see a fully updated page list.
887+
*
888+
* No full-page images are taken of the deleted pages. Instead, they are
889+
* re-initialized as empty, deleted pages. Their right-links don't need to
890+
* be preserved, because no new readers can see the pages, as explained
891+
* above.
887892
*/
888893
for (i = 0; i < data->ndeleted; i++)
889894
{
890-
Buffer buffer = XLogReadBuffer(data->node, data->toDelete[i], false);
895+
Buffer buffer;
896+
Page page;
891897

892-
if (BufferIsValid(buffer))
893-
{
894-
Page page = BufferGetPage(buffer);
895-
896-
if (lsn > PageGetLSN(page))
897-
{
898-
GinPageGetOpaque(page)->flags = GIN_DELETED;
898+
buffer = XLogReadBuffer(data->node, data->toDelete[i], true);
899+
page = BufferGetPage(buffer);
900+
GinInitBuffer(buffer, GIN_DELETED);
899901

900-
PageSetLSN(page, lsn);
901-
MarkBufferDirty(buffer);
902-
}
902+
PageSetLSN(page, lsn);
903+
MarkBufferDirty(buffer);
903904

904-
UnlockReleaseBuffer(buffer);
905-
}
905+
UnlockReleaseBuffer(buffer);
906906
}
907907
UnlockReleaseBuffer(metabuffer);
908908
}

0 commit comments

Comments
 (0)