Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
2PC between Binlog and InnoDB
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
tom--bo
May 21, 2024
1
340
2PC between Binlog and InnoDB
tom--bo
May 21, 2024
Tweet
Share
More Decks by tom--bo
See All by tom--bo
DDLが取得するMDLの調査(私的)まとめ
tombo
3
140
安全なDDLの実行を目指して 〜(その1)取得するMDLの把握〜
tombo
0
150
SQL SECURITY特性の扱いと作ったパッチ
tombo
1
85
MyRaft論文紹介
tombo
3
940
WIP: 2PC between binlog and InnoDB
tombo
1
250
Dive into InnoDB from redo logs
tombo
3
1.7k
MySQLアンカンファレンス01_mysqlredo
tombo
1
970
MySQLアンカンファレンス 開催概要
tombo
0
310
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
Why Our Code Smells
bkeepers
PRO
340
58k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Color Theory Basics | Prateek | Gurzu
gurzu
0
190
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Test your architecture with Archunit
thirion
1
2.1k
Technical Leadership for Architectural Decision Making
baasie
1
220
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
82
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.6k
Accessibility Awareness
sabderemane
0
42
Transcript
binlogとinnodbの2PC @MySQLアンカンファレンス #004 (2024/05/20) tom__bo
疑問 • redoログばかり⾒ていたけど、binlogとの関係は? • ファイルが違うので、binlogでコミットされていて、innodb(redo log)でコ ミットされていない事はありえる? • => どうやら2
Phase Commit (2PC)しているらしい • https://www.slideshare.net/takanorisejima/binary-log-2pc-group-commit • by @ts4thさん • 5.7.12時点の主要なクラスや関数を列挙しながら説明がされている • => 8.0.32での実装を調査してみた(今回の内容) • 以前8.0.28くらいの頃に整理したのですが、結構変わってました
2 Phase Commitとは • 分散システム上で調停者と参加者の全員がコミットするか、 アボートするか決定するAtomic Commitment Protocolの1つ • 最初のフェーズでvote(prepare)を⾏い、全参加者がYesだったら、
第2フェーズでCommit, そうでなければAbortメッセージを送る Coordinator Partitcipant Partitcipant 2. Yes 2’. Yes 1. Vote? Coordinator Partitcipant Partitcipant 3. Commit 3. Commit 3’. Commit
2PCのイメージ
2PCのリカバリイメージ • 各コンポーネントでメッセージの送信前にログを書く • 復旧後にコンポーネントでVoteに”Yes”, コーディネータに Commitのログが残っていたら復元 System Failure
BinlogとInnoDB間の2PC • リカバリのために利⽤ • システム障害時に、両者がCommitに合意したTxをリカバリ • サーバで発番するXIDを基準にして2PCを進⾏ • トランザクションコーディネータ(TC_LOG)が調停 •
binlogとの2PCはMYSQL_BIN_LOGクラスが進⾏ 2PCってコンセンサスとしてはあまり良くないんじゃなかった? Þ BInlogとInnoDBは分散していない(同⼀プロセス中の別コンポーネント) Þ コーディネータがSPOF、タイムアウトどう扱うか問題は気にしなくて良い
BinlogとInnoDB間の2PCとリカバリ • 通常処理は基本的に2PCの流れと同じ • メッセージの送受信ではなくて関数の呼び出し • XIDはTHD構造体に参加者が取りに⾏く • リカバリはBinlogでのコミットが基準 •
2フェーズ⽬のコミットの処理中にシステム障害が発⽣した場合、 Binlogでコミット(xidイベントの永続化)できていて、InnoDBでPrepare できているトランザクションはコミット済みとしてリカバリ
BinlogとInnoDB間の2PCのイメージ
INSERT処理の流れ • BEGIN; INSERT INTO ...; COMMIT;を実⾏し、その時の処理の流れ を整理する • “主要コンポーネント”で説明したServer,
Hander, MYSQL_BINLOG, InnoDB, Binlog間の関数呼び出しの流れを⽰す • シーケンス図画像は以下 • https://drive.google.com/drive/u/0/folders/1HRpvFq7YRxWOMx1gxdoLjd A7oqTCQeUa?ths=true
(シーケンス図で説明)
MySQL 2PCからのリカバリ 1. 最後のbinlogファイルに書かれているxid⼀覧を取得 • Binlog_recovery::recover() 2. xidのうち、innodbでprepareされているものTXをcommit • innobase_xa_recover()
-> trx_recover_for_mysql()
Future work • 2PC(TC_LOG)のインタフェース整理 • Abortするケースの処理 • トランザクショナルでないSEの対応 • InnoDBの実装に依存しているように⾒えるが他のAPIもあるのか?
• Binlogがレプリカに送信されるタイミングがいつなのか調査 • Semi-syncレプリのackを待つのは度のタイミングか? • Group Commit (and/or Ordered Commit)の仕組みの詳細調査 • 細かい確認事項 • cache_mngr->trx_cache.finalize()とGTID取得の前後関係
None