MySQLマスターコピー整合性検出PerconaツールPt-table-checksum

3526 ワード

MySQLマスターレプリケーションでは、重要なテーブルの一貫性チェックが必要になることがよくあります.
プライマリスレーブデータは同期時に一定の遅延があるため,サーバデータを直接読み出す方式では情報の一貫性を厳密に保証することはできない.同期が完全に終了するまで、データは常に変化し、不完全な状態にあります.ロックテーブルはこの問題を実現する可能性がありますが、パフォーマンスは考慮する必要があります.データ検証ができるのが一番です.MySQLの
CHECKSUM TABLE命令は、小型リストでは十分ですが、膨大な規模のリストでは、検査中に負荷が高すぎることを避けるために「ブロック化」処理が必要になります.
PerconaツールPt-table-checksumはテーブルをロックしません.
基本構文:

    Pt-table-checksum   [options]  [DSN]

例:
pt-table-checksum
--databases=monster --tables=abc --replicate-check
h=192.168.1.186,u=chk,p=XXXX,P=3308
 
このツールは、マスター上でchecksum queriesを実行することによって、主にCRC 32関数を使用して参照可能なfuncionパラメータを実現します.これは最も計算しやすく、主従レプリケーションの一貫性を確認し、結果を印刷します.主従データが異なると、異なる結果が発生します.
欠点:サーバ負荷が増加する可能性があります.
--explainオプションの場合、ツールがデータテーブルをどのように検証しているかを確認できます.
このツールはmasterでchecksum queriesを実行し、slaveにコピーします.
同じ時間に1つのテーブルでしか操作できないので、開始前に大量の仕事をしたり、メモリを蓄積したりしてはいけません.
 
 
大規模なテーブルで迅速に動作する理由は、次のとおりです.
it divides each table into chunks of rows
.利用する
REPLACE..SELECT query
それぞれに
chunk
チェックを行います.動的に調整されます
chunk size
(
The tool keeps track of how quickly the server is able to execute the queries, and adjusts the chunks as it learns more about the server’s performance.
指数関数的に減衰した重み付け平均を用いて安定したブロックサイズを維持する).これにより、文全体がテーブル上で1回実行されないようにします.これにより、主従レプリケーションの遅延の可能性を低減することができる.
それぞれに
chunk
チェックを行った場合、タイムアウト時間は
0.5S
.
 
 
chunk sizeのサイズを動的に調整するには、次のようなものが使用されます.
Nibbling’の技術.プライマリ・キーまたは非一意のプライマリ・キーを優先してブロックまたは他のプライマリ・キーを分割し、インデックスがなければテーブルが大きくなければ、テーブルはchunkの雰囲気になります.
 
 
このツールは、レプリケーションを含むデータベースの操作には影響しません.(時計をロックしないという意味です)
pt-table-checksum
detects replicas and connects to them automatically.レプリケーションの遅延が多すぎると、slaveがmasterと同期するまでツールは自動的に一時停止します.コピーに失敗したら、
pt-table-checksum
pauses and waits.出力はありません.
 
       
ツールが実行されると、各chunkでexplainが実行され、大きすぎるとスキップされます.-chunk-size-limitで制限できます.
If a table will be checksummed in a single chunk because it has a small number of rows,
pt-table-checksum
additionally verifies that the table isn’t oversized on replicas
このツールは
slave
この時計はあまり大きくありません.これは避けられる
master
上表時空の
slave
この時計は大きいです.
 
 
master負荷があまり高くないことを保証する方法はいくつかあります.
pt-table-checksum
sets its session-level innodb_lock_wait_timeout to 1 second, so that if there is a lock wait, it will be the victim instead of causing other queries to time out. .負荷が大きすぎると、彼はpauseします.
pt-table-checksum
will pause if there are more than 25 concurrently executing queries. You should probably set a sane value for your server with the
--max-load
option
 
 
pt-table-checksumが意外に停止した場合
-resumeオプションを使用して再起動できます.
 
       
After
pt-table-checksum
finishes checksumming all of the chunks in a table, it pauses and waits for all detected replicas to finish executing the checksum queries. Once that is finished,
it checks all of the replicas to see if they have the same data as the master, and then prints a line of output with the results.
It will also print a progress report when it pauses to wait for replication to catch up, and when it is waiting to check replicas for differences from the master
--replicate-check-onlyというオプションを使用すると、異なる検出結果のみが印刷されます.
 
記事オリジナルリンク:http://weipengfei.blog.51cto.com/1511707/976545
参考資料:http://blog.chinaunix.net/uid-16844903-id-3360228.html