update smgrwrite api

Signed-off-by: shipixian <shipixian_yewu@cmss.chinamobile.com>
This commit is contained in:
shipixian 2023-03-24 11:28:52 +08:00
parent f5da1a230c
commit 8a6fd7ad28
10 changed files with 77 additions and 57 deletions

View File

@ -454,7 +454,7 @@ gist_indexsortbuild(GISTBuildState *state)
PageSetLSN(pagestate->page, GistBuildLSN);
PageSetChecksumInplace(pagestate->page, GIST_ROOT_BLKNO);
smgrwrite(state->indexrel->rd_smgr, MAIN_FORKNUM, GIST_ROOT_BLKNO,
pagestate->page, true);
pagestate->page, true, GistBuildLSN);
if (RelationNeedsWAL(state->indexrel))
log_newpage(&state->indexrel->rd_node, MAIN_FORKNUM, GIST_ROOT_BLKNO,
pagestate->page, true);

View File

@ -163,8 +163,9 @@ btbuildempty(Relation index)
* this even when wal_level=minimal.
*/
PageSetChecksumInplace(metapage, BTREE_METAPAGE);
XLogRecPtr lsn = PageGetLSN(metapage);
smgrwrite(index->rd_smgr, INIT_FORKNUM, BTREE_METAPAGE,
(char *) metapage, true);
(char *) metapage, true, lsn);
log_newpage(&index->rd_smgr->smgr_rnode.node, INIT_FORKNUM,
BTREE_METAPAGE, metapage, true);

View File

@ -681,8 +681,9 @@ _bt_blwritepage(BTWriteState *wstate, Page page, BlockNumber blkno)
else
{
/* overwriting a block we zero-filled before */
XLogRecPtr lsn = PageGetLSN(page);
smgrwrite(wstate->index->rd_smgr, MAIN_FORKNUM, blkno,
(char *) page, true);
(char *) page, true, lsn);
}
pfree(page);

View File

@ -170,7 +170,7 @@ spgbuildempty(Relation index)
*/
PageSetChecksumInplace(page, SPGIST_METAPAGE_BLKNO);
smgrwrite(index->rd_smgr, INIT_FORKNUM, SPGIST_METAPAGE_BLKNO,
(char *) page, true);
(char *) page, true, 0);
log_newpage(&index->rd_smgr->smgr_rnode.node, INIT_FORKNUM,
SPGIST_METAPAGE_BLKNO, page, true);
@ -179,7 +179,7 @@ spgbuildempty(Relation index)
PageSetChecksumInplace(page, SPGIST_ROOT_BLKNO);
smgrwrite(index->rd_smgr, INIT_FORKNUM, SPGIST_ROOT_BLKNO,
(char *) page, true);
(char *) page, true, 0);
log_newpage(&index->rd_smgr->smgr_rnode.node, INIT_FORKNUM,
SPGIST_ROOT_BLKNO, page, true);
@ -188,7 +188,7 @@ spgbuildempty(Relation index)
PageSetChecksumInplace(page, SPGIST_NULL_BLKNO);
smgrwrite(index->rd_smgr, INIT_FORKNUM, SPGIST_NULL_BLKNO,
(char *) page, true);
(char *) page, true, 0);
log_newpage(&index->rd_smgr->smgr_rnode.node, INIT_FORKNUM,
SPGIST_NULL_BLKNO, page, true);

View File

@ -1062,13 +1062,13 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
INSTR_TIME_SET_CURRENT(io_start);
// XLogRecPtr replayLsn = GetXLogWriteRecPtr();
if (!EnableHotStandby) {
// if (!EnableHotStandby || IsBootstrapProcessingMode() == true || InitdbSingle == true) {
smgrread(smgr, forkNum, blockNum, (char *) bufBlock);
} else {
XLogRecPtr replayLsn = GetXLogReplayRecPtr(NULL);
nbytes = he3db_mdread(smgr,forkNum, blockNum, &pageXlogBuf, true, replayLsn);
memcpy((char *) bufBlock, pageXlogBuf, BLCKSZ);
}
// } else {
// XLogRecPtr replayLsn = GetXLogReplayRecPtr(NULL);
// nbytes = he3db_mdread(smgr,forkNum, blockNum, &pageXlogBuf, true, replayLsn);
// memcpy((char *) bufBlock, pageXlogBuf, BLCKSZ);
// }
if (track_io_timing)
@ -3221,6 +3221,14 @@ FlushBuffer(BufferDesc *buf, SMgrRelation reln)
* buffer, other processes might be updating hint bits in it, so we must
* copy the page to private storage if we do checksumming.
*/
// PageKey pageKey;
// pageKey.relfileNode.dbNode = buf->tag.rnode.dbNode;;
// pageKey.relfileNode.relNode = buf->tag.rnode.relNode;
// pageKey.relfileNode.spcNode = buf->tag.rnode.spcNode;
// pageKey.blkNo = buf->tag.blockNum;
// pageKey.forkNo = buf->tag.forkNum;
// pageKey.pageLsn = recptr;
bufToWrite = PageSetChecksumCopy((Page) bufBlock, buf->tag.blockNum);
if (track_io_timing)
@ -3229,22 +3237,15 @@ FlushBuffer(BufferDesc *buf, SMgrRelation reln)
/*
* bufToWrite is either the shared buffer or a copy, as appropriate.
*/
// smgrwrite(reln,
// buf->tag.forkNum,
// buf->tag.blockNum,
// bufToWrite,
// false);
smgrwrite(reln,
buf->tag.forkNum,
buf->tag.blockNum,
bufToWrite,
false, recptr);
PageKey pageKey;
pageKey.relfileNode.dbNode = buf->tag.rnode.dbNode;;
pageKey.relfileNode.relNode = buf->tag.rnode.relNode;
pageKey.relfileNode.spcNode = buf->tag.rnode.spcNode;
pageKey.blkNo = buf->tag.blockNum;
pageKey.forkNo = buf->tag.forkNum;
pageKey.pageLsn = BufferGetLSN(buf);
//将page放到本地盘
EvictOnePageOutOfMemory(pageKey, (char *)BufHdrGetBlock(buf));
// EvictOnePageOutOfMemory(pageKey, bufToWrite);
if (track_io_timing)
{
@ -4022,12 +4023,13 @@ FlushRelationBuffers(Relation rel)
error_context_stack = &errcallback;
PageSetChecksumInplace(localpage, bufHdr->tag.blockNum);
XLogRecPtr lsn = BufferGetLSN(bufHdr);
smgrwrite(rel->rd_smgr,
bufHdr->tag.forkNum,
bufHdr->tag.blockNum,
localpage,
false);
false, lsn);
buf_state &= ~(BM_DIRTY | BM_JUST_DIRTIED);
pg_atomic_unlocked_write_u32(&bufHdr->state, buf_state);

View File

@ -223,13 +223,15 @@ LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum,
oreln = smgropen(bufHdr->tag.rnode, MyBackendId);
PageSetChecksumInplace(localpage, bufHdr->tag.blockNum);
XLogRecPtr lsn = PageGetLSN(localpage);
/* And write... */
smgrwrite(oreln,
bufHdr->tag.forkNum,
bufHdr->tag.blockNum,
localpage,
false);
false,
lsn);
/* Mark not-dirty now in case we error out below */
buf_state &= ~BM_DIRTY;

View File

@ -2431,7 +2431,7 @@ MasterFileRead(char *buffer,uint32_t dbid, uint32_t relid, uint32_t forkno, uint
if (bufrd.count > 0)
{
memcpy(buffer,bufrd.buf,bufrd.count);
free_dataRead(bufrd.buf,bufrd.count,bufrd.cap);
free_dataRead(bufrd.buf,1,1);
}
return bufrd.count;

View File

@ -1040,10 +1040,10 @@ mdtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
}
curopensegs--;
}
CachedRelInfo *cached_rel = NULL;
cached_rel = FindCacheRel(&reln->smgr_rnode.node);
if (cached_rel != NULL)
RemoveCacheRel(&reln->smgr_rnode.node);
// CachedRelInfo *cached_rel = NULL;
// cached_rel = FindCacheRel(&reln->smgr_rnode.node);
// if (cached_rel != NULL)
// RemoveCacheRel(&reln->smgr_rnode.node);
}
/*

View File

@ -489,12 +489,12 @@ smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
else
reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
CachedRelInfo *cached_reln;
cached_reln = FindCacheRel(&reln->smgr_rnode.node);
if (cached_reln != NULL)
cached_reln->cached_nblocks[forknum] = blocknum +1;
else
SetupRelCache(&reln->smgr_rnode.node, forknum, blocknum+1);
// CachedRelInfo *cached_reln;
// cached_reln = FindCacheRel(&reln->smgr_rnode.node);
// if (cached_reln != NULL)
// cached_reln->cached_nblocks[forknum] = blocknum +1;
// else
// SetupRelCache(&reln->smgr_rnode.node, forknum, blocknum+1);
}
@ -556,11 +556,25 @@ smgrread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
*/
void
smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
char *buffer, bool skipFsync)
char *buffer, bool skipFsync, XLogRecPtr lsn)
{
PageKey pageKey;
pageKey.relfileNode.dbNode = reln->smgr_rnode.node.dbNode;
pageKey.relfileNode.relNode = reln->smgr_rnode.node.relNode;
pageKey.relfileNode.spcNode = reln->smgr_rnode.node.spcNode;
pageKey.blkNo = blocknum;
pageKey.forkNo = forknum;
pageKey.pageLsn = lsn;
//将page放到本地盘
printf("write page key: dbid %ld, relid %ld, blkno %ld, forkno %ld, pagelsn %ld\n", pageKey.relfileNode.dbNode,
pageKey.relfileNode.relNode, pageKey.blkNo, pageKey.forkNo, pageKey.pageLsn);
EvictOnePageOutOfMemory(pageKey, buffer);
//if (push_standby == true || SmgrIsTemp(reln)) {
smgrsw[reln->smgr_which].smgr_write(reln, forknum, blocknum,
buffer, skipFsync);
// smgrsw[reln->smgr_which].smgr_write(reln, forknum, blocknum,
// buffer, skipFsync);
// elog(LOG,"smgrwrite reln %d,flk %d,blk %d",reln->smgr_rnode.node.relNode,forknum,blocknum);
//}
}
@ -593,24 +607,24 @@ smgrnblocks(SMgrRelation reln, ForkNumber forknum)
/* Check and return if we get the cached value for the number of blocks. */
//if (push_standby != true )
//{
result = smgrnblocks_cached(reln, forknum);
if (result != InvalidBlockNumber)
return result;
// result = smgrnblocks_cached(reln, forknum);
// if (result != InvalidBlockNumber)
// return result;
//}
CachedRelInfo *cached_reln = NULL;
cached_reln = FindCacheRel(&reln->smgr_rnode.node);
if (cached_reln != NULL && cached_reln->cached_nblocks[forknum] != InvalidBlockNumber)
{
reln->smgr_cached_nblocks[forknum] = cached_reln->cached_nblocks[forknum];
return cached_reln->cached_nblocks[forknum];
}
// CachedRelInfo *cached_reln = NULL;
// cached_reln = FindCacheRel(&reln->smgr_rnode.node);
// if (cached_reln != NULL && cached_reln->cached_nblocks[forknum] != InvalidBlockNumber)
// {
// reln->smgr_cached_nblocks[forknum] = cached_reln->cached_nblocks[forknum];
// return cached_reln->cached_nblocks[forknum];
// }
result = smgrsw[reln->smgr_which].smgr_nblocks(reln, forknum);
// elog(LOG, "===exec lseek ===");
if (cached_reln == NULL)
SetupRelCache(&reln->smgr_rnode.node, forknum, result);
else
cached_reln->cached_nblocks[forknum] = result;
// if (cached_reln == NULL)
// SetupRelCache(&reln->smgr_rnode.node, forknum, result);
// else
// cached_reln->cached_nblocks[forknum] = result;
reln->smgr_cached_nblocks[forknum] = result;

View File

@ -97,7 +97,7 @@ extern void smgrread(SMgrRelation reln, ForkNumber forknum,
extern int he3dbsmgrread(SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, char **buffer, XLogRecPtr lsn);
extern void smgrwrite(SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, char *buffer, bool skipFsync);
BlockNumber blocknum, char *buffer, bool skipFsync, XLogRecPtr lsn);
extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, BlockNumber nblocks);
extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);