Skip to content

Commit

Permalink
Update WAL buffers when restoring WAL at compute needed for LR (#324)
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
knizhnik and Konstantin Knizhnik committed Nov 3, 2023
1 parent ab67ab9 commit bc88f53
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 @@ -9287,3 +9287,29 @@ SetWalWriterSleeping(bool sleeping)
XLogCtl->WalWriterSleeping = sleeping;
SpinLockRelease(&XLogCtl->info_lck);
}

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/xlogrecovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,6 @@ extern void RecoveryRequiresIntParameter(const char *param_name, int currValue,

extern void xlog_outdesc(StringInfo buf, XLogReaderState *record);

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

#endif /* XLOGRECOVERY_H */

0 comments on commit bc88f53

Please sign in to comment.