MongoDB Replica Sets

15,743 views

Published on

10gen CEO Dwight Merriman presents at the NoSQL meetup in NYC

Published in: Technology
  • Be the first to comment

MongoDB Replica Sets

  1. 1. Replica Sets (MongoDB v1.6) Dwight Merriman (@dmerr) 10gen dmerr.tumblr.com
  2. 2. Basics <ul><li>MongoDB replication is a bit like MySQL replication </li></ul><ul><ul><li>Asynchronous master/slave at its core </li></ul></ul><ul><li>Variations: </li></ul><ul><ul><li>Master / slave </li></ul></ul><ul><ul><li>Replica Pairs (deprecated – use replica sets) </li></ul></ul><ul><ul><li>Replica Sets (today’s topic) </li></ul></ul>
  3. 3. Replica Sets <ul><li>A cluster of N servers </li></ul><ul><li>Any (one) node can be primary </li></ul><ul><li>Consensus election of primary </li></ul><ul><li>Automatic failover </li></ul><ul><li>Automatic recovery </li></ul><ul><li>All writes to primary </li></ul><ul><li>Reads can be to primary (default) or a secondary </li></ul><ul><li>v1.6 </li></ul>
  4. 4. With Sharding
  5. 5. Replica Sets – Design Concepts <ul><li>A write is only truly committed once it has replicated to a majority of servers in the set.  </li></ul><ul><ul><ul><li>Thus, for important writes, the developer waits for confirmation of the cluster-wide commit with the getLastError command. </li></ul></ul></ul><ul><li>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. </li></ul><ul><li>On a failover, if there is data which has not replicated form the primary, the data is dropped (see #1). </li></ul>
  6. 6. A Set Member 1 Member 2 Member 3
  7. 7. A Set Member 1 Member 2 PRIMARY Member 3
  8. 8. A Set Member 1 Member 2 DOWN Member 3 PRIMARY negotiate new master
  9. 9. A Set Member 1 Member 2 DOWN Member 3 PRIMARY
  10. 10. A Set Member 1 Member 2 RECOVER-ING Member 3 PRIMARY
  11. 11. A Set Member 1 Member 2 Member 3 PRIMARY
  12. 12. Configuration <ul><li>{ </li></ul><ul><li>_id : <setname>, </li></ul><ul><li>members: [ </li></ul><ul><li>{ </li></ul><ul><li>_id : <ordinal>, </li></ul><ul><li>host : <hostname[:port]>, </li></ul><ul><li>[, priority: <priority>] </li></ul><ul><li>[, arbiterOnly : true] </li></ul><ul><li>[, votes : n] </li></ul><ul><li> [, slaveDelay : s] [, hidden : true ] </li></ul><ul><li>} </li></ul><ul><li>, ... </li></ul><ul><li>], </li></ul><ul><li>settings: { </li></ul><ul><li>[getLastErrorDefaults: <lasterrdefaults>] </li></ul><ul><li>[, heartbeatSleep : <seconds>] </li></ul><ul><li>[, heartbeatTimeout : <seconds>] </li></ul><ul><li>[, heartbeatConnRetries : <n>] </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  13. 13. Initiation <ul><li>> cfg = { </li></ul><ul><li>... _id : &quot;acme_a&quot;, </li></ul><ul><li>... members : [ </li></ul><ul><li>... { _id : 0, host : &quot;sf1.acme.com&quot; }, </li></ul><ul><li>... { _id : 1, host : &quot;sf2.acme.com&quot; }, </li></ul><ul><li>... { _id : 2, host : &quot;sf3.acme.com&quot; } ] } </li></ul><ul><li>> use admin </li></ul><ul><li>> db.runCommand({replSetInitiate:cfg}) </li></ul>
  14. 14. Set Member Types <ul><li>Normal (priority == 1) </li></ul><ul><li>Passive (priority == 0) </li></ul><ul><li>DR (priority < 1.0) (coming soon) </li></ul><ul><li>Arbiter (no data, but can vote) </li></ul>
  15. 15. Commands <ul><li>{ isMaster : 1 } </li></ul><ul><li>{ replSetGetStatus : 1 } </li></ul><ul><li>{ replSetInitiate : <config> } </li></ul><ul><li>{ replSetStepDown : true } </li></ul><ul><li>{ replSetReconfig : <config> } </li></ul><ul><li>> rs.help() </li></ul>
  16. 16. Demo
  17. 17. Questions? <ul><li>Contact 10gen for on-site advisory sessions on MongoDB architecture, schema design, performance tuning, training… </li></ul><ul><li>[email_address] </li></ul><ul><li>irc://irc.freenode.net/#mongodb </li></ul><ul><li>http://groups.google.com/group/mongodb-user </li></ul>

×