Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform inmem_smgr cleaup after processing each record #154

Merged
merged 4 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions contrib/zenith/inmem_smgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "storage/relfilenode.h"
#include "storage/smgr.h"

#define MAX_PAGES 128
#define MAX_PAGES 32

static BufferTag page_tag[MAX_PAGES];
static char page_body[MAX_PAGES][BLCKSZ];
Expand Down Expand Up @@ -195,10 +195,6 @@ inmem_nblocks(SMgrRelation reln, ForkNumber forknum)
{
int nblocks = 0;

/*
* Find the hightest-numbered page, and report that as the relation size.
* XXX: Why does this get called during WAL replay at all?
*/
for (int i = 0; i < used_pages; i++)
{
if (RelFileNodeEquals(reln->smgr_rnode.node, page_tag[i].rnode)
Expand Down
8 changes: 8 additions & 0 deletions src/backend/storage/buffer/localbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "utils/memutils.h"
#include "utils/resowner_private.h"

/* ZENITH: prevent eviction of the buffer of target page */
extern Buffer wal_redo_buffer;

/*#define LBDEBUG*/

Expand Down Expand Up @@ -183,6 +185,12 @@ LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum,

if (LocalRefCount[b] == 0)
{
if (-b - 1 == wal_redo_buffer)
{
/* ZENITH: Prevent eviction of the buffer with target wal redo page */
continue;
}

buf_state = pg_atomic_read_u32(&bufHdr->state);

if (BUF_STATE_GET_USAGECOUNT(buf_state) > 0)
Expand Down
5 changes: 4 additions & 1 deletion src/backend/tcop/zenith_wal_redo.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static ssize_t buffered_read(void *buf, size_t count);

static BufferTag target_redo_tag;

Buffer wal_redo_buffer;
bool am_wal_redo_postgres;

static XLogReaderState *reader_state;
Expand Down Expand Up @@ -566,6 +567,7 @@ PushPage(StringInfo input_message)
content = pq_getmsgbytes(input_message, BLCKSZ);

buf = ReadBufferWithoutRelcache(rnode, forknum, blknum, RBM_ZERO_AND_LOCK, NULL);
wal_redo_buffer = buf;
page = BufferGetPage(buf);
memcpy(page, content, BLCKSZ);
MarkBufferDirty(buf); /* pro forma */
Expand Down Expand Up @@ -594,6 +596,8 @@ ApplyRecord(StringInfo input_message)
*/
lsn = pq_getmsgint64(input_message);

smgrinit(); /* reset inmem smgr state */

/* note: the input must be aligned here */
record = (XLogRecord *) pq_getmsgbytes(input_message, sizeof(XLogRecord));

Expand Down Expand Up @@ -734,7 +738,6 @@ GetPage(StringInfo input_message)

ReleaseBuffer(buf);
DropRelFileNodeAllLocalBuffers(rnode);
smgrinit(); /* reset inmem smgr state */

elog(TRACE, "Page sent back for block %u", blknum);
}
Expand Down