Skip to content

Commit 451ccd6

Browse files
yikekelilin90
authored andcommitted
tools: add jq usages for pd-ctl (#542)
* tools: add jq usages for pd-ctl Via: pingcap/docs-cn#790 * tools: address the comment Via: https://github.com/pingcap/docs-cn/pull/790/files
1 parent 580b747 commit 451ccd6

File tree

1 file changed

+93
-4
lines changed

1 file changed

+93
-4
lines changed

tools/pd-control.md

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ Usage:
367367
time: 43.12698ms
368368
```
369369
370-
### `region \<region_id\>`
370+
### `region \<region_id\> [--jq="<query string>"]`
371371
372-
Use this command to view the region information.
372+
Use this command to view the region information. For a jq formatted output, see [jq-formatted-json-output-usage](#jq-formatted-json-output-usage).
373373
374374
Usage:
375375
@@ -471,9 +471,9 @@ Usage:
471471
>> scheduler remove grant-leader-scheduler-1 // Remove the corresponding scheduler
472472
```
473473
474-
### `store [delete | label | weight] \<store_id\>`
474+
### `store [delete | label | weight] \<store_id\> [--jq="<query string>"]`
475475
476-
Use this command to view the store information or remove a specified store.
476+
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).
477477
478478
Usage:
479479
@@ -518,3 +518,92 @@ Usage:
518518
system: 2017-10-09 05:50:59 +0800 CST
519519
logic: 120102
520520
```
521+
522+
## Jq formatted JSON output usage
523+
524+
### Simplify the output of `store`
525+
526+
```bash
527+
» store --jq=".stores[].store | { id, address, state_name}"
528+
{"id":1,"address":"127.0.0.1:20161","state_name":"Up"}
529+
{"id":30,"address":"127.0.0.1:20162","state_name":"Up"}
530+
...
531+
```
532+
533+
### Query the remaining space of the node
534+
535+
```bash
536+
» store --jq=".stores[] | {id: .store.id, avaiable: .status.available}"
537+
{"id":1,"avaiable":"10 GiB"}
538+
{"id":30,"avaiable":"10 GiB"}
539+
...
540+
```
541+
542+
### Query the distribution status of the Region replicas
543+
544+
```bash
545+
» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id]}"
546+
{"id":2,"peer_stores":[1,30,31]}
547+
{"id":4,"peer_stores":[1,31,34]}
548+
...
549+
```
550+
551+
### Filter Regions according to the number of replicas
552+
553+
For example, to filter out all Regions whose number of replicas is not 3:
554+
555+
```bash
556+
» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length != 3)}"
557+
{"id":12,"peer_stores":[30,32]}
558+
{"id":2,"peer_stores":[1,30,31,32]}
559+
```
560+
561+
### Filter Regions according to the store ID of replicas
562+
563+
For example, to filter out all Regions that have a replica on store30:
564+
565+
```bash
566+
» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(any(.==30))}"
567+
{"id":6,"peer_stores":[1,30,31]}
568+
{"id":22,"peer_stores":[1,30,32]}
569+
...
570+
```
571+
572+
You can also find out all Regions that have a replica on store30 or store31 in the same way:
573+
574+
```bash
575+
» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(any(.==(30,31)))}"
576+
{"id":16,"peer_stores":[1,30,34]}
577+
{"id":28,"peer_stores":[1,30,32]}
578+
{"id":12,"peer_stores":[30,32]}
579+
...
580+
```
581+
582+
### Look for relevant Regions when restoring data
583+
584+
For example, when [store1, store30, store31] is unavailable at its downtime, you can find all Regions whose Down replicas are more than normal replicas:
585+
586+
```bash
587+
» 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) }"
588+
{"id":2,"peer_stores":[1,30,31,32]}
589+
{"id":12,"peer_stores":[30,32]}
590+
{"id":14,"peer_stores":[1,30,32]}
591+
...
592+
```
593+
594+
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:
595+
596+
```bash
597+
» region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length>1 and any(.==1) and all(.!=(30,31)))}"
598+
{"id":24,"peer_stores":[1,32,33]}
599+
```
600+
601+
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:
602+
603+
```bash
604+
» region --jq=".regions[] | {id: .id, remove_peer: [.peers[].store_id] | select(length>1) | map(if .==(30,31) then . else empty end) | select(length==1)}"
605+
{"id":12,"remove_peer":[30]}
606+
{"id":4,"remove_peer":[31]}
607+
{"id":22,"remove_peer":[30]}
608+
...
609+
```

0 commit comments

Comments
 (0)