diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 66f9113..fa1d078 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -14220,7 +14220,11 @@ retry: readOff = targetOff; pgstat_report_wait_start(WAIT_EVENT_WAL_READ); - r = batchRead((uint8_t *) readBuf, ControlFile->checkPointCopy.ThisTimeLineID, targetOff); + bool walStoreToLocal = false; + if (EnableHotStandby && !push_standby) + walStoreToLocal = true; + + r = batchRead((uint8_t *) readBuf, ControlFile->checkPointCopy.ThisTimeLineID, targetOff, walStoreToLocal); pgstat_report_wait_end(); /* diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index 2590c6c..6bc14c8 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -1429,7 +1429,7 @@ He3DBWALRead(XLogReaderState *state, pgstat_report_wait_start(WAIT_EVENT_WAL_READ); #endif - nbytes = batchRead((uint8_t *) buf, state->currTLI, startptr); + nbytes = batchRead((uint8_t *) buf, state->currTLI, startptr, false); #ifndef FRONTEND pgstat_report_wait_end(); diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index 49dda09..cfa5c5c 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -24,6 +24,7 @@ #include "storage/md.h" #include "storage/smgr.h" #include "storage/filecache.h" +#include "utils/hfs.h" #include "utils/hsearch.h" #include "utils/inval.h" #include "utils/guc.h" @@ -446,6 +447,9 @@ smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo) for (forknum = 0; forknum <= MAX_FORKNUM; forknum++) smgrsw[which].smgr_unlink(rnodes[i], forknum, isRedo); + + //remove unused pages and related wals in localdisk cache. + RemoveBufferFromLocal(rnodes[i].node.dbNode, rnodes[i].node.relNode, MAX_FORKNUM, 0); } pfree(rnodes); @@ -674,6 +678,8 @@ smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks, BlockNumber *nb smgrsw[reln->smgr_which].smgr_truncate(reln, forknum[i], nblocks[i]); + //remove unused pages and related wals in localdisk cache. + RemoveBufferFromLocal(reln->smgr_rnode.node.dbNode, reln->smgr_rnode.node.relNode, forknum[i], nblocks[i]); /* * We might as well update the local smgr_cached_nblocks values. The * smgr cache inval message that this function sent will cause other @@ -737,6 +743,9 @@ smgrtruncatelsn(SMgrRelation reln, ForkNumber *forknum, int nforks, BlockNumber } smgrsw[reln->smgr_which].smgr_truncate(reln, forknum[i], nblocks[i]); + //remove unused pages and related wals in localdisk cache. + RemoveBufferFromLocal(reln->smgr_rnode.node.dbNode, reln->smgr_rnode.node.relNode, forknum[i], nblocks[i]); + /* * We might as well update the local smgr_cached_nblocks values. The * smgr cache inval message that this function sent will cause other diff --git a/src/include/utils/hfs.h b/src/include/utils/hfs.h index 622df1f..cefc9e4 100644 --- a/src/include/utils/hfs.h +++ b/src/include/utils/hfs.h @@ -52,7 +52,7 @@ extern Bufrd dataRead(int64_t fd, extern void free_dataRead(uint8_t *buf, size_t count, size_t cap); extern Bufrd readfs(int64_t fd, int64_t offset, uint32_t size); -extern int batchRead(uint8_t *buf, uint32_t timeline, uint64_t startPtr); +extern int batchRead(uint8_t *buf, uint32_t timeline, uint64_t startPtr, bool needStore); extern uint8_t kvwrite(XLogItem *xlogItem); extern uint8_t flushwals(XLogItem *xlogItem, uint32_t timeline); extern uint8_t kvflush(XLogRecPtr lsn); @@ -62,4 +62,5 @@ extern Bufrd ReadWalsByPage(uint32_t dbid, uint32_t blkno, uint64_t startlsn, uint64_t endlsn, - uint32_t timeline); \ No newline at end of file + uint32_t timeline); +extern void RemoveBufferFromLocal(uint32_t dbid, uint32_t relid, uint32_t forkno, uint32_t blkno); \ No newline at end of file