1. TSO 状态在 etcd 中的存储
TSO 的持久化根键是 rootcoord/timestamp(RootCoord 专用的路径),值是一个 64 位无符号整数,表示上一次已经分配出去的最大时间戳(lastSavedTimestamp)。
键:
rootcoord/timestamp值:8 字节小端序
uint64操作保证:所有读写通过 etcd 事务(Txn) 实现原子 Compare-And-Swap(CAS),确保没有并发竞争。
2. etcd 事务细节:原子更新时间戳
2.1 核心流程(saveTimestamp 函数)
在 internal/tso/tso.go 中,timestampAllocator 的 saveTimestamp 方法执行以下原子操作:
读取当前 etcd 值:先通过
clientv3.Get获取