PostgreSQL事务快照源码分析

  • 源码版本:PG 13.3
  • 源码文件:src/backend/utils/time/snapmgr.c

1. 事务快照数据结构

typedef struct SnapshotData { SnapshotType snapshot_type; /* type of snapshot */ TransactionId xmin; /* all XID = xmax are invisible to me */ TransactionId *xip; uint32 xcnt; /* # of xact ids in xip[] */ TransactionId *subxip; int32 subxcnt; /* # of xact ids in subxip[] */ bool suboverflowed; /* has the subxip array overflowed? */ CommandId curcid; /* in my xact, CID < curcid are visible */ uint32 speculativeToken; uint32 active_count; /* refcount on ActiveSnapshot stack */ uint32 regd_count; /* refcount on RegisteredSnapshots */ pairingheap_node ph_node; /* link in the RegisteredSnapshots heap */ TimestampTz whenTaken; /* timestamp when snapshot was taken */ XLogRecPtr lsn; /* position in the WAL stream when taken */ } SnapshotData;