Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MongoDB's Replica Sets - Painless scaling and High Availability (HA)

MongoDB's Replica Sets - Painless scaling and High Availability (HA)

Presentation for NoSQL Roadshow (Basel, Switzerland).

C770b64f01d6b9360b59e8470c2754f4?s=128

Viktor Petersson

August 30, 2012
Tweet

Transcript

  1. Replica Sets Painless scaling and High Availability (HA) Viktor Petersson

    @vpetersson
  2. Who am I? { name : ‘Viktor Petersson’, description :

    [ ‘geek’, ‘entrepreneur’ ], founder_of : ‘wireload’, twitter : ‘@vpetersson’, email : ‘vpetersson@wireload.net’, } @vpetersson
  3. What is MongoDB? @vpetersson • Key-value store • Schemas less

    • Distributed file system (GridFS) • Built-in Map/Reduce • Built to scale
  4. MongoDB 101 Relational Database MongoDB Database Database Table Collection Row

    Document Database structure (simplified) @vpetersson
  5. MongoDB 101 Relational Database MongoDB Master Primary Slave Secondary Arbiter

    (Hidden) Node types @vpetersson
  6. What are Replica Sets and why should I care? @vpetersson

  7. Typical failover with relational databases Master Slave Failover IP Master

    Slave Failover IP Master Normal Degraded @vpetersson (two servers, can lose one)
  8. More complex failover with relational databases Failover IP Normal @vpetersson

    Proxies Database servers Failover IP Degraded (four servers, can lose one of each kind)
  9. Failover with MongoDB Primary Secondary Normal Degraded Secondary Driver Primary

    Secondary Secondary Driver Primary @vpetersson (three servers, can lose two)
  10. Primary Secondary Down -> Recovering Recovering -> Secondary Secondary Driver

    Primary Secondary Secondary Driver Primary Secondary Primary Recovering Automatic recovery @vpetersson
  11. Real life example: Taking down the primary for maintenance. No

    dropped connections. Primary Secondary @vpetersson
  12. Creating a Replica Set is dead simple. All it takes

    is three servers (s0, s1, s2) and three commands¹. $ mongo > rs.initiate() > rs.add(‘s1’) > rs.add(‘s2’) 1. After adding “replSet=myRepSet” and “rest = true” to mongo.conf @vpetersson
  13. Live demo! 3 servers with 1 client @vpetersson

  14. Election @vpetersson 1. Most up to date 2. Highest priority

    3. Less than 10s behind Primary
  15. Configure node priority $ cfg = rs.conf() $ cfg.members[x].priority =

    n $ rs.reconfig(cfg) x = Member id, n = Priority (0 - 100), default is 1. @vpetersson
  16. Leverage your secondary-nodes Warning: Secondaries may be out-of-date. Read preference

    • Primary (default) • Secondary • Secondary_only @vpetersson
  17. What happens when I’ve outgrown my Replica Set? @vpetersson

  18. @vpetersson mongos repset0 repset1 repsetN Sharding

  19. Useful commands View server status $ db.serverStatus() View the replication

    status $ rs.status() Step down as Primary $ rs.stepDown(n) @vpetersson
  20. • Improved location awareness • Improved concurrent capacity • TTL

    collections @vpetersson What’s new in MongoDB 2.2? Full release notes: http://docs.mongodb.org/manual/release-notes/2.2/ (released yesterday)
  21. Summary @vpetersson • Replica Sets are extremely easy to set

    up • Doesn’t require failover IPs or custom scripts • Minimal maintenance • Built to scale
  22. Questions? @vpetersson

  23. Thanks to @vpetersson

  24. Contact me! email: info@viktorpetersson.com www: viktorpetersson.com twitter: @vpetersson Also visit

    WireLoad.net YippieMove.com @vpetersson This deck will be available at ViktorPetersson.com.
  25. • MongoDB: GridFS, sharding and deploying in the cloud (http://goo.gl/1QAV1)

    • MongoDB Replica Set (http://goo.gl/D2pkq) • 10gen (http://goo.gl/3m4Kn) @vpetersson Useful resources