Skip to content

Commit

Permalink
Update WAL buffers when restoring WAL at compute needed for LR (#325)
Browse files Browse the repository at this point in the history
* Update WAL buffers when restoring WAL at compute needed for LR

* Fix copying data in WAL buffers

---------

Co-authored-by: Konstantin Knizhnik <[email protected]>
  • Loading branch information
2 people authored and tristan957 committed Nov 8, 2023
1 parent 23b502f commit 0bb356a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/backend/access/transam/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -13755,3 +13755,29 @@ XLogRequestWalReceiverReply(void)
{
doRequestWalReceiverReply = true;
}

void
XLogUpdateWalBuffers(char* data, XLogRecPtr start, size_t len)
{
XLogRecPtr end;
int idx;
XLogRecPtr pagebegptr;

LWLockAcquire(WALBufMappingLock, LW_EXCLUSIVE);

end = start + len;
idx = XLogRecPtrToBufIdx(end);
pagebegptr = XLogCtl->xlblocks[idx] - XLOG_BLCKSZ;

if (pagebegptr + XLOG_BLCKSZ >= end && pagebegptr < end)
{
/* Last page of the segment is present in WAL buffers */
char* page = &XLogCtl->pages[idx * XLOG_BLCKSZ];
size_t overlap = end - pagebegptr;
if (overlap <= len)
memcpy(page, data + len - overlap, overlap);
else
memcpy(page + overlap - len, data, len);
}
LWLockRelease(WALBufMappingLock);
}
2 changes: 2 additions & 0 deletions src/include/access/xlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ extern void SetWalWriterSleeping(bool sleeping);
extern void StartupRequestWalReceiverRestart(void);
extern void XLogRequestWalReceiverReply(void);

extern void XLogUpdateWalBuffers(char* data, XLogRecPtr start, size_t len);

extern void assign_max_wal_size(int newval, void *extra);
extern void assign_checkpoint_completion_target(double newval, void *extra);

Expand Down

0 comments on commit 0bb356a

Please sign in to comment.