Skip to content

Commit 0c96f82

Browse files
committed
refactor: refactor Read Replica documentation structure
1 parent 1db3ede commit 0c96f82

File tree

9 files changed

+678
-174
lines changed

9 files changed

+678
-174
lines changed

docs/enterprise/read-replica.md

Lines changed: 0 additions & 173 deletions
This file was deleted.
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
keywords: [enterprise, cluster, read replicas, leader region, follower region]
3+
description: An overview, key concepts, and step-by-step guides for managing read replicas in GreptimeDB Enterprise.
4+
---
5+
6+
# Manage Read Replicas
7+
8+
This guide explains how to manage **Read Replicas (follower regions)** in GreptimeDB Enterprise, including how to add and remove read replicas at both the table and region levels, inspect the current regions distribution with the `SHOW REGION`, and apply placement constraints and recommended best practices for performance.
9+
10+
## Adding Read Replicas to a Table
11+
12+
Adding a Read Replica is as simple as executing one SQL command:
13+
14+
```sql
15+
ADMIN ADD_TABLE_FOLLOWER(<table_name>)
16+
```
17+
18+
Read Replica peers for each region are allocated based on the workload types of the datanodes. **For optimal performance, it is strongly recommended to [configure Datanode groups](/enterprise/deployments-administration/deploy-on-kubernetes/configure-datanode-groups.md) to separate read and write workloads into different datanode groups.**
19+
20+
This is the function in GreptimeDB for adding read replicas to. The parameters are:
21+
22+
- `table_name`: The name of the table to add read replicas to.
23+
24+
Next is an example to illustrate steps to add read replicas to a table.
25+
26+
First start a GreptimeDB Enterprise Cluster with 3 Datanodes. Then create a table:
27+
28+
```sql
29+
CREATE TABLE foo (
30+
ts TIMESTAMP TIME INDEX,
31+
i INT PRIMARY KEY,
32+
s STRING,
33+
) PARTITION ON COLUMNS ('i') (
34+
i <= 0,
35+
i > 0,
36+
);
37+
```
38+
39+
40+
Using the `SHOW REGION`, we can find the regions distribution information:
41+
42+
```sql
43+
SHOW REGION FROM foo;
44+
45+
+-------+---------------+------+--------+
46+
| Table | Region | Peer | Leader |
47+
+-------+---------------+------+--------+
48+
| foo | 4398046511104 | 0 | Yes |
49+
| foo | 4398046511105 | 1 | Yes |
50+
+-------+---------------+------+--------+
51+
```
52+
53+
This shows two write replicas (leader regions) on Datanodes `1` and `2`.
54+
55+
Then to add read replicas (Follower regions):
56+
57+
```sql
58+
ADMIN ADD_TABLE_FOLLOWER('foo');
59+
```
60+
61+
After the read replicas are added, find the regions distribution information:
62+
63+
```sql
64+
SHOW REGION FROM foo;
65+
66+
+-------+---------------+------------+--------+
67+
| Table | Region | Peer | Leader |
68+
+-------+---------------+------------+--------+
69+
| foo | 4398046511104 | 0 | Yes |
70+
| foo | 4398046511104 | 4294967296 | No |
71+
| foo | 4398046511105 | 1 | Yes |
72+
| foo | 4398046511105 | 4294967297 | No |
73+
+-------+---------------+------------+--------+
74+
```
75+
76+
Now, read replicas can be found on Datanode `4294967296` and `4294967297`.
77+
78+
## Removing Read Replicas from a Table
79+
80+
Removing a Read Replica is as simple as executing one SQL command:
81+
82+
```sql
83+
ADMIN REMOVE_TABLE_FOLLOWER(<table_name>)
84+
```
85+
86+
This is the function in GreptimeDB for removing read replicas from a table. The parameters are:
87+
88+
- `table_name`: The name of the table to remove read replicas from.
89+
90+
This command removes **the most recently added read replica' peers from each region**.
91+
92+
For example, before running the command:
93+
94+
```sql
95+
SHOW REGION FROM foo;
96+
+-------+---------------+------------+--------+
97+
| Table | Region | Peer | Leader |
98+
+-------+---------------+------------+--------+
99+
| foo | 4398046511104 | 0 | Yes |
100+
| foo | 4398046511104 | 4294967296 | No |
101+
| foo | 4398046511104 | 4294967297 | No |
102+
| foo | 4398046511105 | 1 | Yes |
103+
| foo | 4398046511105 | 4294967296 | No |
104+
| foo | 4398046511105 | 4294967297 | No |
105+
+-------+---------------+------------+--------+
106+
```
107+
108+
Here, region `4398046511104` has two read replicas on peers (`4294967296`, `4294967297`), and region `4398046511105` also has two read replicas on peers (`4294967296`, `4294967297`).
109+
After executing:
110+
111+
```sql
112+
ADMIN REMOVE_TABLE_FOLLOWER('foo');
113+
+------------------------------------+
114+
| ADMIN REMOVE_TABLE_FOLLOWER('foo') |
115+
+------------------------------------+
116+
| 0 |
117+
+------------------------------------+
118+
```
119+
120+
The most recently added read replicas' peers of each region are removed:
121+
122+
* Region `4398046511104`: removed read replica on peer `4294967297`.
123+
* Region `4398046511105`: removed read replica on peer `4294967296`.
124+
125+
Result:
126+
127+
```sql
128+
SHOW REGION FROM foo;
129+
+-------+---------------+------------+--------+
130+
| Table | Region | Peer | Leader |
131+
+-------+---------------+------------+--------+
132+
| foo | 4398046511104 | 0 | Yes |
133+
| foo | 4398046511104 | 4294967296 | No |
134+
| foo | 4398046511105 | 1 | Yes |
135+
| foo | 4398046511105 | 4294967297 | No |
136+
+-------+---------------+------------+--------+
137+
```
138+
139+
## Adding Read Replica to a Region
140+
```sql
141+
ADMIN ADD_REGION_FOLLOWER(<region_id>, <datanode_id>)
142+
```
143+
144+
This is the function in GreptimeDB for adding read replicas to a region. The parameters are:
145+
146+
- `region_id`: The id of the region to add Read Replica to.
147+
- `datanode_id`: The id of the datanode to add Read Replica to.
148+
149+
A read replica and a write replica cannot be placed on the same datanode. Additionally, each datanode can host only one read replica per region.
150+
151+
Example:
152+
153+
```sql
154+
-- Add a read replica for region 4398046511104 on datanode 2
155+
ADMIN ADD_REGION_FOLLOWER(4398046511104, 2);
156+
```
157+
158+
If the specified datanode already hosts a read replica for that region, or is the write replica (leader) of that region, the command will be rejected.
159+
160+
## Removing Read Replica from a Region
161+
```sql
162+
ADMIN REMOVE_REGION_FOLLOWER(<region_id>, <datanode_id>)
163+
```
164+
165+
This is the function in GreptimeDB for removing read replicas from a region. The parameters are:
166+
167+
- `region_id`: The id of the region to remove read replica from.
168+
- `datanode_id`: The id of the datanode to remove read replica from.
169+
170+
171+
Example:
172+
173+
```sql
174+
-- Remove the read replica on datanode 2 for region 4398046511104
175+
ADMIN REMOVE_REGION_FOLLOWER(4398046511104, 2);
176+
```
177+
178+
179+
## Next steps
180+
181+
* [Query Read Replicas](/enterprise/read-replicas/query-read-replicas.md)

0 commit comments

Comments
 (0)