From afa932cb2fc26655c5250bad54159910f682ed0a Mon Sep 17 00:00:00 2001 From: yikeke Date: Tue, 17 Jul 2018 11:09:01 +0800 Subject: [PATCH 1/2] tools: add jq usages for pd-ctl Via: https://github.com/pingcap/docs-cn/pull/790 --- tools/pd-control.md | 99 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 5 deletions(-) diff --git a/tools/pd-control.md b/tools/pd-control.md index a3f60b0ffbd24..55c74294900ff 100644 --- a/tools/pd-control.md +++ b/tools/pd-control.md @@ -264,9 +264,9 @@ Usage: time: 43.12698ms ``` -### `region \` +### `region \ [--jq=""]` -Use this command to view the region information. +Use this command to view the region information. For a jq formatted output, see [jq-formatted-json-output-usage] (#jq-formatted-json-output-usage). Usage: @@ -332,9 +332,9 @@ Usage: >> scheduler remove grant-leader-scheduler-1 // Remove the corresponding scheduler ``` -### `store [delete | label | weight] \` +### `store [delete | label | weight] \ [--jq=""]` -Use this command to view the store information or remove a specified store. +Use this command to view the store information or remove a specified store. For a jq formatted output, see [jq-formatted-json-output-usage] (#jq-formatted-json-output-usage). Usage: @@ -378,4 +378,93 @@ Usage: >> tso 395181938313123110 // Parse TSO system: 2017-10-09 05:50:59 +0800 CST logic: 120102 -``` \ No newline at end of file +``` + +## Jq formatted json output usage + +### Simplify the output of `store` + +```bash +» store --jq=".stores[].store | { id, address, state_name}" +{"id":1,"address":"127.0.0.1:20161","state_name":"Up"} +{"id":30,"address":"127.0.0.1:20162","state_name":"Up"} +... +``` + +### Query the remaining space of the node + +```bash +» store --jq=".stores[] | {id: .store.id, avaiable: .status.available}" +{"id":1,"avaiable":"10 GiB"} +{"id":30,"avaiable":"10 GiB"} +... +``` + +### Query the distribution status of the Region copies + +```bash +» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id]}" +{"id":2,"peer_stores":[1,30,31]} +{"id":4,"peer_stores":[1,31,34]} +... +``` + +### Filter Regions according to the number of copies + +For example, to filter out all Regions whose number of copies is not 3: + +```bash +» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length != 3)}" +{"id":12,"peer_stores":[30,32]} +{"id":2,"peer_stores":[1,30,31,32]} +``` + +### Filter Regions according to the store ID of copies + +For example,to filter out all Regions that have a replica on store30: + +```bash +» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(any(.==30))}" +{"id":6,"peer_stores":[1,30,31]} +{"id":22,"peer_stores":[1,30,32]} +... +``` + +You can also find out all Regions that have a replica on store30 or store31 in the same way: + +```bash +» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(any(.==(30,31)))}" +{"id":16,"peer_stores":[1,30,34]} +{"id":28,"peer_stores":[1,30,32]} +{"id":12,"peer_stores":[30,32]} +... +``` + +### Look for relevant Regions when restoring data + +For example, when [store1, store30, store31] is unavailable at its downtime, you can find all Regions whose Down copies are more than normal copies: + +```bash +» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length as $total | map(if .==(1,30,31) then . else empty end) | length>=$total-length) }" +{"id":2,"peer_stores":[1,30,31,32]} +{"id":12,"peer_stores":[30,32]} +{"id":14,"peer_stores":[1,30,32]} +... +``` + +Or when [store1, store30, store31] fails to start, you can find Regions that can manually remove data without risks on store1. In this way, you can filter out all Regions that have a replica on store1 but don't have other DownPeers: + +```bash +» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length>1 and any(.==1) and all(.!=(30,31)))}" +{"id":24,"peer_stores":[1,32,33]} +``` + +When [store30, store31] is down, find out all Regions that can be safely processed by creating the `remove-peer` Operator, that is, Regions with one and only DownPeer: + +```bash +» region --jq=".regions[] | {id: .id, remove_peer: [.peers[].store_id] | select(length>1) | map(if .==(30,31) then . else empty end) | select(length==1)}" +{"id":12,"remove_peer":[30]} +{"id":4,"remove_peer":[31]} +{"id":22,"remove_peer":[30]} +... +``` From 48042685ce47a790cf1d036720a1f1b8cd3e003f Mon Sep 17 00:00:00 2001 From: yikeke Date: Wed, 18 Jul 2018 11:53:43 +0800 Subject: [PATCH 2/2] tools: address the comment Via: https://github.com/pingcap/docs-cn/pull/790/files --- tools/pd-control.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/pd-control.md b/tools/pd-control.md index 86eaaa73fd8da..78a5aceebc7fa 100644 --- a/tools/pd-control.md +++ b/tools/pd-control.md @@ -369,7 +369,7 @@ time: 43.12698ms ### `region \ [--jq=""]` -Use this command to view the region information. For a jq formatted output, see [jq-formatted-json-output-usage] (#jq-formatted-json-output-usage). +Use this command to view the region information. For a jq formatted output, see [jq-formatted-json-output-usage](#jq-formatted-json-output-usage). Usage: @@ -473,7 +473,7 @@ Usage: ### `store [delete | label | weight] \ [--jq=""]` -Use this command to view the store information or remove a specified store. For a jq formatted output, see [jq-formatted-json-output-usage] (#jq-formatted-json-output-usage). +Use this command to view the store information or remove a specified store. For a jq formatted output, see [jq-formatted-json-output-usage](#jq-formatted-json-output-usage). Usage: @@ -519,7 +519,7 @@ system: 2017-10-09 05:50:59 +0800 CST logic: 120102 ``` -## Jq formatted json output usage +## Jq formatted JSON output usage ### Simplify the output of `store` @@ -539,7 +539,7 @@ logic: 120102 ... ``` -### Query the distribution status of the Region copies +### Query the distribution status of the Region replicas ```bash » region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id]}" @@ -548,9 +548,9 @@ logic: 120102 ... ``` -### Filter Regions according to the number of copies +### Filter Regions according to the number of replicas -For example, to filter out all Regions whose number of copies is not 3: +For example, to filter out all Regions whose number of replicas is not 3: ```bash » region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length != 3)}" @@ -558,9 +558,9 @@ For example, to filter out all Regions whose number of copies is not 3: {"id":2,"peer_stores":[1,30,31,32]} ``` -### Filter Regions according to the store ID of copies +### Filter Regions according to the store ID of replicas -For example,to filter out all Regions that have a replica on store30: +For example, to filter out all Regions that have a replica on store30: ```bash » region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(any(.==30))}" @@ -581,7 +581,7 @@ You can also find out all Regions that have a replica on store30 or store31 in t ### Look for relevant Regions when restoring data -For example, when [store1, store30, store31] is unavailable at its downtime, you can find all Regions whose Down copies are more than normal copies: +For example, when [store1, store30, store31] is unavailable at its downtime, you can find all Regions whose Down replicas are more than normal replicas: ```bash » region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length as $total | map(if .==(1,30,31) then . else empty end) | length>=$total-length) }" @@ -591,7 +591,7 @@ For example, when [store1, store30, store31] is unavailable at its downtime, you ... ``` -Or when [store1, store30, store31] fails to start, you can find Regions that can manually remove data without risks on store1. In this way, you can filter out all Regions that have a replica on store1 but don't have other DownPeers: +Or when [store1, store30, store31] fails to start, you can find Regions where the data can be manually removed safely on store1. In this way, you can filter out all Regions that have a replica on store1 but don't have other DownPeers: ```bash » region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length>1 and any(.==1) and all(.!=(30,31)))}"