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

MongoDB Replication

MongoDB Replication

Presented at MongoDB Seattle Sept 2012.

Sridhar Nanjundeswaran

September 14, 2012
Tweet

More Decks by Sridhar Nanjundeswaran

Other Decks in Programming

Transcript

  1. 1
    Sridhar Nanjundeswaran, 10gen
    [email protected]
    @snanjund

    View full-size slide

  2. 2
    • Introduction to Replica Sets
    • Developing with Replica Sets
    • Operational Considerations
    • Miscellaneous

    View full-size slide

  3. Introduction to Replica Sets
    What is it?
    Configuration Options

    View full-size slide

  4. 4
    Node 1 Node 2
    Node 3

    View full-size slide

  5. 5
    Node 1
    Secondary
    Node 2
    Secondary
    Node 3
    Primary
    Replication
    Replication
    Heartbeat

    View full-size slide

  6. 6
    Node 1
    Secondary
    Node 2
    Secondary
    Node 3
    Primary
    Heartbeat
    Primary Election

    View full-size slide

  7. 7
    Node 1
    Secondary
    Node 2
    Primary
    Node 3
    Primary
    Heartbeat
    Replication

    View full-size slide

  8. 8
    Node 1
    Secondary
    Node 2
    Primary
    Node 3
    Secondary
    Replication
    Heartbeat
    Replication

    View full-size slide

  9. 9
    • Priorities
    – Help control election
    – Secondary only
    • Slave Delay
    – Purposely delay replication
    • Hidden
    – Not seen as part client connection
    • Tagging

    View full-size slide

  10. 10
    • New in 2.0.0
    • Control over where data is written to
    • Each member can have one or more tags e.g.
    • tags: {dc: "ny"}
    • tags: {dc: "ny",
 ip: "192.168",
 rack:
    "row3rk7"}
    • Replica set defines rules for where data resides
    • Rules can change without changing app code

    View full-size slide

  11. 11
    {
    _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 : "allDCs"})

    View full-size slide

  12. Developing with Replica Sets
    Consistency
    Write Preference
    Read Preference

    View full-size slide

  13. 13
    Primary
    Secondary
    Secondary
    Read
    Write
    Driver
    Client

    View full-size slide

  14. 14
    Primary
    Read
    Write
    Driver
    Read
    Secondary
    Secondary
    Client Application

    View full-size slide

  15. 15
    • Fire and forget
    • Wait for error
    • Wait for journal sync
    • Wait for replication

    View full-size slide

  16. 16
    Driver Primary
    write
    apply in memory

    View full-size slide

  17. 17
    Driver Primary
    getLastError
    apply in memory

    View full-size slide

  18. 18
    Driver Primary
    getLastError
    apply in memory
    write
    j:true
    Write to journal

    View full-size slide

  19. 19
    Driver Primary
    getLastError
    apply in memory
    write
    w:2
    Secondary
    replicate

    View full-size slide

  20. 20
    • 5 modes
    – primary (only) - Default
    – primaryPreferred
    – secondary
    – secondaryPreferred
    – nearest

    View full-size slide

  21. 21
    • Custom read preferences
    • Control where you read from
    – E.g. { "disk": "ssd", "use": "reporting" }
    • Use in conjunction with standard read
    preferences
    – Except primary

    View full-size slide

  22. Operational Considerations
    Upgrade/Maintenance
    Common Deployment Scenarios

    View full-size slide

  23. 23
    • No downtime
    • Rolling upgrade/maintenance
    – Start with Secondary
    – Primary last

    View full-size slide

  24. 24
    • Single datacenter
    • Single switch & power
    • Points of failure:
    – Power
    – Network
    – Datacenter
    – Two node failure
    • Automatic recovery of
    single node crash
    Member 1
    Member 2
    Member 3

    View full-size slide

  25. 25
    • Multi datacenter
    • DR node for safety
    • Can’t do multi data
    center durable write
    safely since only 1
    node in distant DC
    Member 1
    Member 2
    Member 3
    DC
    1
    DC
    2

    View full-size slide

  26. 26
    • Three data centers
    • Can survive full data
    center loss
    • Can do w= { dc : 2 } to
    guarantee write in 2
    data centers (with
    tags)
    Member 1
    Member 2
    Member 3
    Member 4
    DC
    2
    Member 5 -
    DR
    DC
    1
    DC
    3

    View full-size slide

  27. Miscellaneous
    Behind the scenes
    What’s new in 2.2

    View full-size slide

  28. 28
    • Local DB
    • Oplog
    – Capped collection
    – Idempotent version of operation stored
    db.replsettest.update({},{$inc:{set:1}})
    { "ts" : …, "h" : …, "op" : "u", "ns" : "mongo_la.replsettest", "o2" : { "_id" :
    ObjectId("4f177bc768dad821278224d8") }, "o" : { "$set" : { "set" : 2 } } }

    View full-size slide

  29. 29
    • Full read preference support in mongos
    – Drivers too
    • Improved RS lag logging
    • rs.syncFrom command
    • buildIndexes setting
    • replIndexPrefetch setting

    View full-size slide

  30. 30
    • Use replica sets
    • Easy to setup even on a single machine
    • Check doc page for RS tutorials
    – http://docs.mongodb.org/manual/replication/#t
    utorials

    View full-size slide

  31. 31
    @mongodb
    © Copyright 2010 10gen Inc.
    conferences, appearances, and meetups
    http://www.10gen.com/events
    http://bit.ly/mongofb
    Facebook | Twitter |
    LinkedIn http://linkd.in/joinmongo
    download at mongodb.org
    We’re Hiring !
    [email protected] @snanjund

    View full-size slide