Skip to content

Commit a13fe64

Browse files
authored
Perform inmem_smgr cleaup after processing each record (#154)
* Perform inmem_smgr cleaup after processing each record * Prevent eviction of wal redo target page * Prevent eviction of wal redo target page frmo temp buffers
1 parent fcd2af7 commit a13fe64

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

contrib/zenith/inmem_smgr.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "storage/relfilenode.h"
2929
#include "storage/smgr.h"
3030

31-
#define MAX_PAGES 128
31+
#define MAX_PAGES 32
3232

3333
static BufferTag page_tag[MAX_PAGES];
3434
static char page_body[MAX_PAGES][BLCKSZ];
@@ -195,10 +195,6 @@ inmem_nblocks(SMgrRelation reln, ForkNumber forknum)
195195
{
196196
int nblocks = 0;
197197

198-
/*
199-
* Find the hightest-numbered page, and report that as the relation size.
200-
* XXX: Why does this get called during WAL replay at all?
201-
*/
202198
for (int i = 0; i < used_pages; i++)
203199
{
204200
if (RelFileNodeEquals(reln->smgr_rnode.node, page_tag[i].rnode)

src/backend/storage/buffer/localbuf.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "utils/memutils.h"
2626
#include "utils/resowner_private.h"
2727

28+
/* ZENITH: prevent eviction of the buffer of target page */
29+
extern Buffer wal_redo_buffer;
2830

2931
/*#define LBDEBUG*/
3032

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

184186
if (LocalRefCount[b] == 0)
185187
{
188+
if (-b - 1 == wal_redo_buffer)
189+
{
190+
/* ZENITH: Prevent eviction of the buffer with target wal redo page */
191+
continue;
192+
}
193+
186194
buf_state = pg_atomic_read_u32(&bufHdr->state);
187195

188196
if (BUF_STATE_GET_USAGECOUNT(buf_state) > 0)

src/backend/tcop/zenith_wal_redo.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static ssize_t buffered_read(void *buf, size_t count);
100100

101101
static BufferTag target_redo_tag;
102102

103+
Buffer wal_redo_buffer;
103104
bool am_wal_redo_postgres;
104105

105106
static XLogReaderState *reader_state;
@@ -566,6 +567,7 @@ PushPage(StringInfo input_message)
566567
content = pq_getmsgbytes(input_message, BLCKSZ);
567568

568569
buf = ReadBufferWithoutRelcache(rnode, forknum, blknum, RBM_ZERO_AND_LOCK, NULL);
570+
wal_redo_buffer = buf;
569571
page = BufferGetPage(buf);
570572
memcpy(page, content, BLCKSZ);
571573
MarkBufferDirty(buf); /* pro forma */
@@ -594,6 +596,8 @@ ApplyRecord(StringInfo input_message)
594596
*/
595597
lsn = pq_getmsgint64(input_message);
596598

599+
smgrinit(); /* reset inmem smgr state */
600+
597601
/* note: the input must be aligned here */
598602
record = (XLogRecord *) pq_getmsgbytes(input_message, sizeof(XLogRecord));
599603

@@ -734,7 +738,6 @@ GetPage(StringInfo input_message)
734738

735739
ReleaseBuffer(buf);
736740
DropRelFileNodeAllLocalBuffers(rnode);
737-
smgrinit(); /* reset inmem smgr state */
738741

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

0 commit comments

Comments
 (0)