summaryrefslogtreecommitdiff
path: root/src/backend/access/gin/ginxlog.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-05-08 14:43:04 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-05-08 14:43:39 +0300
commit31633f992568ffca9a7927a9f474ad8516840b2c (patch)
tree1d4d658a3e079bf59abc606ec9707c509ff57b55 /src/backend/access/gin/ginxlog.c
parent7603744a077a8f6a878f47e389a3d41844c8adc5 (diff)
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.
Diffstat (limited to 'src/backend/access/gin/ginxlog.c')
-rw-r--r--src/backend/access/gin/ginxlog.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/backend/access/gin/ginxlog.c b/src/backend/access/gin/ginxlog.c
index 386bcb3af6f..66036496153 100644
--- a/src/backend/access/gin/ginxlog.c
+++ b/src/backend/access/gin/ginxlog.c
@@ -698,26 +698,26 @@ ginRedoDeleteListPages(XLogRecPtr lsn, XLogRecord *record)
* cannot get past a reader that is on, or due to visit, any page we are
* going to delete. New incoming readers will block behind our metapage
* lock and then see a fully updated page list.
+ *
+ * No full-page images are taken of the deleted pages. Instead, they are
+ * re-initialized as empty, deleted pages. Their right-links don't need to
+ * be preserved, because no new readers can see the pages, as explained
+ * above.
*/
for (i = 0; i < data->ndeleted; i++)
{
- Buffer buffer = XLogReadBuffer(data->node, data->toDelete[i], false);
+ Buffer buffer;
+ Page page;
- if (BufferIsValid(buffer))
- {
- Page page = BufferGetPage(buffer);
-
- if (!XLByteLE(lsn, PageGetLSN(page)))
- {
- GinPageGetOpaque(page)->flags = GIN_DELETED;
+ buffer = XLogReadBuffer(data->node, data->toDelete[i], true);
+ page = BufferGetPage(buffer);
+ GinInitBuffer(buffer, GIN_DELETED);
- PageSetLSN(page, lsn);
- PageSetTLI(page, ThisTimeLineID);
- MarkBufferDirty(buffer);
- }
+ PageSetLSN(page, lsn);
+ PageSetTLI(page, ThisTimeLineID);
+ MarkBufferDirty(buffer);
- UnlockReleaseBuffer(buffer);
- }
+ UnlockReleaseBuffer(buffer);
}
UnlockReleaseBuffer(metabuffer);
}