修复双集群首备读问题

This commit is contained in:
chenzhikai
2024-09-06 11:42:11 +08:00
parent 74a5a15d0b
commit f2e9811864
5 changed files with 21 additions and 10 deletions

View File

@ -402,6 +402,7 @@ static void knl_t_xlog_init(knl_t_xlog_context* xlog_cxt)
xlog_cxt->LocalXLogInsertAllowed = -1;
xlog_cxt->ArchiveRecoveryRequested = false;
xlog_cxt->InArchiveRecovery = false;
xlog_cxt->inRedoExtendSegment = false;
xlog_cxt->ArchiveRestoreRequested = false;
xlog_cxt->restoredFromArchive = false;
xlog_cxt->recoveryRestoreCommand = NULL;

View File

@ -1166,7 +1166,12 @@ static bool DispatchRepOriginRecord(XLogReaderState *record, List *expectedTLIs,
/* Run from the dispatcher thread. */
static bool DispatchCLogRecord(XLogReaderState *record, List *expectedTLIs, TimestampTz recordXTime)
{
DispatchTxnRecord(record, expectedTLIs, recordXTime, false);
uint8 info = XLogRecGetInfo(record) & (~XLR_INFO_MASK);
if (info == CLOG_ZEROPAGE) {
DispatchRecordWithoutPage(record, expectedTLIs);
} else {
DispatchTxnRecord(record, expectedTLIs, recordXTime, false);
}
return false;
}

View File

@ -2568,7 +2568,7 @@ Buffer ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber fork
* head may be re-used, i.e., the relfilenode may be reused. Thus the
* smgrnblocks interface can not be used on standby. Just skip this check.
*/
} else if (RecoveryInProgress() && !IsSegmentFileNode(smgr->smgr_rnode.node)) {
} else if (RecoveryInProgress()) {
BlockNumber totalBlkNum = smgrnblocks_cached(smgr, forkNum);
/* Update cached blocks */
@ -2576,7 +2576,8 @@ Buffer ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber fork
totalBlkNum = smgrnblocks(smgr, forkNum);
}
if (blockNum >= totalBlkNum) {
if ((blockNum >= totalBlkNum || totalBlkNum == InvalidBlockNumber) &&
!t_thrd.xlog_cxt.inRedoExtendSegment) {
return InvalidBuffer;
}
}

View File

@ -643,6 +643,16 @@ static void redo_atomic_xlog(XLogReaderState *record)
static void redo_seghead_extend(XLogReaderState *record)
{
RedoBufferInfo redo_buf;
t_thrd.xlog_cxt.inRedoExtendSegment = true;
XLogInitBufferForRedo(record, 1, &redo_buf);
t_thrd.xlog_cxt.inRedoExtendSegment = false;
if (BufferIsValid(redo_buf.buf)) {
memset_s(redo_buf.pageinfo.page, BLCKSZ, 0, BLCKSZ);
PageSetLSN(redo_buf.pageinfo.page, redo_buf.lsn);
MarkBufferDirty(redo_buf.buf);
UnlockReleaseBuffer(redo_buf.buf);
}
XLogRedoAction redo_action = XLogReadBufferForRedo(record, 0, &redo_buf);
if (redo_action == BLK_NEEDS_REDO) {
char *data = XLogRecGetBlockData(record, 0, NULL);
@ -667,13 +677,6 @@ static void redo_seghead_extend(XLogReaderState *record)
if (SSCheckInitPageXLogSimple(record, 1, &redo_buf) == BLK_DONE) {
return;
}
XLogInitBufferForRedo(record, 1, &redo_buf);
if (BufferIsValid(redo_buf.buf)) {
memset_s(redo_buf.pageinfo.page, BLCKSZ, 0, BLCKSZ);
PageSetLSN(redo_buf.pageinfo.page, redo_buf.lsn);
MarkBufferDirty(redo_buf.buf);
UnlockReleaseBuffer(redo_buf.buf);
}
}
/*

View File

@ -516,6 +516,7 @@ typedef struct knl_t_xlog_context {
*/
bool ArchiveRecoveryRequested;
bool InArchiveRecovery;
bool inRedoExtendSegment;
bool ArchiveRestoreRequested;
/* Was the last xlog file restored from archive, or local? */