在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、首先读取ControlFile->checkPoint指向的checkpoint 2、如果读取失败,slave直接abort退出,master再次读取ControlFile->prevCheckPoint指向的checkpoint StartupXLOG-> |--checkPointLoc = ControlFile->checkPoint; |--record = ReadCheckpointRecord(xlogreader, checkPointLoc, 1, true): |-- if (record != NULL){ ... }else if (StandbyMode){ ereport(PANIC,(errmsg("could not locate a valid checkpoint record"))); }else{ checkPointLoc = ControlFile->prevCheckPoint; record = ReadCheckpointRecord(xlogreader, checkPointLoc, 2, true); if (record != NULL){ InRecovery = true;//标记下面进入recovery }else{ ereport(PANIC,(errmsg("could not locate a valid checkpoint record"))); } } 一、那么什么条件下读取的checkpoint记录record==NULL?
二、ReadRecord函数返回NULL的条件 ReadRecord(xlogreader, ControlFile->checkPoint, LOG, true) |--record = XLogReadRecord(xlogreader, ControlFile->checkPoint, &errormsg); |-- 2.1 record==NULL && !StandbyMode |-- 2.2 record!=NULL && !tliInHistory(xlogreader->latestPageTLI, expectedTLEs) /*----- note:只要读取了一页xlog,就会赋值为该页第一个记录的时间线 XLogReaderValidatePageHeader -->xlogreader->latestPageTLI=hdr->xlp_tli; ------*/ 三、XlogReadRecord读取checkpoint返回NULL的条件?
三、ReadPageInternal返回的readOff返回小于0的条件 ReadPageInternal(state,targetPagePtr, Min(targetRecOff + SizeOfXLogRecord, XLOG_BLCKSZ)) 1、第一次read wal文件,readLen = state->read_page:读取第一页。readLen < 0 2、readLen>0 && !XLogReaderValidatePageHeader(state, targetSegmentPtr, state->readBuf) 3、读取checkpoint所在页readLen = state->read_page: readLen < 0 4、readLen > 0 && readLen <= SizeOfXLogShortPHD 5、!XLogReaderValidatePageHeader(state, pageptr, (char *) hdr) 四、XLogPageRead何时返回值<0 ? /* 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?
总结 以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对极客世界的支持。 |
请发表评论