Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ideawu/f0d859e4c2ac369c8c3d264f7b255bd3 to your computer and use it in GitHub Desktop.

Select an option

Save ideawu/f0d859e4c2ac369c8c3d264f7b255bd3 to your computer and use it in GitHub Desktop.
一种不依赖事务管理中心实现事务原子性的方法: 参与者单向环
  • 在 Prepare 阶段, 将所有参与者以单向环的方式连接起来, 同时 Prepare 变更
  • 单向环一旦建立起来, 事务便已自动 Commit
  • 依次将所有参与者 Commit
  • 所有参与者都 Committed 之后, 依次解除单向环.

如果事务异常中断, 那么正常的读取流程读取到任意一个参与者时, 开始检测圆环. 若能检测到, 便能判断出事务的状态(Committed). 若圆环断开, 则事务处于 Aborted 状态.

@ideawu
Copy link
Copy Markdown
Author

ideawu commented Dec 11, 2020

如果是乐观事务(缓冲式执行), 因为 prepare 阶段已经知道所有参与者, 所以不需要圆环. 选出一个资源作为 primary key, primary 指向 secondaries, 每一个 secondary 指向 primary. 一旦指向完成, 事务即自动提交. 接着, commit primary key, 再依次 commit secondary.

悲观事务(交互式执行)需要用圆环, 因为交互的过程就是建立圆环.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment