You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PD Recover is a disaster recovery tool of PD, used to recover the PD cluster which cannot start or provide services normally. PD Recover is downloaded with TiDB Ansible in the `resource/bin/pd-recover` path.
9
+
PD Recover is a disaster recovery tool of PD, used to recover the PD cluster which cannot start or provide services normally.
10
+
11
+
## Compile from source code
12
+
13
+
+[Go](https://golang.org/) Version 1.13 or later is required because the Go modules are used.
14
+
+ In the root directory of the [PD project](https://github.com/pingcap/pd), use the `make pd-recover` command to compile and generate `bin/pd-recover`.
15
+
16
+
> **Note:**
17
+
>
18
+
> Generally, you do not need to compile source code because the PD Control tool already exists in the released binary or Docker. However, developer users can refer to the instructions above for compiling source code.
19
+
20
+
## Download TiDB installation package
21
+
22
+
To download the latest version of PD Recover, directly download the TiDB package, because PD Recover is included in the TiDB package.
23
+
24
+
| Package name | OS | Architecture | SHA256 checksum |
25
+
|:---|:---|:---|:---|
26
+
|`https://download.pingcap.org/tidb-{version}-linux-amd64.tar.gz` (pd-recover) | Linux | amd64 |`https://download.pingcap.org/tidb-{version}-linux-amd64.sha256`|
27
+
28
+
> **Note:**
29
+
>
30
+
> `{version}` indicates the version number of TiDB. For example, if `{version}` is `v4.0.0`, the package download link is `https://download.pingcap.org/tidb-v4.0.0-linux-amd64.tar.gz`. You can also download the latest unpublished version by replacing `{version}` with `latest`.
10
31
11
32
## Quick Start
12
33
13
34
This section describes how to use PD Recover to recover a PD cluster.
14
35
15
36
### Get cluster ID
16
37
17
-
The cluster ID can be obtained from the log of PD, TiKV or TiDB. To get the cluster ID, you can either use the `ansible ad-hoc` command in the Control Machine, or view the log directly on the server.
38
+
The cluster ID can be obtained from the log of PD, TiKV or TiDB. To get the cluster ID, you can view the log directly on the server.
18
39
19
-
#### Get `[info] cluster ID` from PD log (recommended)
40
+
#### Get cluster ID from PD log (recommended)
20
41
21
-
To get the `[info] cluster id` from the PD log, run the following command:
42
+
To get the cluster ID from the PD log, run the following command:
22
43
23
44
{{< copyable "shell-regular" >}}
24
45
25
-
```
26
-
ansible -i inventory.ini pd_servers -m shell -a 'cat {{deploy_dir}}/log/pd.log | grep "init cluster id" | head -10'
2019/10/14 19:23:04.688 client.go:161: [info] [pd] init cluster id 6747551640615446306
48
-
……
67
+
...
49
68
```
50
69
51
-
#### Get `[info] PD cluster` from TiKV log
70
+
#### Get cluster ID from TiKV log
52
71
53
-
To get the `[info] PD cluster` from the TiKV log, run the following command:
72
+
To get the cluster ID from the TiKV log, run the following command:
54
73
55
74
{{< copyable "shell-regular" >}}
56
75
57
-
```
58
-
ansible -i inventory.ini tikv_servers -m shell -a 'cat {{deploy_dir}}/log/tikv* | grep "PD cluster" | head -10'
76
+
```bash
77
+
cat {{/path/to}}/tikv.log| grep "connect to PD cluster"
59
78
```
60
79
61
-
```
62
-
10.0.1.15 | CHANGED | rc=0 >>
80
+
```bash
63
81
[2019/10/14 07:06:35.278 +00:00] [INFO] [tikv-server.rs:464] ["connect to PD cluster 6747551640615446306"]
64
-
……
82
+
...
65
83
```
66
84
67
-
### Get `Alloc ID` (TiKV StoreID)
68
-
69
-
The `alloc-id` value you specify must be larger than the currently largest `Alloc ID` value. To get `Alloc ID`, you can either use the `ansible ad-hoc` command in the Control Machine, or view the log directly on the server.
70
-
71
-
#### Get `[info] allocates id` from PD log
72
-
73
-
To get the `[info] allocates id` from the PD log, run the following command:
85
+
### Get allocated ID
74
86
75
-
{{< copyable "shell-regular" >}}
87
+
The allocated ID value you specify must be larger than the currently largest allocated ID value. To get allocated ID, you can either get it from the monitor, or view the log directly on the server.
76
88
77
-
```
78
-
ansible -i inventory.ini pd_servers -m shell -a 'cat {{deploy_dir}}/log/pd* | grep "allocates" | head -10'
79
-
```
80
-
81
-
```
82
-
10.0.1.13 | CHANGED | rc=0 >>
83
-
[2019/10/15 03:15:05.824 +00:00] [INFO] [id.go:91] ["idAllocator allocates a new id"] [alloc-id=3000]
84
-
[2019/10/15 08:55:01.275 +00:00] [INFO] [id.go:91] ["idAllocator allocates a new id"] [alloc-id=4000]
85
-
……
86
-
```
89
+
#### Get allocated ID from the monitor (recommended)
87
90
88
-
#### Get `[info] alloc store id` from TiKV log
91
+
To get allocated ID from the monitor, you need to make sure that the metrics you are viewing are the metrics of **the last PD leader**, and you can get the largest allocated ID from the **Current ID allocation** panel in PD dashboard.
92
+
93
+
#### Get allocated ID from PD log
89
94
90
-
To get the `[info] alloc store id` from the TiKV log, run the following command:
95
+
To get the allocated ID from the PD log, you need to make sure that the log you are viewing is the log of **the last PD leader**, and you can get the maximum allocated ID by running the following command:
91
96
92
97
{{< copyable "shell-regular" >}}
93
98
94
-
```
95
-
ansible -i inventory.ini tikv_servers -m shell -a 'cat {{deploy_dir}}/log/tikv* | grep "alloc store" | head -10'
99
+
```bash
100
+
cat {{/path/to}}/pd*.log | grep "idAllocator allocates a new id"| awk -F'=''{print $2}'|awk -F']''{print $1}'| sort -r |head -n 1
96
101
```
97
102
98
-
```
99
-
10.0.1.13 | CHANGED | rc=0 >>
100
-
[2019/10/14 07:06:35.516 +00:00] [INFO] [node.rs:229] ["alloc store id 4 "]
101
-
10.0.1.14 | CHANGED | rc=0 >>
102
-
[2019/10/14 07:06:35.734 +00:00] [INFO] [node.rs:229] ["alloc store id 5 "]
103
-
10.0.1.15 | CHANGED | rc=0 >>
104
-
[2019/10/14 07:06:35.418 +00:00] [INFO] [node.rs:229] ["alloc store id 1 "]
105
-
10.0.1.21 | CHANGED | rc=0 >>
106
-
[2019/10/15 03:15:05.826 +00:00] [INFO] [node.rs:229] ["alloc store id 2001 "]
107
-
10.0.1.20 | CHANGED | rc=0 >>
108
-
[2019/10/15 03:15:05.987 +00:00] [INFO] [node.rs:229] ["alloc store id 2002 "]
103
+
```bash
104
+
4000
105
+
...
109
106
```
110
107
111
-
### Deploy a new PD cluster
112
-
113
-
To deploy a new PD cluster, run the following command:
108
+
Or you can simply run the above command in all PD servers to find the largest one.
114
109
115
-
{{< copyable "shell-regular" >}}
116
-
117
-
```
118
-
ansible-playbook bootsrap.yml --tags=pd &&
119
-
ansible-playbook deploy.yml --tags=pd &&
120
-
ansible-playbook start.yml --tags=pd
121
-
```
110
+
### Deploy a new PD cluster
122
111
123
-
To delete the old cluster, delete the `data.pd` directory and restart the PD service.
112
+
Before deploying a new PD cluster, you need to stop the the existing PD cluster and then delete the previous data directory which is specified by `--data-dir`.
0 commit comments