Skip to content

Commit e90256c

Browse files
authored
Merge pull request #185 from heywalter/add-disaster-recovery-practice
Add Docs for Disaster Recovery
2 parents f608ed5 + a9dfaea commit e90256c

4 files changed

Lines changed: 345 additions & 0 deletions

File tree

.github/actions/spelling/allow.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,12 @@ JVM
694694
analyticdb
695695
ttl
696696
XUANWU
697+
Grafana
698+
Nginx
699+
pingtime
700+
reconfig
701+
RTO
702+
wtimeout
697703
bfd
698704
currentopmetrics
699705
daguozb
176 KB
Loading
Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
# TapData Cross-Data Center Disaster Recovery Guide
2+
3+
This guide outlines TapData's disaster recovery (DR) solution for cross-data center or availability zone failures, ideal for production setups where an entire site outage could disrupt operations. By leveraging a "primary cluster + cold standby services + hot data" model, it ensures real-time data replication across regions and quick service failover, minimizing downtime during regional disruptions.
4+
5+
:::tip
6+
For high availability within a single cluster (to handle individual node failures), see [Deploying High-Availability TapData Enterprise (Three Nodes)](install-tapdata-ha-with-3-node.md).
7+
:::
8+
9+
## 1. Overview and Solution Design
10+
11+
TapData uses a distributed architecture with key components like TapData Management (for task orchestration), TapData Engine (for data processing), TapData Agent (for data collection), and MongoDB (for metadata storage). While intra-cluster high availability protects against single-point failures, a full data center outage can still halt business activities.
12+
13+
To boost resilience and data continuity, TapData offers a cross-data center/availability zone DR approach, suitable for scenarios such as:
14+
- **Multi-site deployments**: Primary and standby sites in separate data centers or geographic regions.
15+
- **Regional outage protection**: Handling power failures, network blackouts, natural disasters, or other site-wide issues.
16+
- **Stringent continuity needs**: Meeting low Recovery Time Objective (RTO) and Recovery Point Objective (RPO) targets.
17+
- **Compliance standards**: Fulfilling regulatory demands for robust DR capabilities.
18+
19+
![Disaster Recovery Architecture](../../images/disaster_recovery_architecture.png)
20+
21+
The solution employs a dual-site setup with TapData's stateless design and MongoDB's cross-region replica sets for seamless high-availability DR.
22+
23+
- **Zone A (Primary Cluster)**: Hosts the full TapData stack (3 nodes) + MongoDB replica set (3 nodes), managing all production workloads.
24+
- **Zone S (Standby Cluster)**: Pre-configured TapData services (stopped, 3 nodes) + MongoDB replica set (2 nodes active + 1 pre-provisioned), focused solely on data replication during normal operations.
25+
26+
:::tip Data Replication Mechanism
27+
MongoDB's cross-region replica set handles real-time syncing of tasks, metadata, and system states, keeping the standby site in sync with the primary. For detailed replica set setup and failover details, refer to the sections below.
28+
:::
29+
30+
## 2. Host Setup and Deployment Requirements
31+
32+
Based on the architecture above, here's an example host configuration and deployment guidelines:
33+
34+
### 2.1 Host Configuration Details
35+
36+
| Hostname | IP Address | Zone | MongoDB Role | TapData Services | Notes |
37+
|------------|----------------|--------|---------------------------|------------------|------------------------|
38+
| tapdata-a | 192.168.1.10 | Zone A | Primary | **Running** | Primary node |
39+
| tapdata-b | 192.168.1.11 | Zone A | Secondary | **Running** | Secondary node |
40+
| tapdata-c | 192.168.1.12 | Zone A | Secondary | **Running** | Secondary node |
41+
| tapdata-d | 192.168.2.10 | Zone S | Secondary (non-voting) | **Stopped** | Standby node |
42+
| tapdata-e | 192.168.2.11 | Zone S | Secondary (non-voting) | **Stopped** | Standby node |
43+
| tapdata-f | 192.168.2.12 | Zone S | Pre-provisioned (not in replica set) | **Stopped** | Activated only during Zone A failure |
44+
45+
:::tip Network Latency Recommendations
46+
Use dedicated lines for cross-region connectivity, aiming for latency under **100ms** to maintain MongoDB replication performance and timely failure detection. Ensure required ports are open, such as MongoDB (27017), TapData Management (3030), TapData Engine (3080), and SSH (22).
47+
:::
48+
49+
### 2.2 MongoDB Cross-Region Replica Set Configuration
50+
51+
MongoDB serves as TapData's core storage for task configs, metadata, and system states. This setup uses a 5-node cross-region replica set: Zone A (3 nodes) + Zone S (2 nodes), with priorities favoring Zone A for the primary role.
52+
53+
**Key Benefits:**
54+
- **Automatic Syncing**: Data replicates from Zone A to Zone S in real time.
55+
- **Failover Automation**: Built-in election handles primary node failures.
56+
- **Redundancy**: Multiple copies prevent data loss from single failures.
57+
58+
**Recommended Replica Set Config:**
59+
```javascript
60+
rs.reconfig({
61+
members: [
62+
{ _id: 0, host: "192.168.1.10:27017", priority: 2 }, // Zone A primary
63+
{ _id: 1, host: "192.168.1.11:27017", priority: 1 }, // Zone A secondary
64+
{ _id: 2, host: "192.168.1.12:27017", priority: 1 }, // Zone A secondary
65+
{ _id: 3, host: "192.168.2.10:27017", priority: 0 }, // Zone S secondary
66+
{ _id: 4, host: "192.168.2.11:27017", priority: 0 }, // Zone S secondary
67+
]
68+
})
69+
```
70+
71+
**Recommended Write Concern Settings:**
72+
```javascript
73+
// TapData's suggested MongoDB write concern for reliability
74+
db.adminCommand({
75+
setDefaultRWConcern: 1,
76+
defaultWriteConcern: {
77+
w: "majority", // Confirm after writing to most nodes
78+
j: true, // Ensure journal commit
79+
wtimeout: 5000 // 5-second timeout
80+
}
81+
})
82+
```
83+
84+
This ensures writes are acknowledged only after reaching at least 3 nodes (majority in a 5-node set), guaranteeing consistency. Writes typically occur in Zone A, with automatic replication to Zone S.
85+
86+
### 2.3 TapData Service Configuration
87+
88+
**Connection String Setup:**
89+
All TapData nodes share a unified MongoDB replica set connection string:
90+
```bash
91+
# Replace {databaseName} with your TapData database name
92+
mongodb://192.168.1.10:27017,192.168.1.11:27017,192.168.1.12:27017,192.168.2.10:27017,192.168.2.11:27017,192.168.2.12:27017/tapdata?replicaSet=tapdata-rs
93+
```
94+
95+
**Deployment Strategy:**
96+
- **Zone A**: All TapData services run actively for production.
97+
- **Zone S**: Services are installed and configured but remain stopped as cold standby.
98+
- **Config Sync**: Regularly mirror configs from Zone A to Zone S.
99+
100+
**Key Config Files to Sync:**
101+
- **`application.yml`**: Main TapData service config.
102+
- **`agent.yml`**: TapData Agent config.
103+
104+
**Sync Command Example:**
105+
```bash
106+
# Copy configs from Zone A to Zone S (adjust <work_dir> based on your TapData install path)
107+
scp <work_dir>/conf/{application.yml,agent.yml} root@192.168.2.10:<work_dir>/conf/
108+
scp <work_dir>/conf/{application.yml,agent.yml} root@192.168.2.11:<work_dir>/conf/
109+
scp <work_dir>/conf/{application.yml,agent.yml} root@192.168.2.12:<work_dir>/conf/
110+
```
111+
112+
## 3. Disaster Recovery Procedures
113+
114+
### 3.1 Recovery Targets
115+
116+
#### 3.1.1 Recovery Time Objective (RTO)
117+
- **Detection**: 1-2 minutes (via alerts + manual confirmation).
118+
- **MongoDB Failover**: 30 seconds-1 minute (automatic election).
119+
- **TapData Startup**: 2-3 minutes (service launch + health checks).
120+
- **Load Balancer Switch**: 1-2 minutes (DNS/LB updates).
121+
- **Total RTO**: 5-8 minutes.
122+
123+
#### 3.1.2 Recovery Point Objective (RPO)
124+
- **Real-Time Sync**: Handled by replica set replication.
125+
- **Theoretical RPO**: ≤ 30 seconds (accounting for network latency).
126+
- **Practical RPO**: ≤ 1 minute (factoring in potential jitter).
127+
128+
### 3.2 Failover (Zone A to Zone S)
129+
130+
:::tip Automated Detection
131+
Set up monitoring and alerts for automatic failure detection—see [Monitoring and Automation](#41-monitoring-and-automation) for details.
132+
:::
133+
134+
#### 3.2.1 Pre-Failover Checks
135+
136+
**Confirm Outage:**
137+
1. **Multi-Path Verification**: Use various routes and monitoring tools to verify Zone A is inaccessible.
138+
2. **Scope Assessment**: Determine if it's a full Zone A failure or isolated nodes.
139+
140+
**Standby Readiness:**
141+
142+
1. **Zone S MongoDB Health**: Ensure tapdata-d and tapdata-e are running with no replication lag.
143+
2. **TapData Configs**: Confirm configs are synced and dependencies are available.
144+
3. **Connectivity**: Verify Zone S can reach external systems.
145+
146+
#### 3.2.2 Failover Steps
147+
148+
1. **Start MongoDB on Zone S**
149+
150+
Log in to tapdata-f and run:
151+
```bash
152+
systemctl start mongod
153+
```
154+
155+
2. **Reconfigure Replica Set**
156+
157+
Log in to tapdata-d or tapdata-e and execute:
158+
```javascript
159+
mongo --host tapdata-d:27017 # Or tapdata-e:27017
160+
161+
// Add node f first
162+
rs.add({ _id: 5, host: "192.168.2.12:27017", priority: 0 })
163+
164+
// Then reconfigure to 3-node setup
165+
var conf = rs.conf()
166+
conf.members = [
167+
{ _id: 3, host: "tapdata-d:27017", priority: 1 },
168+
{ _id: 4, host: "tapdata-e:27017", priority: 0 },
169+
{ _id: 5, host: "tapdata-f:27017", priority: 0 }
170+
]
171+
rs.reconfig(conf, {force:true})
172+
```
173+
174+
3. **Update Task States**
175+
176+
Log in to the new primary (usually tapdata-d) and run:
177+
```javascript
178+
mongo --host tapdata-d:27017 # Or current primary
179+
use {databaseName}; # Replace with your TapData database name
180+
db.Task.updateMany({}, { $set: { pingtime: -1 } })
181+
```
182+
183+
4. **Launch TapData Services**
184+
185+
On each Zone S node (tapdata-d, tapdata-e, tapdata-f), run:
186+
```bash
187+
systemctl start tapdata
188+
```
189+
190+
5. **Redirect Load Balancer** to Zone S
191+
> Update your access layer (e.g., Nginx, HAProxy, F5) to route client traffic from Zone A to Zone S TapData services.
192+
193+
6. **Validate Recovery**:
194+
- **Task Health**: Ensure sync tasks are running without errors.
195+
- **Data Integrity**: Sample source-to-target comparisons for completeness.
196+
- **Service Availability**: Test via web UI or API.
197+
- **Performance Metrics**: Monitor CPU, memory, and network usage.
198+
- **Logs**: Review for anomalies.
199+
200+
### 3.3 Recovery (Zone S to Zone A)
201+
202+
#### 3.3.1 Pre-Recovery Checks
203+
204+
**Zone A Readiness:**
205+
1. **Infrastructure**: Confirm hardware, network, and storage are fully operational.
206+
2. **Connectivity**: Test links between Zone A, external systems, and Zone S.
207+
3. **Dependencies**: Verify related services (e.g., databases, queues) are up.
208+
209+
**Data Sync Validation:**
210+
1. **Zone S Integrity**: Check current data for completeness.
211+
2. **Lag Check**: Ensure no replication delays across the set.
212+
3. **Monitoring**: Confirm alert systems are functional for the switchback.
213+
214+
#### 3.3.2 Recovery Steps
215+
216+
1. **Start MongoDB on Zone A**
217+
218+
On each Zone A node (tapdata-a, tapdata-b, tapdata-c), run:
219+
```bash
220+
systemctl start mongod
221+
```
222+
223+
2. **Reconfigure 5-Node Replica Set**
224+
225+
Log in to the current primary (in Zone S, e.g., tapdata-d) and execute:
226+
```javascript
227+
mongo --host tapdata-d:27017 # Or current primary
228+
var conf = rs.conf();
229+
conf.members = [
230+
{ _id: 0, host: "tapdata-a:27017", priority: 2 },
231+
{ _id: 1, host: "tapdata-b:27017", priority: 1 },
232+
{ _id: 2, host: "tapdata-c:27017", priority: 1 },
233+
{ _id: 3, host: "tapdata-d:27017", priority: 0 },
234+
{ _id: 4, host: "tapdata-e:27017", priority: 0 }
235+
]
236+
rs.reconfig(conf, {force: true})
237+
```
238+
239+
3. **Check Replica Set Status**
240+
241+
Log in to any node (preferably tapdata-a) and run:
242+
```javascript
243+
mongo --host tapdata-a:27017
244+
rs.status()
245+
```
246+
247+
4. **Transfer Primary** (If Needed)
248+
249+
**Condition**: If the primary isn't in Zone A (still in Zone S).
250+
251+
Log in to the current primary and run:
252+
```javascript
253+
# Check current primary
254+
mongo --host tapdata-d:27017
255+
rs.status()
256+
257+
# Connect to current primary (assuming tapdata-d)
258+
mongo --host tapdata-d:27017
259+
260+
# Step down to trigger re-election
261+
rs.stepDown()
262+
263+
# Confirm new primary is in Zone A
264+
rs.status()
265+
```
266+
267+
5. **Stop Zone S Services**
268+
269+
On tapdata-d and tapdata-e, run:
270+
```bash
271+
systemctl stop tapdata
272+
```
273+
274+
On tapdata-f, run:
275+
```bash
276+
systemctl stop tapdata
277+
systemctl stop mongod # Stop MongoDB
278+
```
279+
280+
6. **Update Tasks and Start Zone A Services**
281+
282+
Log in to Zone A's primary (usually tapdata-a) and run:
283+
```javascript
284+
mongo --host tapdata-a:27017 # Or current primary
285+
use {databaseName}; # Replace with your TapData database name
286+
db.Task.updateMany({}, { $set: { pingtime: -1 } })
287+
```
288+
289+
On each Zone A node (tapdata-a, tapdata-b, tapdata-c), run:
290+
```bash
291+
systemctl start tapdata
292+
```
293+
294+
7. **Validate and Gradually Shift Traffic** back to the primary site.
295+
296+
Perform checks from any Zone A or management node.
297+
298+
## 4. Operations Best Practices
299+
300+
### 4.1 Monitoring and Automation
301+
302+
#### 4.1.1 Failure Detection and Alerts
303+
304+
**Detection Intervals:**
305+
- **Connectivity**: TCP port checks (MongoDB 27017, TapData 3030) every 30 seconds.
306+
- **Service Health**: Replica set status and TapData API checks every 1 minute.
307+
- **Business Metrics**: Task states and replication lag every 5 minutes.
308+
309+
**Alert Rules:**
310+
- MongoDB primary unresponsive for 2 minutes → Critical.
311+
- TapData service down for 3 minutes → Critical.
312+
- Replication lag >5 minutes → Warning.
313+
- >50% Zone A nodes failed → Auto-trigger failover.
314+
315+
#### 4.1.2 Automation Scripts
316+
317+
**Health Monitoring:**
318+
- Integrate tools like Prometheus + Grafana for real-time node and performance tracking.
319+
320+
**Automated Failover:**
321+
- Trigger scripts on failure conditions for replica set reconfiguration, service starts, and validations.
322+
- Test thoroughly in staging before production rollout.
323+
324+
### 4.2 Regular Drills and Monitoring
325+
326+
- **Drill Schedule**: Conduct full DR simulations quarterly, covering detection, failover, validation, and recovery.
327+
- **Key Metrics**: Track uptime, sync lag, and resource utilization.
328+
- **Alerting**: Use tiered notifications for prompt responses.
329+
- **Documentation**: Log drill outcomes, issues, and improvements.
330+
331+
Consistent drills and monitoring refinements are essential for reliable DR. Tailor strategies to your business needs for ongoing enhancements.
332+
333+
### 4.3 Documentation and Security
334+
335+
- **Procedures**: Keep DR docs current, including emergency contacts.
336+
- **Change Logs**: Record all architecture and config updates.
337+
- **Access Controls**: Limit permissions for standby environments.
338+
- **Data Security**: Secure cross-region transfers and routinely verify backup integrity.

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ const sidebars = {
408408
'platform-ops/production-deploy/capacity-planning',
409409
'platform-ops/production-deploy/install-tapdata-ha',
410410
'platform-ops/production-deploy/install-tapdata-ha-with-3-node',
411+
'platform-ops/production-deploy/disaster-recovery',
411412
'platform-ops/production-deploy/install-replica-mongodb',
412413
]
413414
},

0 commit comments

Comments
 (0)