MySQLプロトコルの口では "CALL" ステートメントをフックして(というか単にクエリーを正規表現でマッチさせて) MySQL Fabricの各種APIを呼べるようになっている。
=> 日々の覚書: MySQL Fabricつらい(Fabricサーバー上のMySQLプロトコルの口でFabricのAPIが呼べる編)
ので、これを使うことにする。叩くAPIはたぶんこの辺。
mysqlfabric | mysql | 用途 |
---|---|---|
mysqlfabric manage ping | CALL manage.ping() | mysqlfabricデーモンが生きてるかどうか |
mysqlfabric statistics node | CALL statistics.node() | node_uptime, node_startupを見たいとき |
mysqlfabric group lookup_groups | CALL group.lookup_groups() | group_idをここで取る |
mysqlfabric group health ‘group_id’ | CALL group.health(‘group_id’) | is_alive, status, is_not_runningとか見どころがいっぱい |
my $conn= DBI->connect("dbi:mysql:;host=fabric_ipaddr;port=32275", "fabric_usser", "fabric_password", {RaiseError => 1, PrintError => 0, mysql_connect_timeout => 1, mysql_read_timeout => 1, mysql_write_timeout => 1}); my $manage_ping= $conn->prepare("CALL manage.ping()"); $manage_ping->execute; my $lookup_groups= $conn->prepare("CALL group.lookup_groups()"); $lookup_groups->execute; $lookup_groups->fetchall_arrayref(); ### Skip because 1st Result set is fabric's uuid. $lookup_groups->more_results; ### Go ahead to next Result set. foreach my $group (@{$lookup_groups->fetchall_arrayref({})}) { my $group_id= $group->{group_id}; my $group_health= $conn->prepare("CALL group.health(?)"); $group_health->execute($group_id); $group_health->fetchall_arrayref(); ### Skip because 1st Result set is fabric's uuid. $group_health->more_results; ### Go ahead to next Result set. my $primary_server= ""; foreach my $server (@{$group_health->fetchall_arrayref({})}) { if ($server->{io_not_running} || $server->{sql_not_running}) { critf("group_health is something wrong: %s", $server); } else { $primary_server= $server->{uuid} if $server->{status} eq "PRIMARY"; } } critf("There's no PRIMARY state server in %s", $group_id) unless $primary_server; }
CALL group.lookup_groups();
(をはじめとする色々なストアドプロシージャもどきの)戻りが複数の結果セットをカジュアルに返すので、生まれて初めて more_results なんてメソッド を呼んだ。manage pingなんかは1つしか返さないので、本当はちゃんとループさせて "TTL" が入ってたら多分応答ヘッダーの方だとか判定した方がいいんだろう(たぶん、する)$ mysqlfabric group lookup_groups Fabric UUID: 5ca1ab1e-a007-feed-f00d-cab3fe13249e Time-To-Live: 1 group_id description failure_detector master_uuid ------------ ----------- ---------------- ------------------------------------ fabric_A None 0 8658f0e6-fb9e-11e5-8c6f-001a4a571800 fabric_B None 1 a1ffe373-3e73-11e6-87b3-001a4a5718ee MySQL [(none)]> CALL group.lookup_groups(); +--------------------------------------+-----+---------+ | fabric_uuid | ttl | message | +--------------------------------------+-----+---------+ | 5ca1ab1e-a007-feed-f00d-cab3fe13249e | 1 | NULL | +--------------------------------------+-----+---------+ 1 row in set (0.01 sec) +--------------+-------------+------------------+--------------------------------------+ | group_id | description | failure_detector | master_uuid | +--------------+-------------+------------------+--------------------------------------+ | fabric_A | NULL | 0 | 8658f0e6-fb9e-11e5-8c6f-001a4a571800 | | fabric_B | NULL | 1 | a1ffe373-3e73-11e6-87b3-001a4a5718ee | +--------------+-------------+------------------+--------------------------------------+ 2 rows in set (0.01 sec)
さて…切り替わりをフックするのはどうしようかな。。threat.report_failureあたりは何のマシな情報も吐いてくれなかった。。
mysql> CALL threat.report_failure('a1ffe373-3e73-11e6-87b3-001a4a5718ee'); +--------------------------------------+-----+---------+ | fabric_uuid | ttl | message | +--------------------------------------+-----+---------+ | 5ca1ab1e-a007-feed-f00d-cab3fe13249e | 1 | NULL | +--------------------------------------+-----+---------+ 1 row in set (0.58 sec) +--------------------------------------+----------+---------+--------+ | uuid | finished | success | result | +--------------------------------------+----------+---------+--------+ | 90517342-6a1f-424f-bed3-7a65f6140167 | 1 | 1 | 1 | +--------------------------------------+----------+---------+--------+ 1 row in set (0.58 sec) +-------+---------+---------------+---------------------------------------------------------------+ | state | success | when | description | +-------+---------+---------------+---------------------------------------------------------------+ | 3 | 2 | 1467708190.44 | Triggered by <mysql.fabric.events.Event object at 0x239f350>. | | 4 | 2 | 1467708190.47 | Executing action (_report_failure). | | 5 | 2 | 1467708190.5 | Executed action (_report_failure). | | 3 | 2 | 1467708190.48 | Triggered by <mysql.fabric.events.Event object at 0x22777d0>. | | 4 | 2 | 1467708190.5 | Executing action (_find_candidate_fail). | | 5 | 2 | 1467708190.59 | Executed action (_find_candidate_fail). | | 3 | 2 | 1467708190.58 | Triggered by <mysql.fabric.events.Event object at 0x239f8d0>. | | 4 | 2 | 1467708190.59 | Executing action (_check_candidate_fail). | | 5 | 2 | 1467708190.65 | Executed action (_check_candidate_fail). | | 3 | 2 | 1467708190.64 | Triggered by <mysql.fabric.events.Event object at 0x239f950>. | | 4 | 2 | 1467708190.65 | Executing action (_wait_slave_fail). | | 5 | 2 | 1467708190.87 | Executed action (_wait_slave_fail). | | 3 | 2 | 1467708190.86 | Triggered by <mysql.fabric.events.Event object at 0x239fa90>. | | 4 | 2 | 1467708190.87 | Executing action (_change_to_candidate). | | 5 | 2 | 1467708191.02 | Executed action (_change_to_candidate). | +-------+---------+---------------+---------------------------------------------------------------+ 15 rows in set (0.58 sec)
0 件のコメント :
コメントを投稿