diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c index dd0c124..c1c5998 100644 --- a/contrib/pg_visibility/pg_visibility.c +++ b/contrib/pg_visibility/pg_visibility.c @@ -398,7 +398,7 @@ pg_truncate_visibility_map(PG_FUNCTION_ARGS) if (BlockNumberIsValid(block)) { fork = VISIBILITYMAP_FORKNUM; - smgrtruncate(rel->rd_smgr, &fork, 1, &block); + smgrtruncatelsn(rel->rd_smgr, &fork, 1, &block); } if (RelationNeedsWAL(rel)) @@ -411,7 +411,10 @@ pg_truncate_visibility_map(PG_FUNCTION_ARGS) XLogBeginInsert(); XLogRegisterData((char *) &xlrec, sizeof(xlrec)); - + if (IsBootstrapProcessingMode() != true && InitdbSingle != true) { + RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT + | CHECKPOINT_FLUSH_ALL); + } XLogInsert(RM_SMGR_ID, XLOG_SMGR_TRUNCATE | XLR_SPECIAL_REL_UPDATE); } diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 282cd8b..a5d5898 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8054,7 +8054,6 @@ data_buffer_for_replay(XLogReaderState *record,XLogRecPtr startLsn,XLogRecPtr en uint32 buf_state; bool valid; BufferDesc *buf; - /* See if the block is in the buffer pool already */ //for pg master he3db slave or backup restore SMgrRelation smgr = smgropen(rnode, InvalidBackendId); smgrcreate(smgr, forknum, true); @@ -8070,6 +8069,7 @@ data_buffer_for_replay(XLogReaderState *record,XLogRecPtr startLsn,XLogRecPtr en } else { elog(PANIC,"data_buffer_for_replay blockNum is P_NEW"); } + /* See if the block is in the buffer pool already */ LWLockAcquire(partition_lock, LW_SHARED); buf_id = BufTableLookup(&tag, hash); /* If page is in buffer, we can apply record, otherwise we do nothing */ diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index d25d41b..63a3368 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -350,7 +350,10 @@ RelationTruncate(Relation rel, BlockNumber nblocks) XLogBeginInsert(); XLogRegisterData((char *) &xlrec, sizeof(xlrec)); - + if (IsBootstrapProcessingMode() != true && InitdbSingle != true) { + RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT + | CHECKPOINT_FLUSH_ALL); + } lsn = XLogInsert(RM_SMGR_ID, XLOG_SMGR_TRUNCATE | XLR_SPECIAL_REL_UPDATE); diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index d13608b..113b765 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -1034,7 +1034,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, } while (!StartBufferIO(bufHdr, true)); } } - + /* * if we have gotten to this point, we have allocated a buffer for the * page but its contents are not yet valid. IO_IN_PROGRESS is set for it, @@ -1172,6 +1172,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, } } } + bufHdr->pageIsVaild = true; } } else { smgrread(smgr, forkNum, blockNum, (char *) bufBlock); @@ -1476,8 +1477,12 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, * If we get here, previous attempts to read the buffer must * have failed ... but we shall bravely try again. */ + if (buf->pageIsVaild == false) { + *exist = false; + } else { + *exist = true; + } *foundPtr = false; - *exist = true; } } @@ -1696,6 +1701,11 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, * If we get here, previous attempts to read the buffer * must have failed ... but we shall bravely try again. */ + if (buf->pageIsVaild == false) { + *exist = false; + } else { + *exist = true; + } *foundPtr = false; } } @@ -1748,7 +1758,7 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, buf_state |= BM_TAG_VALID | BM_PERMANENT | BUF_USAGECOUNT_ONE; else buf_state |= BM_TAG_VALID | BUF_USAGECOUNT_ONE; - + buf->pageIsVaild = false; UnlockBufHdr(buf, buf_state); if (oldPartitionLock != NULL) @@ -1766,8 +1776,14 @@ BufferAlloc(SMgrRelation smgr, char relpersistence, ForkNumber forkNum, * to read it before we did, so there's nothing left for BufferAlloc() to * do. */ - if (StartBufferIO(buf, true)) + if (StartBufferIO(buf, true)) { + if (buf->pageIsVaild == false) { + *exist = false; + } else { + *exist = true; + } *foundPtr = false; + } else *foundPtr = true; diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h index 9661f83..afc64fd 100644 --- a/src/include/storage/buf_internals.h +++ b/src/include/storage/buf_internals.h @@ -55,6 +55,7 @@ * Note: BM_TAG_VALID essentially means that there is a buffer hashtable * entry associated with the buffer's tag. */ + #define BM_LOCKED (1U << 22) /* buffer header is locked */ #define BM_DIRTY (1U << 23) /* data needs writing */ #define BM_VALID (1U << 24) /* data is valid */ @@ -197,6 +198,7 @@ typedef struct BufferDesc int wait_backend_pid; /* backend PID of pin-count waiter */ int freeNext; /* link in freelist chain */ LWLock content_lock; /* to lock access to buffer contents */ + bool pageIsVaild; } BufferDesc; extern BufferDesc **bulk_io_in_progress_buf;