As a command line tool of PD, PD Control obtains the state information of the cluster and tunes the cluster.

Source code compiling

  • Go Version 1.11 or later
  • In the root directory of the PD project, use the make command to compile and generate bin/pd-ctl

Note: Generally, you do not need to compile source code because the PD Control tool already exists in the released Binary or Docker. For developer users, the make command can be used to compile source code.

Usage

Single-command mode:

  1. ./pd-ctl store -u http://127.0.0.1:2379

Interactive mode:

  1. ./pd-ctl -u http://127.0.0.1:2379

Use environment variables:

  1. export PD_ADDR=http://127.0.0.1:2379
  2. ./pd-ctl

Use TLS to encrypt:

  1. ./pd-ctl -u https://127.0.0.1:2379 --cacert="path/to/ca" --cert="path/to/cert" --key="path/to/key"

Command line flags

—pd,-u

—detach,-d

  • Use single command line mode (not entering readline)
  • Default: true

–cacert

  • Specify the path to the certificate file of the trusted CA in PEM format
  • Default: "”

–cert

  • Specify the path to the certificate of SSL in PEM format
  • Default: "”

–key

  • Specify the path to the certificate key file of SSL in PEM format, which is the private key of the certificate specified by —cert
  • Default: "”

–version,-V

  • Print the version information and exit
  • Default: false

Command

cluster

Use this command to view the basic information of the cluster.

Usage:

  1. >> cluster // To show the cluster information
  2. {
  3. "id": 6493707687106161130,
  4. "max_peer_count": 3
  5. }

config [show | set <option> <value>]

Use this command to view or modify the configuration information.

Usage:

  1. >> ./bin/pd-ctl config show all // Display all config information of the scheduler
  2. {
  3. "client-urls": "http://127.0.0.1:2379",
  4. "peer-urls": "http://127.0.0.1:2380",
  5. "advertise-client-urls": "http://127.0.0.1:2379",
  6. "advertise-peer-urls": "http://127.0.0.1:2380",
  7. "name": "pd-chenshunings-MacBook-Pro.local",
  8. "data-dir": "default.pd-chenshunings-MacBook-Pro.local",
  9. "force-new-cluster": false,
  10. "initial-cluster": "pd-chenshunings-MacBook-Pro.local=http://127.0.0.1:2380",
  11. "initial-cluster-state": "new",
  12. "join": "",
  13. "lease": 3,
  14. "log": {
  15. "level": "",
  16. "format": "text",
  17. "disable-timestamp": false,
  18. "file": {
  19. "filename": "",
  20. "log-rotate": true,
  21. "max-size": 0,
  22. "max-days": 0,
  23. "max-backups": 0
  24. },
  25. "development": false,
  26. "disable-caller": false,
  27. "disable-stacktrace": false,
  28. "sampling": null
  29. },
  30. "log-file": "",
  31. "log-level": "",
  32. "tso-save-interval": "3s",
  33. "metric": {
  34. "job": "pd-chenshunings-MacBook-Pro.local",
  35. "address": "",
  36. "interval": "15s"
  37. },
  38. "schedule": {
  39. "max-snapshot-count": 3,
  40. "max-pending-peer-count": 16,
  41. "max-merge-region-size": 20,
  42. "max-merge-region-keys": 200000,
  43. "split-merge-interval": "1h0m0s",
  44. "enable-one-way-merge": false,
  45. "patrol-region-interval": "100ms",
  46. "max-store-down-time": "30m0s",
  47. "leader-schedule-limit": 8,
  48. "region-schedule-limit": 1024,
  49. "replica-schedule-limit": 1024,
  50. "merge-schedule-limit": 8,
  51. "hot-region-schedule-limit": 2,
  52. "hot-region-cache-hits-threshold": 3,
  53. "store-balance-rate": 1,
  54. "tolerant-size-ratio": 0,
  55. "low-space-ratio": 0.8,
  56. "high-space-ratio": 0.6,
  57. "disable-raft-learner": "false",
  58. "disable-remove-down-replica": "false",
  59. "disable-replace-offline-replica": "false",
  60. "disable-make-up-replica": "false",
  61. "disable-remove-extra-replica": "false",
  62. "disable-location-replacement": "false",
  63. "disable-namespace-relocation": "false",
  64. "schedulers-v2": [
  65. {
  66. "type": "balance-region",
  67. "args": null,
  68. "disable": false
  69. },
  70. {
  71. "type": "balance-leader",
  72. "args": null,
  73. "disable": false
  74. },
  75. {
  76. "type": "hot-region",
  77. "args": null,
  78. "disable": false
  79. },
  80. {
  81. "type": "label",
  82. "args": null,
  83. "disable": false
  84. }
  85. ]
  86. },
  87. "replication": {
  88. "max-replicas": 3,
  89. "location-labels": "",
  90. "strictly-match-label": "false"
  91. },
  92. "namespace": {},
  93. "pd-server": {
  94. "use-region-storage": "true"
  95. },
  96. "cluster-version": "0.0.0",
  97. "quota-backend-bytes": "0 B",
  98. "auto-compaction-mode": "periodic",
  99. "auto-compaction-retention-v2": "1h",
  100. "TickInterval": "500ms",
  101. "ElectionInterval": "3s",
  102. "PreVote": true,
  103. "security": {
  104. "cacert-path": "",
  105. "cert-path": "",
  106. "key-path": ""
  107. },
  108. "label-property": {},
  109. "WarningMsgs": null,
  110. "namespace-classifier": "table",
  111. "LeaderPriorityCheckInterval": "1m0s"
  112. }
  113. >> config show // Display default config information
  114. >> config show namespace ts1 // Display the config information of the namespace named ts1
  115. {
  116. "leader-schedule-limit": 4,
  117. "region-schedule-limit": 4,
  118. "replica-schedule-limit": 8,
  119. "merge-schedule-limit": 8,
  120. "max-replicas": 3,
  121. }
  122. >> config show replication // Display the config information of replication
  123. {
  124. "max-replicas": 3,
  125. "location-labels": "zone,host"
  126. }
  127. >> config show cluster-version // Display the current version of the cluster, which is the current minimum version of TiKV nodes in the cluster and does not correspond to the binary version.
  128. "2.0.0"
  • max-snapshot-count controls the maximum number of snapshots that a single store receives or sends out at the same time. The scheduler is restricted by this configuration to avoid taking up normal application resources. When you need to improve the speed of adding replicas or balancing, increase this value.
  1. >> config set max-snapshot-count 16 // Set the maximum number of snapshots to 16
  • max-pending-peer-count controls the maximum number of pending peers in a single store. The scheduler is restricted by this configuration to avoid producing a large number of Regions without the latest log in some nodes. When you need to improve the speed of adding replicas or balancing, increase this value. Setting it to 0 indicates no limit.
  1. >> config set max-pending-peer-count 64 // Set the maximum number of pending peers to 64
  • max-merge-region-size controls the upper limit on the size of Region Merge (the unit is M). When regionSize exceeds the specified value, PD does not merge it with the adjacent Region. Setting it to 0 indicates disabling Region Merge. The default value is 20.
  1. >> config set max-merge-region-size 16 // Set the upper limit on the size of Region Merge to 16M
  • max-merge-region-keys controls the upper limit on the key count of Region Merge. When regionKeyCount exceeds the specified value, PD does not merge it with the adjacent Region. The default value is 200000.
  1. >> config set max-merge-region-keys 50000 // Set the the upper limit on KeyCount to 50000
  • split-merge-interval controls the interval between the split and merge operations on a same Region. This means:

    • Newly split Regions won't be merged within the specified period of time.

    • Region Merge won't happen within the specified period of time after PD starts or restarts.

The default value is 1h.

  1. >> config set split-merge-interval 24h // Set the interval between `split` and `merge` to one day
  • patrol-region-interval controls the execution frequency that replicaChecker checks the health status of Regions. A shorter interval indicates a higher execution frequency. Generally, you do not need to adjust it.
  1. >> config set patrol-region-interval 10ms // Set the execution frequency of replicaChecker to 10ms
  • max-store-down-time controls the time that PD decides the disconnected store cannot be restored if exceeded. If PD does not receive heartbeats from a store within the specified period of time, PD adds replicas in other nodes.
  1. >> config set max-store-down-time 30m // Set the time within which PD receives no heartbeats and after which PD starts to add replicas to 30 minutes
  • leader-schedule-limit controls the number of tasks scheduling the leader at the same time. This value affects the speed of leader balance. A larger value means a higher speed and setting the value to 0 closes the scheduling. Usually the leader scheduling has a small load, and you can increase the value in need.
  1. >> config set leader-schedule-limit 4 // 4 tasks of leader scheduling at the same time at most
  • region-schedule-limit controls the number of tasks scheduling the Region at the same time. This value affects the speed of Region balance. A larger value means a higher speed and setting the value to 0 closes the scheduling. Usually the Region scheduling has a large load, so do not set a too large value.
  1. >> config set region-schedule-limit 2 // 2 tasks of Region scheduling at the same time at most
  • replica-schedule-limit controls the number of tasks scheduling the replica at the same time. This value affects the scheduling speed when the node is down or removed. A larger value means a higher speed and setting the value to 0 closes the scheduling. Usually the replica scheduling has a large load, so do not set a too large value.
  1. >> config set replica-schedule-limit 4 // 4 tasks of replica scheduling at the same time at most
  • merge-schedule-limit controls the number of Region Merge scheduling tasks. Setting the value to 0 closes Region Merge. Usually the Merge scheduling has a large load, so do not set a too large value. The default value is 8.
  1. >> config set merge-schedule-limit 16 // 16 tasks of Merge scheduling at the same time at most

The configuration above is global. You can also tune the configuration by configuring different namespaces. The global configuration is used if the corresponding configuration of the namespace is not set.

Note: The configuration of the namespace only supports editing leader-schedule-limit, region-schedule-limit, replica-schedule-limit and max-replicas.

  1. ```bash
  2. >> config set namespace ts1 leader-schedule-limit 4 // 4 tasks of leader scheduling at the same time at most for the namespace named ts1
  3. >> config set namespace ts2 region-schedule-limit 2 // 2 tasks of region scheduling at the same time at most for the namespace named ts2
  4. ```
  • tolerant-size-ratio controls the size of the balance buffer area. When the score difference between the leader or Region of the two stores is less than specified multiple times of the Region size, it is considered in balance by PD.
  1. >> config set tolerant-size-ratio 20 // Set the size of the buffer area to about 20 times of the average regionSize
  • low-space-ratio controls the threshold value that is considered as insufficient store space. When the ratio of the space occupied by the node exceeds the specified value, PD tries to avoid migrating data to the corresponding node as much as possible. At the same time, PD mainly schedules the remaining space to avoid using up the disk space of the corresponding node.
  1. config set low-space-ratio 0.9 // Set the threshold value of insufficient space to 0.9
  • high-space-ratio controls the threshold value that is considered as sufficient store space. When the ratio of the space occupied by the node is less than the specified value, PD ignores the remaining space and mainly schedules the actual data volume.
  1. config set high-space-ratio 0.5 // Set the threshold value of sufficient space to 0.5
  • disable-raft-learner is used to disable Raft learner. By default, PD uses Raft learner when adding replicas to reduce the risk of unavailability due to downtime or network failure.
  1. config set disable-raft-learner true // Disable Raft learner
  • cluster-version is the version of the cluster, which is used to enable or disable some features and to deal with the compatibility issues. By default, it is the minimum version of all normally running TiKV nodes in the cluster. You can set it manually only when you need to roll it back to an earlier version.
  1. config set cluster-version 1.0.8 // Set the version of the cluster to 1.0.8
  • disable-remove-down-replica is used to disable the feature of automatically deleting DownReplica. When you set it to true, PD does not automatically clean up the downtime replicas.

  • disable-replace-offline-replica is used to disable the feature of migrating OfflineReplica. When you set it to true, PD does not migrate the offline replicas.

  • disable-make-up-replica is used to disable the feature of making up replicas. When you set it to true, PD does not adding replicas for Regions without sufficient replicas.

  • disable-remove-extra-replica is used to disable the feature of removing extra replicas. When you set it to true, PD does not remove extra replicas for Regions with redundant replicas.

  • disable-location-replacement is used to disable the isolation level check. When you set it to true, PD does not improve the isolation level of Region replicas by scheduling.

  • disable-namespace-relocation is used to disable Region relocation to the store of its namespace. When you set it to true, PD does not move Regions to stores where they belong to.

  • use-region-storage is used to enable or disable Region metadata storage in PD. When you set it to true, the metadata of PD Regions will be saved to the Region Meta-Storage, a separate storage engine. This solves the potential performance issue with BoltDB (backend of etcd) that may occur if the stored metadata has reached a GB level. Metadata is synchronized across multiple PD servers and eventually consistency is guaranteed through Raft. The default value is true.

Note:

This feature is introduced in TiKV 3.0.

config delete namespace <name> [<option>]

Use this command to delete the configuration of namespace.

Usage:

After you configure the namespace, if you want it to continue to use global configuration, delete the configuration information of the namespace using the following command:

  1. >> config delete namespace ts1 // Delete the configuration of the namespace named ts1

If you want to use global configuration only for a certain configuration of the namespace, use the following command:

  1. >> config delete namespace region-schedule-limit ts2 // Delete the region-schedule-limit configuration of the namespace named ts2

health

Use this command to view the health information of the cluster.

Usage:

  1. >> health // Display the health information
  2. [
  3. {
  4. "name": "pd",
  5. "member_id": 13195394291058371180,
  6. "client_urls": [
  7. "http://127.0.0.1:2379"
  8. ],
  9. "health": true
  10. },
  11. ...
  12. ]

hot [read | write | store]

Use this command to view the hot spot information of the cluster.

Usage:

  1. >> hot read // Display hot spot for the read operation
  2. >> hot write // Display hot spot for the write operation
  3. >> hot store // Display hot spot for all the read and write operations

label [store <name> <value>]

Use this command to view the label information of the cluster.

Usage:

  1. >> label // Display all labels
  2. >> label store zone cn // Display all stores including the "zone":"cn" label

member [delete | leader_priority | leader [show | resign | transfer <member_name>]]

Use this command to view the PD members, remove a specified member, or configure the priority of leader.

Usage:

  1. >> member // Display the information of all members
  2. {
  3. "header": {
  4. "cluster_id": 6493707687106161130
  5. },
  6. "members": [
  7. {
  8. "name": "pd1",
  9. "member_id": 9724873857558226554,
  10. "peer_urls": [
  11. "http://127.0.0.1:2380"
  12. ],
  13. "client_urls": [
  14. "http://127.0.0.1:2379"
  15. ]
  16. },
  17. ...
  18. ],
  19. "leader": {...},
  20. "etcd_leader": {...}
  21. }
  22. >> member delete name pd2 // Delete "pd2"
  23. Success!
  24. >> member delete id 1319539429105371180 // Delete a node using id
  25. Success!
  26. >> member leader show // Display the leader information
  27. {
  28. "name": "pd",
  29. "addr": "http://192.168.199.229:2379",
  30. "id": 9724873857558226554
  31. }
  32. >> member leader resign // Move leader away from the current member
  33. Success!
  34. >> member leader transfer pd3 // Migrate leader to a specified member
  35. Success!

operator [show | add | remove]

Use this command to view and control the scheduling operation, split a Region, or merge Regions.

Usage:

  1. >> operator show // Display all operators
  2. >> operator show admin // Display all admin operators
  3. >> operator show leader // Display all leader operators
  4. >> operator show region // Display all Region operators
  5. >> operator add add-peer 1 2 // Add a replica of Region 1 on store 2
  6. >> operator add remove-peer 1 2 // Remove a replica of Region 1 on store 2
  7. >> operator add transfer-leader 1 2 // Schedule the leader of Region 1 to store 2
  8. >> operator add transfer-region 1 2 3 4 // Schedule Region 1 to stores 2,3,4
  9. >> operator add transfer-peer 1 2 3 // Schedule the replica of Region 1 on store 2 to store 3
  10. >> operator add merge-region 1 2 // Merge Region 1 with Region 2
  11. >> operator add split-region 1 --policy=approximate // Split Region 1 into two Regions in halves, based on approximately estimated value
  12. >> operator add split-region 1 --policy=scan // Split Region 1 into two Regions in halves, based on accurate scan value
  13. >> operator remove 1 // Remove the scheduling operation of Region 1

The splitting of Regions starts from the position as close as possible to the middle. You can locate this position using two strategies, namely “scan” and “approximate”. The difference between them is that the former determines the middle key by scanning the Region, and the latter obtains the approximate position by checking the statistics recorded in the SST file. Generally, the former is more accurate, while the latter consumes less I/O and can be completed faster.

ping

Use this command to view the time that ping PD takes.

Usage:

  1. >> ping
  2. time: 43.12698ms

region <region_id> [—jq="<query string>"]

Use this command to view the region information. For a jq formatted output, see jq-formatted-json-output-usage.

Usage:

  1. >> region // Display the information of all regions
  2. {
  3. "count": 10,
  4. "regions": [
  5. {
  6. "id": 4,
  7. "start_key": "",
  8. "end_key": "t\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\xff\\x05\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xf8",
  9. "epoch": {...},
  10. "peers": [...],
  11. "leader": {...},
  12. "written_bytes": 251302,
  13. "read_bytes": 60472,
  14. "approximate_size": 1,
  15. "approximate_keys": 367
  16. },
  17. ...
  18. ]
  19. }
  20. >> region 2 // Display the information of the region with the id of 2
  21. {
  22. "id": 2,
  23. "start_key": "t\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\xff\\x1d\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xf8",
  24. "end_key": "",
  25. "epoch": {...},
  26. "peers": [...],
  27. "leader": {...},
  28. "written_bytes": 251302,
  29. "read_bytes": 60472,
  30. "approximate_size": 96,
  31. "approximate_keys": 524442
  32. }

region key [—format=raw|encode] <key>

Use this command to query the region that a specific key resides in. It supports the raw and encoding formats. And you need to use single quotes around the key when it is in the encoding format.

Raw format usage (default):

  1. >> region key abc
  2. >> region key xyz
  3. {
  4. "id": 2,
  5. "start_key": "t\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\xff\\x1d\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xf8",
  6. "end_key": "",
  7. "epoch": {...},
  8. "peers": [...],
  9. "leader": {...},
  10. "written_bytes": 251302,
  11. "read_bytes": 60472,
  12. "approximate_size": 96,
  13. "approximate_keys": 524442
  14. }

Encoding format usage:

  1. >> region key --format=encode 't\200\000\000\000\000\000\000\377\035_r\200\000\000\000\000\377\017U\320\000\000\000\000\000\372'
  2. {
  3. "region": {
  4. "id": 2,
  5. ...
  6. }
  7. }

region sibling <region_id>

Use this command to check the adjacent Regions of a specific Region.

Usage:

  1. >> region sibling 28
  2. [
  3. {
  4. "id": 26,
  5. "start_key": "t\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\xff\\x19\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xf8",
  6. "end_key": "t\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\xff\\x1b\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xf8",
  7. ...
  8. },
  9. {
  10. "id": 2,
  11. "start_key": "t\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\xff\\x1d\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xf8",
  12. "end_key": "",
  13. ...
  14. }
  15. ]

region store <store_id>

Use this command to list all Regions of a specific store.

Usage:

  1. >> region store 1
  2. {
  3. "count": 10,
  4. "regions": [
  5. {
  6. "id": 8,
  7. "start_key": "t\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\xff\\a\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xf8",
  8. ...
  9. },
  10. {
  11. ...
  12. },
  13. ...
  14. ]
  15. }

region topread [limit]

Use this command to list Regions with top read flow. The default value of the limit is 16.

Usage:

  1. >> region topread
  2. {
  3. "count": 16,
  4. "regions": [...]
  5. }

region topwrite [limit]

Use this command to list Regions with top write flow. The default value of the limit is 16.

Usage:

  1. >> region topwrite
  2. {
  3. "count": 16,
  4. "regions": [...]
  5. }

region topconfver [limit]

Use this command to list Regions with top conf version. The default value of the limit is 16.

Usage:

  1. >> region topconfver
  2. {
  3. "count": 16,
  4. "regions": [...]
  5. }

region topversion [limit]

Use this command to list Regions with top version. The default value of the limit is 16.

Usage:

  1. >> region topversion
  2. {
  3. "count": 16,
  4. "regions": [...]
  5. }

region topsize [limit]

Use this command to list Regions with top approximate size. The default value of the limit is 16.

Usage:

  1. >> region topsize
  2. {
  3. "count": 16,
  4. "regions": [...]
  5. }

region check [miss-peer | extra-peer | down-peer | pending-peer | incorrect-ns]

Use this command to check the Regions in abnormal conditions.

Description of various types:

  • miss-peer: the Region without enough replicas
  • extra-peer: the Region with extra replicas
  • down-peer: the Region in which some replicas are Down
  • pending-peer:the Region in which some replicas are Pending
  • incorrect-ns:the Region in which some replicas deviate from the namespace constraints

Usage:

  1. >> region check miss-peer
  2. {
  3. "count": 2,
  4. "regions": [...]
  5. }

scheduler [show | add | remove]

Use this command to view and control the scheduling strategy.

Usage:

  1. >> scheduler show // Display all schedulers
  2. >> scheduler add grant-leader-scheduler 1 // Schedule all the leaders of the regions on store 1 to store 1
  3. >> scheduler add evict-leader-scheduler 1 // Move all the region leaders on store 1 out
  4. >> scheduler add shuffle-leader-scheduler // Randomly exchange the leader on different stores
  5. >> scheduler add shuffle-region-scheduler // Randomly scheduling the regions on different stores
  6. >> scheduler remove grant-leader-scheduler-1 // Remove the corresponding scheduler

store [delete | label | weight] <store_id> [—jq="<query string>"]

Use this command to view the store information or remove a specified store. For a jq formatted output, see jq-formatted-json-output-usage.

Usage:

  1. >> store // Display information of all stores
  2. {
  3. "count": 3,
  4. "stores": [...]
  5. }
  6. >> store 1 // Get the store with the store id of 1
  7. {
  8. "store": {
  9. "id": 1,
  10. "address": "127.0.0.1:20160",
  11. "version": "2.1.0-rc.5",
  12. "state_name": "Up"
  13. },
  14. "status": {
  15. "capacity": "10 GiB",
  16. "available": "10 GiB",
  17. "leader_count": 14,
  18. "leader_weight": 1,
  19. "leader_score": 14,
  20. "leader_size": 14,
  21. "region_count": 14,
  22. "region_weight": 1,
  23. "region_score": 14,
  24. "region_size": 14,
  25. "start_ts": "2018-11-26T18:59:05+08:00",
  26. "last_heartbeat_ts": "2018-11-26T19:38:41.335120555+08:00",
  27. "uptime": "39m36.335120555s"
  28. }
  29. }
  30. >> store delete 1 // Delete the store with the store id of 1
  31. Success!
  32. >> store label 1 zone cn // Set the value of the label with the "zone" key to "cn" for the store with the store id of 1
  33. >> store weight 1 5 10 // Set the leader weight to 5 and region weight to 10 for the store with the store id of 1

store limit <store_id> <rate>

Use this command to modify the upper limit of scheduling rate for a specific store. The tasks include operations such as adding a peer or a learner.

Example:

  1. >> store limit 2 10 // Set the upper limit of scheduling speed for store 2 to be 10 scheduling tasks per minute.

stores show limit

Use this command to view the upper limit of the scheduling rate for all stores, in the unit of tasks per minute.

Example:

  1. » stores show limit // If store-balance-rate is set to 15, the corresponding rate for all stores should be 15.
  2. {
  3. "4": {
  4. "rate": 15
  5. },
  6. "5": {
  7. "rate": 15
  8. },
  9. ...
  10. }

stores set limit <rate>

Use this command to set the maximum number of scheduling tasks for all stores, in the unit of tasks per minute. The tasks include operations such as adding a peer or a learner.

Example:

  1. >> stores set limit 20 // Set the upper limit of scheduling speed for all stores to be 20 scheduling tasks per minute.

table_ns [create | add | remove | set_store | rm_store | set_meta | rm_meta]

Use this command to view the namespace information of the table.

Usage:

  1. >> table_ns add ts1 1 // Add the table with the table id of 1 to the namespace named ts1
  2. >> table_ns create ts1 // Add the namespace named ts1
  3. >> table_ns remove ts1 1 // Remove the table with the table id of 1 from the namespace named ts1
  4. >> table_ns rm_meta ts1 // Remove the metadata from the namespace named ts1
  5. >> table_ns rm_store 1 ts1 // Remove the table with the store id of 1 from the namespace named ts1
  6. >> table_ns set_meta ts1 // Add the metadata to namespace named ts1
  7. >> table_ns set_store 1 ts1 // Add the table with the store id of 1 to the namespace named ts1

tso

Use this command to parse the physical and logical time of TSO.

Usage:

  1. >> tso 395181938313123110 // Parse TSO
  2. system: 2017-10-09 05:50:59.507 +0800 CST
  3. logic: 120102

Jq formatted JSON output usage

Simplify the output of store

  1. » store --jq=".stores[].store | { id, address, state_name}"
  2. {"id":1,"address":"127.0.0.1:20161","state_name":"Up"}
  3. {"id":30,"address":"127.0.0.1:20162","state_name":"Up"}
  4. ...

Query the remaining space of the node

  1. » store --jq=".stores[] | {id: .store.id, available: .status.available}"
  2. {"id":1,"available":"10 GiB"}
  3. {"id":30,"available":"10 GiB"}
  4. ...

Query the distribution status of the Region replicas

  1. » region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id]}"
  2. {"id":2,"peer_stores":[1,30,31]}
  3. {"id":4,"peer_stores":[1,31,34]}
  4. ...

Filter Regions according to the number of replicas

For example, to filter out all Regions whose number of replicas is not 3:

  1. » region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length != 3)}"
  2. {"id":12,"peer_stores":[30,32]}
  3. {"id":2,"peer_stores":[1,30,31,32]}

Filter Regions according to the store ID of replicas

For example, to filter out all Regions that have a replica on store30:

  1. » region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(any(.==30))}"
  2. {"id":6,"peer_stores":[1,30,31]}
  3. {"id":22,"peer_stores":[1,30,32]}
  4. ...

You can also find out all Regions that have a replica on store30 or store31 in the same way:

  1. » region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(any(.==(30,31)))}"
  2. {"id":16,"peer_stores":[1,30,34]}
  3. {"id":28,"peer_stores":[1,30,32]}
  4. {"id":12,"peer_stores":[30,32]}
  5. ...

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 replicas are more than normal replicas:

  1. » 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) }"
  2. {"id":2,"peer_stores":[1,30,31,32]}
  3. {"id":12,"peer_stores":[30,32]}
  4. {"id":14,"peer_stores":[1,30,32]}
  5. ...

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:

  1. » region --jq=".regions[] | {id: .id, peer_stores: [.peers[].store_id] | select(length>1 and any(.==1) and all(.!=(30,31)))}"
  2. {"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:

  1. » region --jq=".regions[] | {id: .id, remove_peer: [.peers[].store_id] | select(length>1) | map(if .==(30,31) then . else empty end) | select(length==1)}"
  2. {"id":12,"remove_peer":[30]}
  3. {"id":4,"remove_peer":[31]}
  4. {"id":22,"remove_peer":[30]}
  5. ...