/*
1、WaitForWALToBecomeAvailable open失败
2、lseek 失败 && !StandbyMode
3、read失败 && !StandbyMode
4、校验page头失败 && !StandbyMode
如果是StandbyMode,则会重新retry->WaitForWALToBecomeAvailable,切换日志源进行open
*/
!WaitForWALToBecomeAvailable(targetPagePtr + reqLen,private->randAccess,1,targetRecPtr)//open
|-- return -1
readOff = targetPageOff;
if (lseek(readFile, (off_t) readOff, SEEK_SET) < 0){
!StandbyMode:: return -1
}
if (read(readFile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ){
!StandbyMode:: return -1
}
XLogReaderValidatePageHeader(xlogreader, targetPagePtr, readBuf)
!StandbyMode:: return -1
五、WaitForWALToBecomeAvailable何时返回false?
--XLOG_FROM_ARCHIVE | XLOG_FROM_PG_WAL
1、先XLogFileReadAnyTLI open日志:
1、遍历时间线列表里的每一个时间线,从最新的开始
2、当读取checkpoint的时候,source是XLOG_FROM_ANY
3、先找归档的日志进行open;如果open失败再找WAL日志进行open
4、如果都没有open成功,则向前找时间线,open前一个时间线segno和文件号相同的文件进行open
5、open成功后expectedTLEs被赋值为当前时间线列表的所有值
2、如果open失败,则切换日志源:XLOG_FROM_ARCHIVE | XLOG_FROM_PG_WAL -> XLOG_FROM_STREAM
3、切换日志源后,XLOG_FROM_ARCHIVE | XLOG_FROM_PG_WAL 则:
slave && promote :return false
!StandbyMode:return false
--XLOG_FROM_STREAM
1、!WalRcvStreaming()即receiver进程挂了,切换日志源
2、CheckForStandbyTrigger()切换日志源
3、XLOG_FROM_STREAM->XLOG_FROM_ARCHIVE
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx