本节简单介绍了XLOG全局(所有进程之间)共享的数据结构:XLoGCtlData和XLogCtlInsert。在这两个结构体中,存储了REDO point/Lock等相关重要的信息
本节简单介绍了XLOG全局(所有进程之间)共享的数据结构:XLoGCtlData和XLogCtlInsert。在这两个结构体中,存储了REDO point/Lock等相关重要的信息.
XLogCtlInsert
WAL插入记录时使用的共享数据结构
typedef struct XLogCtlInsert
{
//包含CurrBytePos和PrevBytePos的lock
slock_t insertpos_lck;
uint64 CurrBytePos;
uint64 PrevBytePos;
char pad[PG_CACHE_LINE_SIZE];
//插入时的当前redo point
XLogRecPtr RedoRecPtr;
//为PITR强制执行full-page写?
bool forcePageWrites;
//是否全页写?
bool fullPageWrites;
ExclusiveBackupState exclusiveBackupState;
int nonExclusiveBackups;
XLogRecPtr lastBackupStart;
WALInsertLockPadded *WALInsertLocks;
} XLogCtlInsert;
XLogCtl
XLOG的所有共享内存状态信息
typedef struct XLogCtlData
{
XLogCtlInsert Insert;//插入控制器
//------ 通过info_lck锁保护
XLogwrtRqst LogwrtRqst;
//Insert->RedoRecPtr最近的拷贝
XLogRecPtr RedoRecPtr;
//最后的checkpoint的nextXID & epoch
uint32 ckptXidEpoch;
TransactionId ckptXid;
//最新异步提交/回滚的LSN
XLogRecPtr asyncXactLSN;
//slot需要的最"老"的LSN
XLogRecPtr replicationSlotMinLSN;
//最后移除/回收的XLOG段
XLogSegNo lastRemovedSegNo;
//---- "伪装"的LSN计数器,用于不需要记录日志的关系.通过ulsn_lck锁保护
XLogRecPtr unloggedLSN;
slock_t ulsn_lck;
//---- 切换后最新的xlog段的时间线和LSN,通过WALWriteLock锁保护
pg_time_t lastSegSwitchTime;
XLogRecPtr lastSegSwitchLSN;
XLogwrtResult LogwrtResult;
XLogRecPtr InitializedUpTo;
//未写入的XLOG pages的缓存
char *pages;
//ptr-s的第一个字节 + XLOG_BLCKSZ
XLogRecPtr *xlblocks;
//已分配的xlog缓冲的索引最高值
int XLogCacheBlck;
TimeLineID ThisTimeLineID;
TimeLineID PrevTimeLineID;
bool SharedRecoveryInProgress;
bool SharedHotStandbyActive;
bool WalWriterSleeping;
Latch recoveryWakeupLatch;
XLogRecPtr lastCheckPointRecPtr;
XLogRecPtr lastCheckPointEndPtr;
CheckPoint lastCheckPoint;
XLogRecPtr lastReplayedEndRecPtr;
TimeLineID lastReplayedTLI;
XLogRecPtr replayEndRecPtr;
TimeLineID replayEndTLI;
//最后的COMMIT/ABORT回放(或正在回放)记录的时间戳
TimestampTz recoveryLastXTime;
TimestampTz currentChunkStartTime;
//是否请求暂停恢复
bool recoveryPause;
XLogRecPtr lastFpwDisableRecPtr;
//锁结构
slock_t info_lck;
} XLogCtlData;
static XLogCtlData *XLogCtl = NULL;
跟踪任意一个后台进程,打印全局变量XLogCtl.
(gdb) p XLogCtl
$6 = (XLogCtlData *) 0x7f391e00ea80
(gdb) p *XLogCtl
$7 = {Insert = {insertpos_lck = 0 '\000', CurrBytePos = 5494680728, PrevBytePos = 5494680616,
pad = '\000' <repeats 127 times>, RedoRecPtr = 5510830896, forcePageWrites = false, fullPageWrites = true,
exclusiveBackupState = EXCLUSIVE_BACKUP_NONE, nonExclusiveBackups = 0, lastBackupStart = 0,
WALInsertLocks = 0x7f391e013100}, LogwrtRqst = {Write = 5510831008, Flush = 5510831008}, RedoRecPtr = 5510830896,
ckptXidEpoch = 0, ckptXid = 2036, asyncXactLSN = 5510830896, replicationSlotMinLSN = 0, lastRemovedSegNo = 0,
unloggedLSN = 1, ulsn_lck = 0 '\000', lastSegSwitchTime = 1545962218, lastSegSwitchLSN = 5507670464, LogwrtResult = {
Write = 5510831008, Flush = 5510831008}, InitializedUpTo = 5527601152, pages = 0x7f391e014000 "\230\320\006",
xlblocks = 0x7f391e00f088, XLogCacheBlck = 2047, ThisTimeLineID = 1, PrevTimeLineID = 1,
arcHiveCleanupCommand = '\000' <repeats 1023 times>, SharedRecoveryInProgress = false, SharedHotStandbyActive = false,
WalWriterSleeping = true, recoveryWakeupLatch = {is_set = 0, is_shared = true, owner_pid = 0}, lastCheckPointRecPtr = 0,
lastCheckPointEndPtr = 0, lastCheckPoint = {redo = 0, ThisTimeLineID = 0, PrevTimeLineID = 0, fullPageWrites = false,
nextXidEpoch = 0, nextXid = 0, nextOid = 0, nextMulti = 0, nextMultiOffset = 0, oldestXid = 0, oldestXidDB = 0,
oldestMulti = 0, oldestMultiDB = 0, time = 0, oldestCommitTsXid = 0, newestCommitTsXid = 0, oldestActiveXid = 0},
lastReplayedEndRecPtr = 0, lastReplayedTLI = 0, replayEndRecPtr = 0, replayEndTLI = 0, recoveryLastXTime = 0,
currentChunkStartTime = 0, recoveryPause = false, lastFpwDisableRecPtr = 0, info_lck = 0 '\000'}
(gdb)
其中:
1.XLogCtl->Insert是XLogCtlInsert结构体变量.
2.RedoRecPtr为5510830896 -> 1/48789B30,该值与pg_control文件中的REDO location相对应.
[xdb@localhost ~]$ pg_controldata|grep REDO
Latest checkpoint's REDO location: 1/48789B30
Latest checkpoint's REDO WAL file: 000000010000000100000048
3.ThisTimeLineID&PrevTimeLineID,时间线ID,值为1.
其他相关信息可对照结构体定义阅读.
postgresql 源码解读(4)- 插入数据#3(heap_insert)
PG Source Code
--结束END--
本文标题: PostgreSQL 源码解读(112)- WAL#8(XLogCtrl数据结构)
本文链接: https://lsjlt.com/news/49524.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0