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
tom--bo
May 21, 2024
1
280
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
110
安全なDDLの実行を目指して 〜(その1)取得するMDLの把握〜
tombo
0
100
SQL SECURITY特性の扱いと作ったパッチ
tombo
1
70
MyRaft論文紹介
tombo
3
890
WIP: 2PC between binlog and InnoDB
tombo
1
220
Dive into InnoDB from redo logs
tombo
3
1.5k
MySQLアンカンファレンス01_mysqlredo
tombo
1
790
MySQLアンカンファレンス 開催概要
tombo
0
300
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
The World Runs on Bad Software
bkeepers
PRO
70
11k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
21
1.3k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
840
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
We Have a Design System, Now What?
morganepeng
53
7.7k
GitHub's CSS Performance
jonrohan
1031
460k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
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