Replication and MongoDB<br />Dwight Merriman (@dmerr)<br />10gen<br />
Basics<br />A bit like MySQL replication<br />Asynchronous master/slave<br />Let’s try it…<br />
Command Line<br />--master [--oplogSize <MB>]<br />--slave –source <host> [--only <db>]<br />
The local db<br />Doesn’t replicate<br />On master:<br />local.oplog.$main<br />local.slaves<br />On slave:<br />local.sou...
Administration<br />> // master<br />> use local<br />> db.printReplicationInfo()<br />> db.slaves.find()<br />> db.oplog....
Topologies<br />M->S<br />M->S<br /> ->S<br /> ->S<br />M->S<br />M-/<br />M<->M *very restrictive<br />
Replica Pairs<br />--pairwith<br />
Replica Pairs<br />Replica Sets<br /><ul><li> A cluster of N servers
 Any (one) node can be primary
 Consensus election of primary
 Automatic failover
 Automatic recovery
 All writes to primary
 Reads can be to primary or a second
 Rack and data center aware
 ETA: v1.6 July 2010 (“stable”)</li></li></ul><li>Replica Sets – Design Concepts<br />A write is only truly committed once...
A Set<br />Member 1<br />Member 3<br />Member 2<br />
A Set<br />Member 1<br />Member 3<br />Member 2<br />PRIMARY<br />
A Set<br />Member 1<br />Member 3<br />PRIMARY<br />Member 2<br />DOWN<br />
A Set<br />Member 1<br />Member 3<br />PRIMARY<br />Member 2<br />RECOVER-ING<br />
Upcoming SlideShare
Loading in...5
×

MongoDB Replication (Dwight Merriman)

7,194

Published on

Published in: Technology
1 Comment
19 Likes
Statistics
Notes
No Downloads
Views
Total Views
7,194
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
177
Comments
1
Likes
19
Embeds 0
No embeds

No notes for slide

MongoDB Replication (Dwight Merriman)

  1. 1. Replication and MongoDB<br />Dwight Merriman (@dmerr)<br />10gen<br />
  2. 2. Basics<br />A bit like MySQL replication<br />Asynchronous master/slave<br />Let’s try it…<br />
  3. 3. Command Line<br />--master [--oplogSize <MB>]<br />--slave –source <host> [--only <db>]<br />
  4. 4. The local db<br />Doesn’t replicate<br />On master:<br />local.oplog.$main<br />local.slaves<br />On slave:<br />local.sources<br /> > use local<br /> > db.sources.find()<br />
  5. 5. Administration<br />> // master<br />> use local<br />> db.printReplicationInfo()<br />> db.slaves.find()<br />> db.oplog.$main.findOne()<br />// slave<br />> use local<br />> db.printSlaveReplicationInfo()<br />
  6. 6. Topologies<br />M->S<br />M->S<br /> ->S<br /> ->S<br />M->S<br />M-/<br />M<->M *very restrictive<br />
  7. 7. Replica Pairs<br />--pairwith<br />
  8. 8. Replica Pairs<br />Replica Sets<br /><ul><li> A cluster of N servers
  9. 9. Any (one) node can be primary
  10. 10. Consensus election of primary
  11. 11. Automatic failover
  12. 12. Automatic recovery
  13. 13. All writes to primary
  14. 14. Reads can be to primary or a second
  15. 15. Rack and data center aware
  16. 16. ETA: v1.6 July 2010 (“stable”)</li></li></ul><li>Replica Sets – Design Concepts<br />A write is only truly committed once it has replicated to a majority of servers in the set.  (We can wait for confirmation for this though, with getLastError.)<br />Writes which are committed at the master of the set may be visible before the true cluster-wide commit has occurred.  This property, which is more relaxed than some traditional products, makes theoretically achievable performance and availability higher.<br />On a failover, if there is data which has not replicated form the primary, the data is dropped (see #1).<br />
  17. 17. A Set<br />Member 1<br />Member 3<br />Member 2<br />
  18. 18. A Set<br />Member 1<br />Member 3<br />Member 2<br />PRIMARY<br />
  19. 19. A Set<br />Member 1<br />Member 3<br />PRIMARY<br />Member 2<br />DOWN<br />
  20. 20. A Set<br />Member 1<br />Member 3<br />PRIMARY<br />Member 2<br />RECOVER-ING<br />
  21. 21. A Set<br />Member 1<br />Member 3<br />PRIMARY<br />Member 2<br />
  22. 22. Configuration<br />{<br /> _id : <setname>,<br /> members: [<br /> {<br /> _id : <ordinal>,<br /> host : <hostname[:port]>,<br /> [, priority: <priority>]<br /> [, arbiterOnly : true]<br /> [, votes : n]<br /> }<br /> , ...<br /> ],<br /> settings: {<br /> [heartbeatSleep : <seconds>]<br /> [, heartbeatTimeout : <seconds>]<br /> [, heartbeatConnRetries : <n>]<br /> [, getLastErrorDefaults: <lasterrdefaults>]<br /> }<br />}<br />
  23. 23. Initiation<br />> cfg = {<br />... _id : "acme_a",<br />... members : [<br />... { _id : 0, host : "sf1.acme.com" },<br />... { _id : 1, host : "sf2.acme.com" },<br />... { _id : 2, host : "sf3.acme.com" } ] }<br />> use admin<br />> db.runCommand({replSetInitiate:cfg})<br />
  24. 24. Commands<br />{ isMaster : 1 }<br /> Checks if the node to which we are connecting is currently primary. Most drivers do this check automatically and then send requires to the current primary.<br />{ replSetGetStatus : 1 }<br /> Status information on the replica set from this node's point of view.<br />http://localhost:28017/replSetGetStatus?text<br />{ replSetInitiate : <config> }<br /> Initiate a replica set. <br />{ replSetFreeze : <bool> }<br /> Freezing a replica set prevents failovers from occurring. This can be useful during maintenance.<br />
  25. 25. Set Member Types<br />Normal<br />DR (priority < 1.0)<br />Passive (priority == 0)<br />Arbiter (no data, but can vote)<br />
  26. 26. With Sharding<br />
  27. 27. Docs: http://www.mongodb.org/display/DOCS/Replica+Sets<br />Questions?<br />Email dwight@10gen.com if you would like <br />to be a replica set beta tester.<br />10gen is hiring.<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×