(完整流程在log_heap_update)
1 注册阶段
(1)用两个registered_buffers记录新旧页面buffer
代码语言:javascript复制XLogRegisterBuffer(0, newbuf, bufflags);
XLogRegisterBuffer(1, oldbuf, REGBUF_STANDARD);
(2)注册maindata【SizeOfHeapUpdate大小:14】
代码语言:javascript复制XLogRegisterData((char *) &xlrec, SizeOfHeapUpdate);
/* 关于 update / hot update需要知道的信息 */
typedef struct xl_heap_update
{
TransactionId old_xmax; /* xmax of the old tuple */
OffsetNumber old_offnum; /* old tuple's offset */
uint8 old_infobits_set; /* infomask bits to set on old tuple */
uint8 flags;
TransactionId new_xmax; /* xmax of the new tuple */
OffsetNumber new_offnum; /* new tuple's offset */
/*
* If XLOG_HEAP_CONTAINS_OLD_TUPLE or XLOG_HEAP_CONTAINS_OLD_KEY flags are
* set, a xl_heap_header struct and tuple data for the old tuple follows.
*/
} xl_heap_update;
maindata专用指针
(3)新页面注册元组头【SizeOfHeapHeader大小:5】
代码语言:javascript复制XLogRegisterBufData(0, (char *) &xlhdr, SizeOfHeapHeader);
(4)新页面注册元组数据【数据大小:9】
代码语言:javascript复制XLogRegisterBufData(0,((char *) newtup->t_data) SizeofHeapTupleHeader, newtup->t_len - SizeofHeapTupleHeader - suffixlen);
newbuffer在registered_buffers[0]中记录,挂两个rdata
oldbuffer在registered_buffers[1]中记录,没有挂rdata
2 组装阶段
跨页UPDATE场景下XLogRecordAssemble返回值hdr_rdt都挂了啥?
hdr_rdt挂四个元素:
代码语言:javascript复制----------------------------------------------------------------------------------------
【XLogRecord结构】
XLogRecord << hdr_rdt.data = hdr_scratch;
----------------------------------------------------------------------------------------
【头信息,和下面数据信息一一对应】
(新页面)XLogRecordBlockHeader << memcpy(scratch, &bkpb, SizeOfXLogRecordBlockHeader);
(无)XLogRecordBlockImageHeader << memcpy(scratch, &bimg, SizeOfXLogRecordBlockImageHeader);
(无)XLogRecordBlockCompressHeader << memcpy(scratch, &cbimg, SizeOfXLogRecordBlockCompressHeader);
(新页面)RelFileNode << memcpy(scratch, ®buf->rnode, sizeof(RelFileNode));
(新页面)BlockNumber << memcpy(scratch, ®buf->block, sizeof(BlockNumber));
(旧页面)XLogRecordBlockHeader
(旧页面)BlockNumber
----------------------------------------------------------------------------------------
【数据】
(3)新页面注册元组头【SizeOfHeapHeader大小:5】
----------------------------------------------------------------------------------------
(4)新页面注册元组数据【数据大小:9】
----------------------------------------------------------------------------------------
【MAINDATA】
(2)注册maindata【SizeOfHeapUpdate大小:14】
具体数据:
代码语言:javascript复制4: *hdr_rdt->next->next->next = {next = 0x0, data = 0x7ffc19800b70 "