Webinar: Replication and Replica Sets
-
Upload
mongodb -
Category
Technology
-
view
2.209 -
download
1
description
Transcript of Webinar: Replication and Replica Sets
![Page 1: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/1.jpg)
Consulting Engineer, MongoDB
Rohit Nijhawan
Introduction to Replication and Replica Sets
![Page 2: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/2.jpg)
Agenda
• Replica Sets Lifecycle
• Developing with Replica Sets
• Operational Considerations
![Page 3: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/3.jpg)
Why Replication?
• How many have faced node failures?
• How many have been woken up from sleep to do a fail-over(s)?
• How many have experienced issues due to network latency?
• Different uses for data– Normal processing– Simple analytics
![Page 4: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/4.jpg)
Replica Set Lifecycle
![Page 5: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/5.jpg)
Replica Set – Creation
![Page 6: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/6.jpg)
Replica Set – Initialize
![Page 7: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/7.jpg)
Replica Set – Failure
![Page 8: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/8.jpg)
Replica Set – Failover
![Page 9: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/9.jpg)
Replica Set – Recovery
![Page 10: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/10.jpg)
Replica Set – Recovered
![Page 11: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/11.jpg)
Replica Set Roles & Configuration
![Page 12: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/12.jpg)
Replica Set Roles
![Page 13: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/13.jpg)
> conf = {
_id : "mySet",
members : [
{_id : 0, host : "A”, priority : 3},
{_id : 1, host : "B", priority : 2},
{_id : 2, host : "C”},
{_id : 3, host : "D", hidden : true},
{_id : 4, host : "E", hidden : true, slaveDelay : 3600}
]
}
> rs.initiate(conf)
Configuration Options
![Page 14: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/14.jpg)
> conf = {
_id : "mySet”,
members : [
{_id : 0, host : "A”, priority : 3},
{_id : 1, host : "B", priority : 2},
{_id : 2, host : "C”},
{_id : 3, host : "D", hidden : true},
{_id : 4, host : "E", hidden : true, slaveDelay : 3600}
]
}
> rs.initiate(conf)
Configuration Options
Primary DC
![Page 15: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/15.jpg)
> conf = {
_id : "mySet”,
members : [
{_id : 0, host : "A”, priority : 3},
{_id : 1, host : "B", priority : 2},
{_id : 2, host : "C”},
{_id : 3, host : "D", hidden : true},
{_id : 4, host : "E", hidden : true, slaveDelay : 3600}
]
}
> rs.initiate(conf)
Configuration Options
Secondary DCDefault Priority = 1
![Page 16: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/16.jpg)
> conf = {
_id : "mySet”,
members : [
{_id : 0, host : "A”, priority : 3},
{_id : 1, host : "B", priority : 2},
{_id : 2, host : "C”},
{_id : 3, host : "D", hidden : true},
{_id : 4, host : "E", hidden : true, slaveDelay : 3600}
]
}
> rs.initiate(conf)
Configuration Options
Analytics
node
![Page 17: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/17.jpg)
> conf = {
_id : "mySet”,
members : [
{_id : 0, host : "A”, priority : 3},
{_id : 1, host : "B", priority : 2},
{_id : 2, host : "C”},
{_id : 3, host : "D", hidden : true},
{_id : 4, host : "E", hidden : true, slaveDelay : 3600}
]
}
> rs.initiate(conf)
Configuration Options
Backup node
![Page 18: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/18.jpg)
Developing with Replica Sets
![Page 19: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/19.jpg)
Strong Consistency
![Page 20: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/20.jpg)
Delayed Consistency
![Page 21: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/21.jpg)
Write Concern
• Network acknowledgement
• Wait for error
• Wait for journal sync
• Wait for replication
![Page 22: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/22.jpg)
Unacknowledged
![Page 23: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/23.jpg)
MongoDB Acknowledged (wait for error)
![Page 24: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/24.jpg)
Wait for Journal Sync
![Page 25: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/25.jpg)
Wait for Replication
![Page 26: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/26.jpg)
Tagging
• Control where data is written to, and read from
• Each member can have one or more tags– tags: {dc: "ny"}– tags: {dc: "ny", subnet: "192.168", rack:
"row3rk7"}
• Replica set defines rules for write concerns
• Rules can change without changing app code
![Page 27: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/27.jpg)
{
_id : "mySet",
members : [
{_id : 0, host : "A", tags : {"dc": "ny"}},
{_id : 1, host : "B", tags : {"dc": "ny"}},
{_id : 2, host : "C", tags : {"dc": "sf"}},
{_id : 3, host : "D", tags : {"dc": "sf"}},
{_id : 4, host : "E", tags : {"dc": "cloud"}}],
settings : {
getLastErrorModes : {
allDCs : {"dc" : 3},
someDCs : {"dc" : 2}} }
}
> db.blogs.insert({...})
> db.runCommand({getLastError : 1, w : "someDCs"})
Tagging Example
![Page 28: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/28.jpg)
Wait for Replication (Tagging)
![Page 29: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/29.jpg)
Read Preference Modes
• 5 modes– primary (only) - Default– primaryPreferred– secondary– secondaryPreferred– Nearest
When more than one node is possible, closest node is used for reads (all modes but primary)
![Page 30: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/30.jpg)
Operational Considerations
![Page 31: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/31.jpg)
Maintenance and Upgrade
• No downtime
• Rolling upgrade/maintenance– Start with Secondary– Primary last
![Page 32: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/32.jpg)
Replica Set – 1 Data Center
Single datacenter
Single switch & power
Points of failure:– Power– Network– Data center– Two node failure
Automatic recovery of single node crash
![Page 33: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/33.jpg)
Replica Set – 2 Data Centers
Multi data center
DR node for safety
Can’t do multi data center durable write safely since only 1 node in distant DC
![Page 34: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/34.jpg)
Replica Set – 3 Data Centers
Three data centers
Can survive full data center loss
Can do w= { dc : 2 } to guarantee write in 2 data centers (with tags)
![Page 35: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/35.jpg)
Recent improvements
Read preference support with sharding– Drivers too
Improved replication over WAN/high-latency networks
rs.syncFrom command
buildIndexes setting
replIndexPrefetch setting
![Page 36: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/36.jpg)
Just Use It
Use replica sets
Easy to setup – Try on a single machine
Check doc page for RS tutorials– http://docs.mongodb.org/manual/replication/
#tutorials
![Page 37: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/37.jpg)
Questions?
![Page 38: Webinar: Replication and Replica Sets](https://reader036.fdocuments.net/reader036/viewer/2022062513/5562537bd8b42a1b4b8b4f5e/html5/thumbnails/38.jpg)
Thank You
Consulting Engineer, MongoDB
Rohit Nijhawan