txn

command
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

txn 示例:跨域原子事务——扣钱包 + 写存档,任一失败全回滚。

演示 pkg/txn 的两阶段提交:用 staging(副本)视图操作,Prepare 暂存、 Commit 落库、Rollback 丢弃。这里用内存快照模拟:Prepare 前深拷贝主库, Commit 把 staging swap 成主库,Rollback 丢弃 staging。

场景:购买道具——扣金币 + 写背包存档。扣费后存档若失败,金币必须退还。

跑:go run ./examples/txn

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL