fix(opengauss-commit-ts): include storage/spin.h explicitly and document the epoch-zero commit-time sentinel.
Signed-off-by: 林晨 (Leo Cheng) leo-cheng@vip.qq.com
openGauss track-1 problem-3: reverse-lookup a transaction commit time from its xid (track_commit_timestamp / commit_ts SLRU).
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
opengauss-commit-ts
openGauss 特性开发赛 · 赛题三「事务 ID 反查事务提交时间」的内核实现。
给定一个事务 ID(xid),反查它实际提交的墙钟时间。用于审计合规、问题定位 (把
xmin/xmax对上真实时刻)、数据变更时序回溯——不引入触发器/审计表, 每个已提交事务只多留一个轻量的提交时间戳。gitlink.org.cn/opengaussexamples/examples(决赛以 PR 形式提交回上游)comps/gitlink/track1_2026openGauss/特性设计文档.md思路
openGauss 源自 PostgreSQL 9.2.4,分叉早于 PG 9.5 的
commit_ts,内核里没有这个特性 (已实爬全仓确认无任何残留)。但 openGauss 自带一个几乎同构的现成范本——csnlog (xid → 定长 CSN的 SLRU)。本实现以 csnlog 为一比一模板改造成xid → 定长提交时间戳的 SLRU,天然贴合 openGauss 线程池模型与全局变量组织(g_instance/t_thrd/u_sess), 合并摩擦最小。track_commit_timestamp(PGC_POSTMASTER,默认 off,零开销)pg_commit_tsSLRU 存储:xid 作页内下标,O(1) 反查;崩溃恢复 / WAL / vacuum 截断全复用xactStopTimestamp写入映射;该值即写进 commit WAL 记录 (xl_xact_commit.xact_time)的同一时间,故备机 / 崩溃重放用 WAL 自带时间重建,无需新 rmgrpg_xact_commit_timestamp(xid) → timestamptz、pg_last_committed_xact() → (xid, timestamp)目录
状态
selftest/RESULTS.txt)。docs/BUILD_AND_TEST.md)。许可证:Mulan PSL v2(与 openGauss 一致)。