OpenAPIを使用してDMクラスターを管理する

DMは、DMクラスタを簡単に照会および操作するためのOpenAPI機能を提供します。これは、 dmctlツールの機能と同様です。この機能を有効にする必要がある場合は、DMマスター構成ファイルに次の構成を追加します。

openapi = true

ノート:

  • DMは、OpenAPI3.0.0標準を満たす仕様書を提供します。このドキュメントには、すべてのリクエストパラメータと戻り値が含まれています。ドキュメントyamlをコピーして、 Swaggerエディターでプレビューできます。

  • DMマスターノードを展開した後、 http://{master-addr}/api/v1/docsにアクセスしてドキュメントをオンラインでプレビューできます。

APIを使用して、DMクラスタで次のメンテナンス操作を実行できます。

クラスターを管理するためのAPI

データソースを管理するためのAPI

レプリケーションタスクを管理するためのAPI

次のセクションでは、APIの具体的な使用法について説明します。

APIエラーメッセージテンプレート

APIリクエストを送信した後、エラーが発生した場合、返されるエラーメッセージは次の形式になります。

{ "error_msg": "", "error_code": "" }

上記のJSON出力から、 error_msgはエラーメッセージを示し、 error_codeは対応するエラーコードです。

DMマスターノードの情報を取得する

このAPIは同期インターフェースです。リクエストが成功すると、対応するノードの情報が返されます。

URIをリクエストする

GET /api/v1/cluster/masters

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/cluster/masters' \ -H 'accept: application/json'
{ "total": 1, "data": [ { "name": "master1", "alive": true, "leader": true, "addr": "127.0.0.1:8261" } ] }

DMマスターノードを停止します

このAPIは同期インターフェースです。リクエストが成功した場合、返される本文のステータスコードは204です。

URIをリクエストする

DELETE /api/v1/cluster/masters/{master-name}

curl -X 'DELETE' \ 'http://127.0.0.1:8261/api/v1/cluster/masters/master1' \ -H 'accept: */*'

DMワーカーノードの情報を取得します

このAPIは同期インターフェースです。リクエストが成功すると、対応するノードの情報が返されます。

URIをリクエストする

GET /api/v1/cluster/workers

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/cluster/workers' \ -H 'accept: application/json'
{ "total": 1, "data": [ { "name": "worker1", "addr": "127.0.0.1:8261", "bound_stage": "bound", "bound_source_name": "mysql-01" } ] }

DMワーカーノードを停止します

このAPIは同期インターフェースです。リクエストが成功した場合、返される本文のステータスコードは204です。

URIをリクエストする

DELETE /api/v1/cluster/workers/{worker-name}

curl -X 'DELETE' \ 'http://127.0.0.1:8261/api/v1/cluster/workers/worker1' \ -H 'accept: */*'

データソースを作成する

このAPIは同期インターフェースです。リクエストが成功すると、対応するデータソースの情報が返されます。

URIをリクエストする

POST /api/v1/sources

curl -X 'POST' \ 'http://127.0.0.1:8261/api/v1/sources' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "source_name": "mysql-01", "host": "127.0.0.1", "port": 3306, "user": "root", "password": "123456", "enable_gtid": false, "security": { "ssl_ca_content": "", "ssl_cert_content": "", "ssl_key_content": "", "cert_allowed_cn": [ "string" ] }, "purge": { "interval": 3600, "expires": 0, "remain_space": 15 } }'
{ "source_name": "mysql-01", "host": "127.0.0.1", "port": 3306, "user": "root", "password": "123456", "enable_gtid": false, "security": { "ssl_ca_content": "", "ssl_cert_content": "", "ssl_key_content": "", "cert_allowed_cn": [ "string" ] }, "purge": { "interval": 3600, "expires": 0, "remain_space": 15 }, "status_list": [ { "source_name": "mysql-replica-01", "worker_name": "worker-1", "relay_status": { "master_binlog": "(mysql-bin.000001, 1979)", "master_binlog_gtid": "e9a1fc22-ec08-11e9-b2ac-0242ac110003:1-7849", "relay_dir": "./sub_dir", "relay_binlog_gtid": "e9a1fc22-ec08-11e9-b2ac-0242ac110003:1-7849", "relay_catch_up_master": true, "stage": "Running" }, "error_msg": "string" } ] }

データソースリストを取得する

このAPIは同期インターフェースです。リクエストが成功すると、データソースリストが返されます。

URIをリクエストする

GET /api/v1/sources

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/sources?with_status=true' \ -H 'accept: application/json'
{ "data": [ { "enable_gtid": false, "host": "127.0.0.1", "password": "******", "port": 3306, "purge": { "expires": 0, "interval": 3600, "remain_space": 15 }, "security": null, "source_name": "mysql-01", "user": "root" }, { "enable_gtid": false, "host": "127.0.0.1", "password": "******", "port": 3307, "purge": { "expires": 0, "interval": 3600, "remain_space": 15 }, "security": null, "source_name": "mysql-02", "user": "root" } ], "total": 2 }

データソースを削除する

このAPIは同期インターフェースです。リクエストが成功した場合、返される本文のステータスコードは204です。

URIをリクエストする

DELETE /api/v1/sources/{source-name}

curl -X 'DELETE' \ 'http://127.0.0.1:8261/api/v1/sources/mysql-01?force=true' \ -H 'accept: application/json'

データソースの情報を取得する

このAPIは同期インターフェースです。リクエストが成功すると、対応するノードの情報が返されます。

URIをリクエストする

GET /api/v1/sources/{source-name}/status

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/sources/mysql-replica-01/status' \ -H 'accept: application/json'
{ "total": 1, "data": [ { "source_name": "mysql-replica-01", "worker_name": "worker-1", "relay_status": { "master_binlog": "(mysql-bin.000001, 1979)", "master_binlog_gtid": "e9a1fc22-ec08-11e9-b2ac-0242ac110003:1-7849", "relay_dir": "./sub_dir", "relay_binlog_gtid": "e9a1fc22-ec08-11e9-b2ac-0242ac110003:1-7849", "relay_catch_up_master": true, "stage": "Running" }, "error_msg": "string" } ] }

データソースのリレーログ機能を開始します

このAPIは非同期インターフェースです。リクエストが成功した場合、返された本文のステータスコードは200です。最新のステータスを確認するには、 データソースの情報を取得するを実行できます。

URIをリクエストする

POST /api/v1/sources/{source-name}/start-relay

curl -X 'POST' \ 'http://127.0.0.1:8261/api/v1/sources/mysql-01/start-relay' \ -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '{ "worker_name_list": [ "worker-1" ], "relay_binlog_name": "mysql-bin.000002", "relay_binlog_gtid": "e9a1fc22-ec08-11e9-b2ac-0242ac110003:1-7849", "relay_dir": "./relay_log" }'

データソースのリレーログ機能を停止します

このAPIは非同期インターフェースです。リクエストが成功した場合、返された本文のステータスコードは200です。最新のステータスを確認するには、 データソースの情報を取得するを実行できます。

URIをリクエストする

POST /api/v1/sources/{source-name}/stop-relay

curl -X 'POST' \ 'http://127.0.0.1:8261/api/v1/sources/mysql-01/stop-relay' \ -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '{ "worker_name_list": [ "worker-1" ] }'

データソースのリレーログ機能を一時停止します

このAPIは非同期インターフェースです。リクエストが成功した場合、返された本文のステータスコードは200です。最新のステータスを確認するには、 データソースの情報を取得するを実行できます。

URIをリクエストする

POST /api/v1/sources/{source-name}/pause-relay

curl -X 'POST' \ 'http://127.0.0.1:8261/api/v1/sources/mysql-01/pause-relay' \ -H 'accept: */*'

データソースのリレーログ機能を再開します

このAPIは非同期インターフェースです。リクエストが成功した場合、返された本文のステータスコードは200です。最新のステータスを確認するには、 データソースの情報を取得するを実行できます。

URIをリクエストする

POST /api/v1/sources/{source-name}/resume-relay

curl -X 'POST' \ 'http://127.0.0.1:8261/api/v1/sources/mysql-01/resume-relay' \ -H 'accept: */*'

データソースとDMワーカー間のバインディングを変更します

このAPIは非同期インターフェースです。リクエストが成功した場合、返された本文のステータスコードは200です。最新のステータスを確認するには、 DMワーカーノードの情報を取得するを実行できます。

URIをリクエストする

POST /api/v1/sources/{source-name}/transfer

curl -X 'POST' \ 'http://127.0.0.1:8261/api/v1/sources/mysql-01/transfer' \ -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '{ "worker_name": "worker-1" }'

データソースのスキーマ名のリストを取得する

このAPIは同期インターフェースです。リクエストが成功すると、対応するリストが返されます。

URIをリクエストする

GET /api/v1/sources/{source-name}/schemas

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/sources/source-1/schemas' \ -H 'accept: application/json'
[ "db1" ]

データソース内の指定されたスキーマのテーブル名のリストを取得します

このAPIは同期インターフェースです。リクエストが成功すると、対応するリストが返されます。

URIをリクエストする

GET /api/v1/sources/{source-name}/schemas/{schema-name}

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/sources/source-1/schemas/db1' \ -H 'accept: application/json'
[ "table1" ]

レプリケーションタスクを作成する

このAPIは非同期インターフェースです。リクエストが成功した場合、返された本文のステータスコードは200です。最新のステータスを確認するには、 レプリケーションタスクの情報を取得するを実行できます。

URIをリクエストする

POST /api/v1/tasks

curl -X 'POST' \ 'http://127.0.0.1:8261/api/v1/tasks' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "remove_meta": false, "task": { "name": "task-1", "task_mode": "all", "shard_mode": "pessimistic", "meta_schema": "dm-meta", "enhance_online_schema_change": true, "on_duplicate": "overwrite", "target_config": { "host": "127.0.0.1", "port": 3306, "user": "root", "password": "123456", "security": { "ssl_ca_content": "", "ssl_cert_content": "", "ssl_key_content": "", "cert_allowed_cn": [ "string" ] } }, "binlog_filter_rule": { "rule-1": { "ignore_event": [ "all dml" ], "ignore_sql": [ "^Drop" ] }, "rule-2": { "ignore_event": [ "all dml" ], "ignore_sql": [ "^Drop" ] }, "rule-3": { "ignore_event": [ "all dml" ], "ignore_sql": [ "^Drop" ] } }, "table_migrate_rule": [ { "source": { "source_name": "source-name", "schema": "db-*", "table": "tb-*" }, "target": { "schema": "db1", "table": "tb1" }, "binlog_filter_rule": [ "rule-1", "rule-2", "rule-3", ] } ], "source_config": { "full_migrate_conf": { "export_threads": 4, "import_threads": 16, "data_dir": "./exported_data", "consistency": "auto" }, "incr_migrate_conf": { "repl_threads": 16, "repl_batch": 100 }, "source_conf": [ { "source_name": "mysql-replica-01", "binlog_name": "binlog.000001", "binlog_pos": 4, "binlog_gtid": "03fc0263-28c7-11e7-a653-6c0b84d59f30:1-7041423,05474d3c-28c7-11e7-8352-203db246dd3d:1-170" } ] } }, "source_name_list": [ "source-1" ] }'
{ "name": "task-1", "task_mode": "all", "shard_mode": "pessimistic", "meta_schema": "dm-meta", "enhance_online_schema_change": true, "on_duplicate": "overwrite", "target_config": { "host": "127.0.0.1", "port": 3306, "user": "root", "password": "123456", "security": { "ssl_ca_content": "", "ssl_cert_content": "", "ssl_key_content": "", "cert_allowed_cn": [ "string" ] } }, "binlog_filter_rule": { "rule-1": { "ignore_event": [ "all dml" ], "ignore_sql": [ "^Drop" ] }, "rule-2": { "ignore_event": [ "all dml" ], "ignore_sql": [ "^Drop" ] }, "rule-3": { "ignore_event": [ "all dml" ], "ignore_sql": [ "^Drop" ] } }, "table_migrate_rule": [ { "source": { "source_name": "source-name", "schema": "db-*", "table": "tb-*" }, "target": { "schema": "db1", "table": "tb1" }, "binlog_filter_rule": [ "rule-1", "rule-2", "rule-3", ] } ], "source_config": { "full_migrate_conf": { "export_threads": 4, "import_threads": 16, "data_dir": "./exported_data", "consistency": "auto" }, "incr_migrate_conf": { "repl_threads": 16, "repl_batch": 100 }, "source_conf": [ { "source_name": "mysql-replica-01", "binlog_name": "binlog.000001", "binlog_pos": 4, "binlog_gtid": "03fc0263-28c7-11e7-a653-6c0b84d59f30:1-7041423,05474d3c-28c7-11e7-8352-203db246dd3d:1-170" } ] } }

レプリケーションタスクリストを取得する

このAPIは同期インターフェースです。要求が成功すると、対応するレプリケーションタスクの情報が返されます。

URIをリクエストする

GET /api/v1/tasks

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/tasks' \ -H 'accept: application/json'
{ "total": 2, "data": [ { "name": "task-1", "task_mode": "all", "shard_mode": "pessimistic", "meta_schema": "dm-meta", "enhance_online_schema_change": true, "on_duplicate": "overwrite", "target_config": { "host": "127.0.0.1", "port": 3306, "user": "root", "password": "123456", "security": { "ssl_ca_content": "", "ssl_cert_content": "", "ssl_key_content": "", "cert_allowed_cn": [ "string" ] } }, "binlog_filter_rule": { "rule-1": { "ignore_event": [ "all dml" ], "ignore_sql": [ "^Drop" ] }, "rule-2": { "ignore_event": [ "all dml" ], "ignore_sql": [ "^Drop" ] }, "rule-3": { "ignore_event": [ "all dml" ], "ignore_sql": [ "^Drop" ] } }, "table_migrate_rule": [ { "source": { "source_name": "source-name", "schema": "db-*", "table": "tb-*" }, "target": { "schema": "db1", "table": "tb1" }, "binlog_filter_rule": [ "rule-1", "rule-2", "rule-3", ] } ], "source_config": { "full_migrate_conf": { "export_threads": 4, "import_threads": 16, "data_dir": "./exported_data", "consistency": "auto" }, "incr_migrate_conf": { "repl_threads": 16, "repl_batch": 100 }, "source_conf": [ { "source_name": "mysql-replica-01", "binlog_name": "binlog.000001", "binlog_pos": 4, "binlog_gtid": "03fc0263-28c7-11e7-a653-6c0b84d59f30:1-7041423,05474d3c-28c7-11e7-8352-203db246dd3d:1-170" } ] } } ] }

レプリケーションタスクを停止します

このAPIは非同期インターフェースです。リクエストが成功した場合、返された本文のステータスコードは204です。最新のステータスについて知るには、 レプリケーションタスクの情報を取得するを実行できます。

URIをリクエストする

DELETE /api/v1/tasks/{task-name}

curl -X 'DELETE' \ 'http://127.0.0.1:8261/api/v1/tasks/task-1' \ -H 'accept: */*'

レプリケーションタスクの情報を取得します

このAPIは同期インターフェースです。リクエストが成功すると、対応するノードの情報が返されます。

URIをリクエストする

GET /api/v1/tasks/task-1/status

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/tasks/task-1/status?stage=running' \ -H 'accept: application/json'
{ "total": 1, "data": [ { "name": "string", "source_name": "string", "worker_name": "string", "stage": "runing", "unit": "sync", "unresolved_ddl_lock_id": "string", "load_status": { "finished_bytes": 0, "total_bytes": 0, "progress": "string", "meta_binlog": "string", "meta_binlog_gtid": "string" }, "sync_status": { "total_events": 0, "total_tps": 0, "recent_tps": 0, "master_binlog": "string", "master_binlog_gtid": "string", "syncer_binlog": "string", "syncer_binlog_gtid": "string", "blocking_ddls": [ "string" ], "unresolved_groups": [ { "target": "string", "ddl_list": [ "string" ], "first_location": "string", "synced": [ "string" ], "unsynced": [ "string" ] } ], "synced": true, "binlog_type": "string", "seconds_behind_master": 0 } } ] }

レプリケーションタスクを一時停止します

このAPIは非同期インターフェースです。リクエストが成功した場合、返された本文のステータスコードは200です。最新のステータスを確認するには、 レプリケーションタスクの情報を取得するを実行できます。

URIをリクエストする

POST /api/v1/tasks/task-1/pause

curl -X 'POST' \ 'http://127.0.0.1:8261/api/v1/tasks/task-1/pause' \ -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '[ "source-1" ]'

レプリケーションタスクを再開します

このAPIは非同期インターフェースです。リクエストが成功した場合、返された本文のステータスコードは200です。最新のステータスを確認するには、 レプリケーションタスクの情報を取得するを実行できます。

URIをリクエストする

POST /api/v1/tasks/task-1/resume

curl -X 'POST' \ 'http://127.0.0.1:8261/api/v1/tasks/task-1/resume' \ -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '[ "source-1" ]'

レプリケーションタスクに関連付けられているデータソースのスキーマ名のリストを取得します

このAPIは同期インターフェースです。リクエストが成功すると、対応するリストが返されます。

URIをリクエストする

GET /api/v1/tasks/{task-name}/sources/{source-name}/schemas

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/tasks/task-1/sources/source-1/schemas' \ -H 'accept: application/json'
[ "db1" ]

レプリケーションタスクに関連付けられているデータソース内の指定されたスキーマのテーブル名のリストを取得します

このAPIは同期インターフェースです。リクエストが成功すると、対応するリストが返されます。

URIをリクエストする

GET /api/v1/tasks/{task-name}/sources/{source-name}/schemas/{schema-name}

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/tasks/task-1/sources/source-1/schemas/db1' \ -H 'accept: application/json'
[ "table1" ]

レプリケーションタスクに関連付けられているデータソースのスキーマのCREATEステートメントを取得します

このAPIは同期インターフェースです。リクエストが成功すると、対応するCREATEステートメントが返されます。

URIをリクエストする

GET /api/v1/tasks/{task-name}/sources/{source-name}/schemas/{schema-name}/{table-name}

curl -X 'GET' \ 'http://127.0.0.1:8261/api/v1/tasks/task-1/sources/source-1/schemas/db1/table1' \ -H 'accept: application/json'
{ "schema_name": "db1", "table_name": "table1", "schema_create_sql": "CREATE TABLE `t1` (`id` int(11) NOT NULL AUTO_INCREMENT,PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" }

レプリケーションタスクに関連付けられているデータソースのスキーマのCREATEステートメントを更新します

このAPIは同期インターフェースです。リクエストが成功した場合、返される本文のステータスコードは200です。

URIをリクエストする

POST /api/v1/tasks/{task-name}/sources/{source-name}/schemas/{schema-name}/{table-name}

curl -X 'PUT' \ 'http://127.0.0.1:8261/api/v1/tasks/task-1/sources/task-1/schemas/db1/table1' \ -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '{ "sql_content": "CREATE TABLE `t1` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL, `c3` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;", "flush": true, "sync": true }'

レプリケーションタスクに関連付けられているデータソースのスキーマを削除します

このAPIは同期インターフェースです。リクエストが成功した場合、返される本文のステータスコードは200です。

URIをリクエストする

DELETE /api/v1/tasks/{task-name}/sources/{source-name}/schemas/{schema-name}/{table-name}

curl -X 'DELETE' \ 'http://127.0.0.1:8261/api/v1/tasks/task-1/sources/source-1/schemas/db1/table1' \ -H 'accept: */*'

このページは役に立ちましたか?

Playground
新規
登録なしで TiDB の機能をワンストップでインタラクティブに体験できます。
製品
TiDB Cloud
TiDB
価格
PoC お問い合わせ
エコシステム
TiKV
TiFlash
OSS Insight
© 2024 PingCAP. All Rights Reserved.
Privacy Policy.