$30 off During Our Annual Pro Sale. View Details »

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).

Viktor Petersson

August 30, 2012
Tweet

More Decks by Viktor Petersson

Other Decks in Technology

Transcript

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

    View Slide

  2. Who am I?
    {
    name : ‘Viktor Petersson’,
    description : [ ‘geek’, ‘entrepreneur’ ],
    founder_of : ‘wireload’,
    twitter : ‘@vpetersson’,
    email : ‘[email protected]’,
    }
    @vpetersson

    View Slide

  3. What is MongoDB?
    @vpetersson
    • Key-value store
    • Schemas less
    • Distributed file system (GridFS)
    • Built-in Map/Reduce
    • Built to scale

    View Slide

  4. MongoDB 101
    Relational Database MongoDB
    Database Database
    Table Collection
    Row Document
    Database structure (simplified)
    @vpetersson

    View Slide

  5. MongoDB 101
    Relational Database MongoDB
    Master Primary
    Slave Secondary
    Arbiter
    (Hidden)
    Node types
    @vpetersson

    View Slide

  6. What are Replica Sets and
    why should I care?
    @vpetersson

    View Slide

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

    View Slide

  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)

    View Slide

  9. Failover with MongoDB
    Primary Secondary
    Normal Degraded
    Secondary
    Driver
    Primary Secondary Secondary
    Driver
    Primary
    @vpetersson
    (three servers, can lose two)

    View Slide

  10. Primary Secondary
    Down -> Recovering Recovering -> Secondary
    Secondary
    Driver
    Primary Secondary Secondary
    Driver
    Primary
    Secondary
    Primary
    Recovering
    Automatic recovery
    @vpetersson

    View Slide

  11. Real life example:
    Taking down the primary for maintenance.
    No dropped connections.
    Primary Secondary
    @vpetersson

    View Slide

  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

    View Slide

  13. Live demo!
    3 servers with 1 client
    @vpetersson

    View Slide

  14. Election
    @vpetersson
    1. Most up to date
    2. Highest priority
    3. Less than 10s behind Primary

    View Slide

  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

    View Slide

  16. Leverage your secondary-nodes
    Warning: Secondaries may be out-of-date.
    Read preference
    • Primary (default)
    • Secondary
    • Secondary_only
    @vpetersson

    View Slide

  17. What happens when I’ve
    outgrown my Replica Set?
    @vpetersson

    View Slide

  18. @vpetersson
    mongos
    repset0 repset1 repsetN
    Sharding

    View Slide

  19. Useful commands
    View server status
    $ db.serverStatus()
    View the replication status
    $ rs.status()
    Step down as Primary
    $ rs.stepDown(n)
    @vpetersson

    View Slide

  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)

    View Slide

  21. Summary
    @vpetersson
    • Replica Sets are extremely easy to set up
    • Doesn’t require failover IPs or custom scripts
    • Minimal maintenance
    • Built to scale

    View Slide

  22. Questions?
    @vpetersson

    View Slide

  23. Thanks to
    @vpetersson

    View Slide

  24. Contact me!
    email: [email protected]
    www: viktorpetersson.com
    twitter: @vpetersson
    Also visit
    WireLoad.net
    YippieMove.com
    @vpetersson
    This deck will be available at ViktorPetersson.com.

    View Slide

  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

    View Slide