-
Notifications
You must be signed in to change notification settings - Fork 691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools: add jq usages for pd-ctl #542
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,9 +264,9 @@ Usage: | |
time: 43.12698ms | ||
``` | ||
|
||
### `region \<region_id\>` | ||
### `region \<region_id\> [--jq="<query string>"]` | ||
|
||
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_id\>` | ||
### `store [delete | label | weight] \<store_id\> [--jq="<query string>"]` | ||
|
||
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). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the link format. |
||
|
||
Usage: | ||
|
||
|
@@ -378,4 +378,93 @@ Usage: | |
>> tso 395181938313123110 // Parse TSO | ||
system: 2017-10-09 05:50:59 +0800 CST | ||
logic: 120102 | ||
``` | ||
``` | ||
|
||
## Jq formatted json output usage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. json -> JSON |
||
|
||
### 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copies -> replicas In TiDB, replica is a concept that means 副本. Ref: https://pingcap.com/blog/2017-09-15-rocksdbintikv/#region |
||
|
||
```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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
|
||
For example, to filter out all Regions whose number of copies is not 3: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
|
||
```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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
|
||
For example,to filter out all Regions that have a replica on store30: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave a whitespace before "to". |
||
|
||
```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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
|
||
```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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the first sentence to: Or when [store1, store30, store31] fails to start, you can find the Region where the data can be manually removed safely. |
||
|
||
```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]} | ||
... | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete the extra whitespace between ] and (.
The link format is: []()