Skip to content

Commit 1ee0efc

Browse files
committed
doc: add witness related docs
Signed-off-by: Aolin <[email protected]>
1 parent 0fb278e commit 1ee0efc

9 files changed

+158
-1
lines changed

TOC-tidb-cloud.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@
183183
- [Overview](/garbage-collection-overview.md)
184184
- [Configuration](/garbage-collection-configuration.md)
185185
- [Tune TiFlash performance](/tiflash/tune-tiflash-performance.md)
186+
- [Use Witness Replicas to Save Costs](/use-witness-to-save-costs.md)
187+
- [Use Witness Replicas to Speed Up Failover](/use-witness-to-speed-up-failover.md)
186188
- Security
187189
- Identity Access Control
188190
- [Password Authentication](/tidb-cloud/tidb-cloud-password-authentication.md)

TOC.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@
165165
- [Maintain TiDB Using TiUP](/maintain-tidb-using-tiup.md)
166166
- [Modify Configuration Dynamically](/dynamic-config.md)
167167
- [Online Unsafe Recovery](/online-unsafe-recovery.md)
168+
- [Use Witness Replicas to Save Costs](/use-witness-to-save-costs.md)
169+
- [Use Witness Replicas to Speed Up Failover](/use-witness-to-speed-up-failover.md)
168170
- [Replicate Data Between Primary and Secondary Clusters](/replicate-between-primary-and-secondary-clusters.md)
169171
- Monitor and Alert
170172
- [Monitoring Framework Overview](/tidb-monitoring-framework.md)

configure-placement-rules.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ aliases: ['/docs/dev/configure-placement-rules/','/docs/dev/how-to/configure/pla
1212
1313
Placement Rules, introduced in v5.0, is a replica rule system that guides PD to generate corresponding schedules for different types of data. By combining different scheduling rules, you can finely control the attributes of any continuous data range, such as the number of replicas, the storage location, the host type, whether to participate in Raft election, and whether to act as the Raft leader.
1414

15-
The Placement Rules feature is enabled by default in v5.0 and later versions of TiDB. To disable it, refer to [Disable Placement Rules](#disable-placement-rules).
15+
The Placement Rules feature is enabled by default in v5.0 and later versions of TiDB. To disable it, refer to [Disable Placement Rules](#disable-placement-rules).
1616

1717
## Rule system
1818

@@ -37,6 +37,7 @@ The following table shows the meaning of each field in a rule:
3737
| `StartKey` | `string`, in hexadecimal form | Applies to the starting key of a range. |
3838
| `EndKey` | `string`, in hexadecimal form | Applies to the ending key of a range. |
3939
| `Role` | `string` | Replica roles, including voter/leader/follower/learner. |
40+
| `IsWitness` | `true`/`false` | Whether it is a [Witness](/glossary.md#witness) replica or not. |
4041
| `Count` | `int`, positive integer | The number of replicas. |
4142
| `LabelConstraint` | `[]Constraint` | Filters nodes based on the label. |
4243
| `LocationLabels` | `[]string` | Used for physical isolation. |
@@ -486,3 +487,32 @@ The rule group:
486487
"override": true,
487488
}
488489
```
490+
491+
### Scenario 6: Configure Witness replicas in a highly reliable storage environment
492+
493+
The following rule shows how to configure `IsWitness` and uses Amazon EBS as an example to save costs by configuring [Witness](/glossary.md#witness) replicas.
494+
495+
The rule is as follows:
496+
497+
```json
498+
[
499+
{
500+
"group_id": "pd",
501+
"id": "default",
502+
"start_key": "",
503+
"end_key": "",
504+
"role": "voter",
505+
"is_witness": false,
506+
"count": 2
507+
},
508+
{
509+
"group_id": "pd",
510+
"id": "witness",
511+
"start_key": "",
512+
"end_key": "",
513+
"role": "voter",
514+
"is_witness": true,
515+
"count": 1
516+
}
517+
]
518+
```

glossary.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,12 @@ Because TiKV is a distributed storage system, it requires a global timing servic
159159
### TTL
160160

161161
[Time to live (TTL)](/time-to-live.md) is a feature that allows you to manage TiDB data lifetime at the row level. For a table with the TTL attribute, TiDB automatically checks data lifetime and deletes expired data at the row level.
162+
163+
## W
164+
165+
### Witness
166+
167+
A Witness replica only stores the most recent Raft logs for majority confirmation, but does not store data. The scenarios for using a Witness replica are as follows:
168+
169+
- Save costs in a highly reliable storage environment. For more details, see [Use Witness replicas to save costs](/use-witness-to-save-costs.md).
170+
- Quickly recover from any failure to improve system availability. For more details, see [Use Witness replicas to speed up failover](/use-witness-to-speed-up-failover.md).

pd-configuration-file.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ Configuration items related to scheduling
222222
+ Controls the time interval between the `split` and `merge` operations on the same Region. That means a newly split Region will not be merged for a while.
223223
+ Default value: `1h`
224224
225+
### `switch-witness-interval` <span class="version-mark">New in v6.6.0</span>
226+
227+
+ Controls the time interval between the switch to [Witness](/glossary.md#witness) and the switch to non-Witness operations on the same Region. That means a newly switched to non-Witness Region will not be switched to Witness for a while.
228+
+ Default value: `1h`
229+
225230
### `max-snapshot-count`
226231
227232
+ Controls the maximum number of snapshots that a single store receives or sends at the same time. PD schedulers depend on this configuration to prevent the resources used for normal traffic from being preempted.
@@ -277,6 +282,21 @@ Configuration items related to scheduling
277282
+ The number of the `Region Merge` scheduling tasks performed at the same time. Set this parameter to `0` to disable `Region Merge`.
278283
+ Default value: `8`
279284
285+
### `witness-schedule-limit` <span class="version-mark">New in v6.6.0</span>
286+
287+
+ Controls the concurrency of Witness scheduling tasks.
288+
+ Default value: `4`
289+
+ Minimum value: `1`
290+
+ Maximum value: `9`
291+
292+
### `enable-witness` <span class="version-mark">New in v6.6.0</span>
293+
294+
+ Controls whether to enable the Witness replica feature.
295+
+ The scenarios for using a Witness replica are as follows:
296+
- Save costs in a highly reliable storage environment. For more details, see [Use Witness replicas to save costs](/use-witness-to-save-costs.md).
297+
- Quickly recover from any failure to improve system availability. For more details, see [Use Witness replicas to speed up failover](/use-witness-to-speed-up-failover.md).
298+
+ Default value: `false`
299+
280300
### `high-space-ratio`
281301
282302
+ The threshold ratio below which the capacity of the store is sufficient. If the space occupancy ratio of the store is smaller than this threshold value, PD ignores the remaining space of the store when performing scheduling, and balances load mainly based on the Region size. This configuration takes effect only when `region-score-formula-version` is set to `v1`.

pd-control.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ Usage:
140140
},
141141
"schedule": {
142142
"enable-cross-table-merge": "true",
143+
"enable-witness": "true",
143144
"high-space-ratio": 0.7,
144145
"hot-region-cache-hits-threshold": 3,
145146
"hot-region-schedule-limit": 4,
@@ -1088,6 +1089,17 @@ unsafe remove-failed-stores show
10881089
]
10891090
```
10901091
1092+
To enable the [Witness replica](/glossary.md#witness) feature, run the following command:
1093+
1094+
```bash
1095+
config set enable-witness true
1096+
```
1097+
1098+
The scenarios for using a Witness replica are as follows:
1099+
1100+
- Save costs in a highly reliable storage environment. For more details, see [Use Witness replicas to save costs](/use-witness-to-save-costs.md).
1101+
- Quickly recover from any failure to improve system availability. For more details, see [Use Witness replicas to speed up failover](/use-witness-to-speed-up-failover.md).
1102+
10911103
## Jq formatted JSON output usage
10921104
10931105
### Simplify the output of `store`

tidb-cloud/serverless-tier-limitations.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ We are constantly filling in the feature gaps between Serverless Tier and Dedica
4646

4747
* [Changefeed](/tidb-cloud/changefeed-overview.md) is not supported for Serverless Tier currently.
4848
* [Data Migration](/tidb-cloud/migrate-from-mysql-using-data-migration.md) is not supported for Serverless Tier currently.
49+
50+
## Storage
51+
52+
- [Use Witness Replicas to Save Costs](/use-witness-to-save-costs.md) and [Use Witness Replicas to Speed Up Failover](/use-witness-to-speed-up-failover.md)) are not supported for Serverless Tier clusters currently.

use-witness-to-save-costs.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Use Witness Replicas to Save Costs
3+
summary: Learn how to use Witness replicas to save costs in a highly reliable storage environment.
4+
---
5+
6+
# Use Witness Replicas to Save Costs
7+
8+
This document describes how to use Witness replicas to save costs in a highly reliable storage environment. If you need to use Witness replicas to improve the durability when a TiKV node is down, refer to [Use Witness replicas to speed up failover](/use-witness-to-speed-up-failover.md).
9+
10+
## Feature description
11+
12+
In cloud environments, it is recommended to use Amazon Elastic Block Store (EBS) with 99.8%~99.9% durability or Persistent Disk of Google Cloud Platform (GCP) with 99.99%~99.999% durability as the storage of each TiKV node. In this case, using three Raft replicas with TiKV is possible but not necessary. To reduce costs, TiKV introduces the Witness replica, which is the "2 Replicas With 1 Log Only" mechanism. The 1 Log Only replica only stores Raft logs and does not apply data, and still ensures data consistency through the Raft protocol. Compared with the standard three replica architecture, the Witness replica can save storage resources and CPU usage.
13+
14+
> **Warning:**
15+
>
16+
> The Withness replica is introduced in v6.6.0 and is not compatible with previous versions. It is not supported to downgrade.
17+
18+
## User scenarios
19+
20+
In a highly reliable storage environment (99.8%~99.9%), such as Amazon EBS and Persistent Disk of GCP, you can enable and configure Witness replicas to save costs.
21+
22+
## Usage
23+
24+
### Step 1: Enable Witness
25+
26+
To enable Witness, use PD Control to run the `config set enable-witness true` command:
27+
28+
```bash
29+
pd-ctl config set enable-witness true
30+
```
31+
32+
If the command returns `Success`, the Witness replica feature is enabled. If you have not configured Witness replicas using Placement Rules, no Witness replicas will be created by default. Only when a TiKV node is down, a Witness replica will be added immediately and will be promoted to a normal Voter by the system later.
33+
34+
### Step 2: Configure Witness replicas
35+
36+
As an example of three replicas, modify `rule.json` to the configuration in [Scenario 6: Configure Witness replicas in a highly reliable storage environment](/configure-placement-rules.md#scenario-6-configure-witness-replicas-in-a-highly-reliable-storage-environment).
37+
38+
After editing the file, use the following command to save the configuration to the PD server:
39+
40+
```bash
41+
pd-ctl config placement-rules save --in=rule.json
42+
```
43+
44+
## Notes
45+
46+
- It is recommended to configure Witness replicas only in a highly reliable storage environment, such as using Amazon EBS with 99.8%~99.9% durability or Persistent Disk of GCP with 99.99%~99.999% durability to store TiKV nodes.
47+
- Since a Witness replica does not apply Raft logs, it cannot provide read and write services. When the Leader is down and the remaining Voters do not have the latest Raft logs, Raft elects the Witness replica as a Leader. After the Witness replica is elected, it sends Raft logs to Voters and transfers the leader to a Voter. If the Witness replica cannot transfer the leader in time, the application might receive an `IsWitness` error after the Backoff timeout.
48+
- When there is a pending Voter in the system, to prevent the Witness replica from accumulating too many Raft logs and occupying the entire disk space, the system will promote the Witness replica to a normal Voter.

use-witness-to-speed-up-failover.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Use Witness Replicas to Speed Up Failover
3+
summary: Learn how to use a Witness replica to speed up failover.
4+
---
5+
6+
# Use Witness Replicas to Speed Up Failover
7+
8+
This document describes how to use Witness replicas to improve durability when a TiKV node is down. If you need to use Witness replicas to save costs in a high-reliability storage environment, refer to [Use Witness replicas to save costs](/use-witness-to-save-costs.md).
9+
10+
## Feature description
11+
12+
The Witness feature can be used to quickly recover from any failure (failover) to improve system availability and data durability. For example, in a Raft group of three replicas, if one replica fails, the system is fragile although it meets the majority requirement. It takes a long time to recover a new member (the process requires copying the snapshot first and then applying the latest logs), especially when the Region snapshot is large. In addition, the process of copying replicas might cause more pressure on unhealthy Group members. Therefore, adding a Witness replica can quickly remove the unhealthy node, reduce the risk of the Raft group being unavailable due to another node failure when recovering a new member (the Learner replica cannot participate in the election and submission), and ensure the security of logs during recovery.
13+
14+
> **Warning:**
15+
>
16+
> The Withness replica is introduced in v6.6.0 and is not compatible with previous versions. It is not supported to downgrade.
17+
18+
## User scenarios
19+
20+
In a scenario where you want to quickly recover from any failure to improve durability, you can enable Witness without configuring a Witness replica.
21+
22+
## Usage
23+
24+
To enable Witness, use PD Control to run the `config set enable-witness true` command:
25+
26+
```bash
27+
pd-ctl config set enable-witness true
28+
```
29+
30+
If the command returns `Success`, the Witness replica feature is enabled. If you have not configured Witness replicas according to [Use Witness replicas to save costs](/use-witness-to-save-costs.md), no Witness replicas will be created by default. Only when a TiKV node is down, a Witness replica will be added immediately and will be promoted to a normal Voter by the system later.

0 commit comments

Comments
 (0)