From a94bbcc7ef1e3d533b0f237b4e37c1c1abaf5927 Mon Sep 17 00:00:00 2001 From: Nils Dijk Date: Fri, 11 Sep 2020 18:12:47 +0200 Subject: [PATCH] write wal entries when writing to the buffers --- cstore_writer.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cstore_writer.c b/cstore_writer.c index 8a5f498e2..5e44812bd 100644 --- a/cstore_writer.c +++ b/cstore_writer.c @@ -18,6 +18,7 @@ #include "access/nbtree.h" #include "catalog/pg_am.h" +#include "miscadmin.h" #include "storage/fd.h" #include "storage/smgr.h" #include "utils/memutils.h" @@ -401,11 +402,30 @@ WriteToSmgr(TableWriteState *writeState, char *data, uint32 dataLength) /* always appending */ Assert(phdr->pd_lower == addr.offset); + START_CRIT_SECTION(); + to_write = Min(phdr->pd_upper - phdr->pd_lower, remaining); memcpy(page + phdr->pd_lower, data, to_write); phdr->pd_lower += to_write; MarkBufferDirty(buffer); + + if (RelationNeedsWAL(rel)) + { + XLogBeginInsert(); + + /* + * Since cstore will mostly write whole pages we force the transmission of the + * whole image in the buffer + */ + XLogRegisterBuffer(0, buffer, REGBUF_FORCE_IMAGE); + + XLogRecPtr recptr = XLogInsert(RM_GENERIC_ID, 0); + PageSetLSN(page, recptr); + } + + END_CRIT_SECTION(); + UnlockReleaseBuffer(buffer); data += to_write;