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"color: #ff0000">二、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的条件?
XLogReadRecord(xlogreader, ControlFile->checkPoint, &errormsg)
targetPagePtr = ControlFile->checkPoint - (ControlFile->checkPoint % XLOG_BLCKSZ);
targetRecOff = ControlFile->checkPoint % XLOG_BLCKSZ;
readOff = ReadPageInternal(state,targetPagePtr, Min(targetRecOff + SizeOfXLogRecord, XLOG_BLCKSZ));
pageHeaderSize = XLogPageHeaderSize((XLogPageHeader) state->readBuf);
record = (XLogRecord *) (state->readBuf + RecPtr % XLOG_BLCKSZ);
total_len = record->xl_tot_len;
-------------
1、readOff < 0
2、0< targetRecOff < pageHeaderSize
3、(((XLogPageHeader) state->readBuf)->xlp_info & XLP_FIRST_IS_CONTRECORD) && targetRecOff == pageHeaderSize
page头有跨页的record并且checkpoint定位的偏移正好在页头尾部
4、targetRecOff <= XLOG_BLCKSZ - SizeOfXLogRecord &&
!ValidXLogRecordHeader(state, ControlFile->checkPoint, state->ReadRecPtr, record,randAccess)
---(record->xl_tot_len < SizeOfXLogRecord || record->xl_rmid > RM_MAX_ID || record->xl_prev != state->ReadRecPtr)
5、targetRecOff > XLOG_BLCKSZ - SizeOfXLogRecord && total_len < SizeOfXLogRecord
6、total_len > state->readRecordBufSize && !allocate_recordbuf(state, total_len)
一旦该记录损坏,total_len的长度非常大的话,就需要allocate_recordbuf扩展state->readbuf,可能因此分配失败abort
记录的checksum需要等待全部读取完整记录后才校验
-------------
三、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 "htmlcode">
五、WaitForWALToBecomeAvailable何时返回false? --XLOG_FROM_ARCHIVE | XLOG_FROM_PG_WAL 总结 以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。
/*
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
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
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]