日志源会在XLOG_FROM_ARCHIVE->XLOG_FROM_STREAM->XLOG_FROM_ARCHIVE直接切换,只有读取过程中出错,就会切换到另外一个日志源。但实际执行过程中,XLOG_FROM_ARCHIVE出错后会到XLOG_FROM_PG_WAL读取,但是日志源的变量并不会改变。这个需要注意。
static int
XLogFileReadAnyTLI(XLogSegNo segno, int emode, int source)
{
if (expectedTLEs)
tles = expectedTLEs;
else
tles = readTimeLineHistory(recoveryTargetTLI);
/*
1、WaitForWALToBecomeAvailable调用时,source是XLOG_FROM_ARCHIVE时,会使用XLOG_FROM_ANY
2、使用XLOG_FROM_ANY,会首先从归档中读取xlog,如果open失败,则会使用XLOG_FROM_PG_WAL
3、外部日志源变量并没有切换
*/
foreach(cell, tles){
TimeLineID tli = ((TimeLineHistoryEntry *) lfirst(cell))->tli;
if (tli < curFileTLI)
break; /* don't bother looking at too-old TLIs */
if (source == XLOG_FROM_ANY || source == XLOG_FROM_ARCHIVE){
fd = XLogFileRead(segno, emode, tli,XLOG_FROM_ARCHIVE, true);
if (fd != -1){
if (!expectedTLEs)
expectedTLEs = tles;
return fd;
}
}
if (source == XLOG_FROM_ANY || source == XLOG_FROM_PG_WAL){
fd = XLogFileRead(segno, emode, tli, XLOG_FROM_PG_WAL, true);
if (fd != -1){
if (!expectedTLEs)
expectedTLEs = tles;
return fd;
}
}
}
return -1;
}
转载于:https://blog.51cto.com/yanzongshuai/2306988