Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Internal Tools, 10genJ. Randall Hunt#MongoDBDaysIntroduction to Replicationand Replica Sets
Agenda• Replica Sets Lifecycle• Developing with Replica Sets• Operational Considerations
Why Replication?• How many have faced node failures?• How many have been woken up from sleep todo a fail-over(s)?• How man...
Replica Set Lifecycle
Replica Set – Creation
Replica Set – Initialize
Replica Set – Failure
Replica Set – Failover
Replica Set – Recovery
Replica Set – Recovered
Replica Set Roles &Configuration
Replica Set Roles
> conf = {_id : "mySet",members : [{_id : 0, host : "A”, priority : 3},{_id : 1, host : "B", priority : 2},{_id : 2, host ...
> conf = {_id : "mySet”,members : [{_id : 0, host : "A”, priority : 3},{_id : 1, host : "B", priority : 2},{_id : 2, host ...
> conf = {_id : "mySet”,members : [{_id : 0, host : "A”, priority : 3},{_id : 1, host : "B", priority : 2},{_id : 2, host ...
> conf = {_id : "mySet”,members : [{_id : 0, host : "A”, priority : 3},{_id : 1, host : "B", priority : 2},{_id : 2, host ...
> conf = {_id : "mySet”,members : [{_id : 0, host : "A”, priority : 3},{_id : 1, host : "B", priority : 2},{_id : 2, host ...
Developing with ReplicaSets
Strong Consistency
Delayed Consistency
Write Concern• Network acknowledgement• Wait for error• Wait for journal sync• Wait for replication
Unacknowledged
MongoDB Acknowledged (wait forerror)
Wait for Journal Sync
Wait for Replication
Tagging• Control where data is written to, and read from• Each member can have one or more tags– tags: {dc: "ny"}– tags: {...
{_id : "mySet",members : [{_id : 0, host : "A", tags : {"dc": "ny"}},{_id : 1, host : "B", tags : {"dc": "ny"}},{_id : 2, ...
Wait for Replication (Tagging)
Read Preference Modes• 5 modes– primary (only) - Default– primaryPreferred– secondary– secondaryPreferred– NearestWhen mor...
OperationalConsiderations
Maintenance and Upgrade• No downtime• Rolling upgrade/maintenance– Start with Secondary– Primary last
Replica Set – 1 Data Center• Single datacenter• Single switch & power• Points of failure:– Power– Network– Data center– Tw...
Replica Set – 2 Data Centers• Multi data center• DR node for safety• Can’t do multi datacenter durable writesafely since o...
Replica Set – 3 Data Centers• Three data centers• Can survive full datacenter loss• Can do w= { dc : 2 } toguarantee write...
Recent improvements• Read preference support with sharding– Drivers too• Improved replication over WAN/high-latencynetwork...
Just Use It• Use replica sets• Easy to setup– Try on a single machine• Check doc page for RS tutorials– http://docs.mongod...
Internal Tools, 10genJ. Randall Hunt#MongoDBDaysThank You
Next Sessions at 12:405th Floor:West Side Ballroom 3&4: Indexing and Query OptimizationWest Side Ballroom 1&2: Text Search...
Basic Replication in MongoDB
Basic Replication in MongoDB
Upcoming SlideShare
Loading in …5
×

Basic Replication in MongoDB

2,232 views

Published on

Published in: Technology, Business
  • Be the first to comment

Basic Replication in MongoDB

  1. 1. Internal Tools, 10genJ. Randall Hunt#MongoDBDaysIntroduction to Replicationand Replica Sets
  2. 2. Agenda• Replica Sets Lifecycle• Developing with Replica Sets• Operational Considerations
  3. 3. Why Replication?• How many have faced node failures?• How many have been woken up from sleep todo a fail-over(s)?• How many have experienced issues due tonetwork latency?• Different uses for data– Normal processing– Simple analytics
  4. 4. Replica Set Lifecycle
  5. 5. Replica Set – Creation
  6. 6. Replica Set – Initialize
  7. 7. Replica Set – Failure
  8. 8. Replica Set – Failover
  9. 9. Replica Set – Recovery
  10. 10. Replica Set – Recovered
  11. 11. Replica Set Roles &Configuration
  12. 12. Replica Set Roles
  13. 13. > 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
  14. 14. > 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 OptionsPrimary DC
  15. 15. > 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 OptionsSecondary DCDefault Priority = 1
  16. 16. > 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 OptionsAnalyticsnode
  17. 17. > 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 OptionsBackup node
  18. 18. Developing with ReplicaSets
  19. 19. Strong Consistency
  20. 20. Delayed Consistency
  21. 21. Write Concern• Network acknowledgement• Wait for error• Wait for journal sync• Wait for replication
  22. 22. Unacknowledged
  23. 23. MongoDB Acknowledged (wait forerror)
  24. 24. Wait for Journal Sync
  25. 25. Wait for Replication
  26. 26. 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
  27. 27. {_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
  28. 28. Wait for Replication (Tagging)
  29. 29. Read Preference Modes• 5 modes– primary (only) - Default– primaryPreferred– secondary– secondaryPreferred– NearestWhen more than one node is possible, closest node is usedfor reads (all modes but primary)
  30. 30. OperationalConsiderations
  31. 31. Maintenance and Upgrade• No downtime• Rolling upgrade/maintenance– Start with Secondary– Primary last
  32. 32. Replica Set – 1 Data Center• Single datacenter• Single switch & power• Points of failure:– Power– Network– Data center– Two node failure• Automatic recovery ofsingle node crash
  33. 33. Replica Set – 2 Data Centers• Multi data center• DR node for safety• Can’t do multi datacenter durable writesafely since only 1node in distant DC
  34. 34. Replica Set – 3 Data Centers• Three data centers• Can survive full datacenter loss• Can do w= { dc : 2 } toguarantee write in 2data centers (with tags)
  35. 35. Recent improvements• Read preference support with sharding– Drivers too• Improved replication over WAN/high-latencynetworks• rs.syncFrom command• buildIndexes setting• replIndexPrefetch setting
  36. 36. 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
  37. 37. Internal Tools, 10genJ. Randall Hunt#MongoDBDaysThank You
  38. 38. Next Sessions at 12:405th Floor:West Side Ballroom 3&4: Indexing and Query OptimizationWest Side Ballroom 1&2: Text Search (Beta)Juilliard Complex: Business Track: Building a Personalized MobileApp Experience Using MongoDB atADPLyceum Complex:Ask the Experts7th Floor:Empire Complex: Scaling MongoDB; Sharding Into and Beyond theMulti-Terabyte RangeSoHo Complex:Automated Slow QueryAnalysis: MongoDB &Hadoop, Sittin in a Tree

×