SlideShare a Scribd company logo
1 of 43
Download to read offline
#MongoDBDays - @m4rcsch




Replication and Replica Sets
Marc Schwering
Solutions Architect, 10gen
Notes to the presenter
Themes for this presentation:
•  Balance between cost and redundancy.
•  Cover the many scenarios which replication
   would solve and why.
•  Secret sauce of avoiding downtime & data loss


•  If time is short, skip 'Behind the curtain' section
•  If time is very short, skip Operational
   Considerations also
Agenda
•  Replica Sets Lifecycle
•  Developing with Replica Sets
•  Operational Considerations
Why Replication?
•  How many have faced node failures?
•  How many have been woken up from sleep to do
 a fail-over(s)?
•  How many have experienced issues due to
 network latency?
•  Different uses for data
   –  Normal processing
   –  Simple analytics
ReplicaSet Lifecycle
Node 1            Node 2




                Node 3




Replica Set – Creation
Node 1                             Node 2
       Secondary                         Secondary
                          Heartbeat

           Re




                                           n
                                           tio
              pli




                                        ica
                  cat




                                         pl
                  on  i




                                      Re
                          Node 3
                           Primary




Replica Set – Initialize
Primary Election
       Node 1                         Node 2
       Secondary      Heartbeat       Secondary




                      Node 3




Replica Set – Failure
Replication
       Node 1                    Node 2
       Secondary                 Primary
                   Heartbeat




                   Node 3




Replica Set – Failover
Replication
       Node 1                      Node 2
       Secondary                    Primary
                   Heartbeat




                                        n
                                    tio
                                   ica
                                    pl
                                 Re
                   Node 3
                   Recovery




Replica Set – Recovery
Replication
       Node 1                      Node 2
       Secondary                    Primary
                   Heartbeat




                                        n
                                    tio
                                   ica
                                    pl
                                 Re
                   Node 3
                   Secondary




Replica Set – Recovered
ReplicaSet Roles &
Configuration
Node 1                         Node 2
       Secondary                      Arbiter
                          Heartbeat

           Re
              pli
                  cat
                  on  i

                          Node 3
                           Primary




Replica Set Roles
Configuration Options
> conf = {
        _id : "mySet",
        members : [
            {_id : 0, host : "A”, priority : 3},
            {_id : 1, host : "B", priority : 2},
            {_id : 2, host : "C”},
            {_id : 3, host : "D", hidden : true},
            {_id : 4, host : "E", hidden : true, slaveDelay :
3600}
    ]
}


> rs.initiate(conf)
Configuration Options
> conf = {
        _id : "mySet”,
        members : [                  Primary DC
            {_id : 0, host : "A”, priority : 3},
            {_id : 1, host : "B", priority : 2},
            {_id : 2, host : "C”},
            {_id : 3, host : "D", hidden : true},
            {_id : 4, host : "E", hidden : true, slaveDelay :
3600}
    ]
}


> rs.initiate(conf)
Configuration Options
> conf = {
                                                        Secondary DC
        _id : "mySet”,                              Default Priority = 1
        members : [
            {_id : 0, host : "A”, priority : 3},
            {_id : 1, host : "B", priority : 2},
            {_id : 2, host : "C”},
            {_id : 3, host : "D", hidden : true},
            {_id : 4, host : "E", hidden : true, slaveDelay :
3600}
    ]
}


> rs.initiate(conf)
Configuration Options
> conf = {
        _id : "mySet”,
        members : [
            {_id : 0, host : "A”, priority : 3},     Analytics
            {_id : 1, host : "B", priority : 2},       node
            {_id : 2, host : "C”},
            {_id : 3, host : "D", hidden : true},
            {_id : 4, host : "E", hidden : true, slaveDelay :
3600}
    ]
}


> rs.initiate(conf)
Configuration Options
> conf = {
        _id : "mySet”,
        members : [
            {_id : 0, host : "A”, priority : 3},
            {_id : 1, host : "B", priority : 2},
            {_id : 2, host : "C”},
            {_id : 3, host : "D", hidden : true},
            {_id : 4, host : "E", hidden : true, slaveDelay :
3600}
    ]
}
                                              Backup node

> rs.initiate(conf)
Developing with Replica Sets
Client Application
                        Driver




                    Write




                                 Read
                       Primary



        Secondary                       Secondary



Strong Consistency
Client Application
                    Driver




                        Write
          ad




                                    Re
        Re




                                       ad
                    Primary



       Secondary                Secondary



Delayed Consistency
Write Concern
•  Network acknowledgement
•  Wait for error
•  Wait for journal sync
•  Wait for replication
Driver



           write

 Primary

                   apply in
                    memory




Unacknowledged
Driver




            getLastError
  Primary

            apply in
             memory




MongoDB Acknowledged (wait for error)
Driver




                    getLastError


                                   j:true
            write
  Primary

                    apply in                write to
                     memory                  journal




Wait for Journal Sync
Driver




                     getLastError
             write




                                    w:2
  Primary




                                          replicate
                     apply in
                      memory



 Secondary




Wait for Replication
Tagging
•  Control where data is written to, and read from
•  Each member can have one or more tags
   –  tags: {dc: "ny"}
   –  tags: {dc: "ny",
            subnet: "192.168",
            rack: "row3rk7"}
•  Replica set defines rules for write concerns
•  Rules can change without changing app code
Tagging Example
{
    _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 : "someDCs"})
Driver




                              getLastError


                                             W:allDCs
                     write
  Primary (SF)




                                                        replicate
                             apply in
                              memory


 Secondary (NY)




                                                                    replicate
 Secondary (Cloud)




Wait for Replication (Tagging)
Read Preference Modes
•  5 modes
   –  primary (only) - Default
   –  primaryPreferred
   –  secondary
   –  secondaryPreferred
   –  Nearest

   When more than one node is possible, closest node is used for
   reads (all modes but primary)
Tagged Read Preference
•  Custom read preferences
•  Control where you read from by (node) tags
   –  E.g. { "disk": "ssd", "use": "reporting" }

•  Use in conjunction with standard read preferences
   –  Except primary
Operational Considerations
Maintenance and Upgrade
•  No downtime
•  Rolling upgrade/maintenance
   –  Start with Secondary
   –  Primary last
Replica Set – 1 Data Center
                    •  Single datacenter
      Datacenter
                    •  Single switch & power
      Member 1      •  Points of failure:
                       –  Power
      Member 2         –  Network
                       –  Data center
     Datacenter 2
      Member 3         –  Two node failure

                    •  Automatic recovery of
                     single node crash
Replica Set – 2 Data Centers
                    •  Multi data center
     Datacenter 1
                    •  DR node for safety
      Member 1
                    •  Can’t do multi data
      Member 2       center durable write
                     safely since only 1 node
                     in distant DC
     Datacenter 2

      Member 3
Replica Set – 3 Data Centers
     Datacenter 1   •  Three data centers
      Member 1

      Member 2
                    •  Can survive full data
                     center loss
     Datacenter 2
      Member 3      •  Can do w= { dc : 2 } to
      Member 4       guarantee write in 2
                     data centers (with tags)
     Datacenter 3
      Member 5
Behind the Curtain
Implementation details
•  Heartbeat every 2 seconds
   –  Times out in 10 seconds

•  Local DB (not replicated)
   –  system.replset
   –  oplog.rs
      •  Capped collection
      •  Idempotent version of operation stored
Op(erations) Log is idempotent
> db.replsettest.insert({_id:1,value:1})
{ "ts" : Timestamp(1350539727000, 1), "h" :
NumberLong("6375186941486301201"), "op" : "i", "ns" :
"test.replsettest", "o" : { "_id" : 1, "value" : 1 } }


> db.replsettest.update({_id:1},{$inc:{value:10}})
{ "ts" : Timestamp(1350539786000, 1), "h" :
NumberLong("5484673652472424968"), "op" : "u", "ns" :
"test.replsettest", "o2" : { "_id" : 1 },
 "o" : { "$set" : { "value" : 11 } } }
Single operation can have many
entries
> db.replsettest.update({},{$set:{name : ”foo”}, false,
true})
{ "ts" : Timestamp(1350540395000, 1), "h" :
NumberLong("-4727576249368135876"), "op" : "u", "ns" :
"test.replsettest", "o2" : { "_id" : 2 }, "o" :
{ "$set" : { "name" : "foo" } } }
{ "ts" : Timestamp(1350540395000, 2), "h" :
NumberLong("-7292949613259260138"), "op" : "u", "ns" :
"test.replsettest", "o2" : { "_id" : 3 }, "o" :
{ "$set" : { "name" : "foo" } } }
{ "ts" : Timestamp(1350540395000, 3), "h" :
NumberLong("-1888768148831990635"), "op" : "u", "ns" :
"test.replsettest", "o2" : { "_id" : 1 }, "o" :
{ "$set" : { "name" : "foo" } } }
Recent improvements
•  Read preference support with sharding
   –  Drivers too

•  Improved replication over WAN/high-latency
 networks
•  rs.syncFrom command
•  buildIndexes setting
•  replIndexPrefetch setting
Just Use It
•  Use replica sets
•  Easy to setup
   –  Try on a single machine

•  Check doc page for RS tutorials
   –  http://docs.mongodb.org/manual/replication/#tutorials
#MongoDBDays - @m4rcsch




Thank You
Marc Schwering
Solutions Architect, 10gen

More Related Content

Similar to MongoDB London 2013 - Basic Replication

Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 
2013 london advanced-replication
2013 london advanced-replication2013 london advanced-replication
2013 london advanced-replicationMarc Schwering
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica SetsMongoDB
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica SetsMongoDB
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica setsRandall Hunt
 
Basic Replication in MongoDB
Basic Replication in MongoDBBasic Replication in MongoDB
Basic Replication in MongoDBMongoDB
 
Replication MongoDB Days 2013
Replication MongoDB Days 2013Replication MongoDB Days 2013
Replication MongoDB Days 2013Randall Hunt
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced ReplicationMongoDB
 
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB
 
Mongosv 2011 - Replication
Mongosv 2011 - ReplicationMongosv 2011 - Replication
Mongosv 2011 - ReplicationJared Rosoff
 
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)MongoDB
 
MongoDB Replica Sets
MongoDB Replica SetsMongoDB Replica Sets
MongoDB Replica SetsMongoDB
 
Webinar: Operational Best Practices
Webinar: Operational Best PracticesWebinar: Operational Best Practices
Webinar: Operational Best PracticesMongoDB
 
Playing CTFs for Fun & Profit
Playing CTFs for Fun & ProfitPlaying CTFs for Fun & Profit
Playing CTFs for Fun & Profitimpdefined
 
Advanced Windows Debugging
Advanced Windows DebuggingAdvanced Windows Debugging
Advanced Windows DebuggingBala Subra
 
Replication
ReplicationReplication
ReplicationMongoDB
 
Webinar Back to Basics 3 - Introduzione ai Replica Set
Webinar Back to Basics 3 - Introduzione ai Replica SetWebinar Back to Basics 3 - Introduzione ai Replica Set
Webinar Back to Basics 3 - Introduzione ai Replica SetMongoDB
 
Planning for Debugging
Planning for DebuggingPlanning for Debugging
Planning for Debugginglokku
 
Dynomite at Erlang Factory
Dynomite at Erlang FactoryDynomite at Erlang Factory
Dynomite at Erlang Factorymoonpolysoft
 

Similar to MongoDB London 2013 - Basic Replication (20)

Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
2013 london advanced-replication
2013 london advanced-replication2013 london advanced-replication
2013 london advanced-replication
 
Replication and Replica Sets
Replication and Replica SetsReplication and Replica Sets
Replication and Replica Sets
 
Webinar: Replication and Replica Sets
Webinar: Replication and Replica SetsWebinar: Replication and Replica Sets
Webinar: Replication and Replica Sets
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica sets
 
Basic Replication in MongoDB
Basic Replication in MongoDBBasic Replication in MongoDB
Basic Replication in MongoDB
 
Replication MongoDB Days 2013
Replication MongoDB Days 2013Replication MongoDB Days 2013
Replication MongoDB Days 2013
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
 
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
 
Mongosv 2011 - Replication
Mongosv 2011 - ReplicationMongosv 2011 - Replication
Mongosv 2011 - Replication
 
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)
 
MongoDB Replica Sets
MongoDB Replica SetsMongoDB Replica Sets
MongoDB Replica Sets
 
Webinar: Operational Best Practices
Webinar: Operational Best PracticesWebinar: Operational Best Practices
Webinar: Operational Best Practices
 
Playing CTFs for Fun & Profit
Playing CTFs for Fun & ProfitPlaying CTFs for Fun & Profit
Playing CTFs for Fun & Profit
 
Advanced Windows Debugging
Advanced Windows DebuggingAdvanced Windows Debugging
Advanced Windows Debugging
 
Replication
ReplicationReplication
Replication
 
Webinar Back to Basics 3 - Introduzione ai Replica Set
Webinar Back to Basics 3 - Introduzione ai Replica SetWebinar Back to Basics 3 - Introduzione ai Replica Set
Webinar Back to Basics 3 - Introduzione ai Replica Set
 
Planning for Debugging
Planning for DebuggingPlanning for Debugging
Planning for Debugging
 
Dynomite at Erlang Factory
Dynomite at Erlang FactoryDynomite at Erlang Factory
Dynomite at Erlang Factory
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

MongoDB London 2013 - Basic Replication

  • 1. #MongoDBDays - @m4rcsch Replication and Replica Sets Marc Schwering Solutions Architect, 10gen
  • 2. Notes to the presenter Themes for this presentation: •  Balance between cost and redundancy. •  Cover the many scenarios which replication would solve and why. •  Secret sauce of avoiding downtime & data loss •  If time is short, skip 'Behind the curtain' section •  If time is very short, skip Operational Considerations also
  • 3. Agenda •  Replica Sets Lifecycle •  Developing with Replica Sets •  Operational Considerations
  • 4. Why Replication? •  How many have faced node failures? •  How many have been woken up from sleep to do a fail-over(s)? •  How many have experienced issues due to network latency? •  Different uses for data –  Normal processing –  Simple analytics
  • 6. Node 1 Node 2 Node 3 Replica Set – Creation
  • 7. Node 1 Node 2 Secondary Secondary Heartbeat Re n tio pli ica cat pl on i Re Node 3 Primary Replica Set – Initialize
  • 8. Primary Election Node 1 Node 2 Secondary Heartbeat Secondary Node 3 Replica Set – Failure
  • 9. Replication Node 1 Node 2 Secondary Primary Heartbeat Node 3 Replica Set – Failover
  • 10. Replication Node 1 Node 2 Secondary Primary Heartbeat n tio ica pl Re Node 3 Recovery Replica Set – Recovery
  • 11. Replication Node 1 Node 2 Secondary Primary Heartbeat n tio ica pl Re Node 3 Secondary Replica Set – Recovered
  • 13. Node 1 Node 2 Secondary Arbiter Heartbeat Re pli cat on i Node 3 Primary Replica Set Roles
  • 14. Configuration Options > conf = { _id : "mySet", members : [ {_id : 0, host : "A”, priority : 3}, {_id : 1, host : "B", priority : 2}, {_id : 2, host : "C”}, {_id : 3, host : "D", hidden : true}, {_id : 4, host : "E", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf)
  • 15. Configuration Options > conf = { _id : "mySet”, members : [ Primary DC {_id : 0, host : "A”, priority : 3}, {_id : 1, host : "B", priority : 2}, {_id : 2, host : "C”}, {_id : 3, host : "D", hidden : true}, {_id : 4, host : "E", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf)
  • 16. Configuration Options > conf = { Secondary DC _id : "mySet”, Default Priority = 1 members : [ {_id : 0, host : "A”, priority : 3}, {_id : 1, host : "B", priority : 2}, {_id : 2, host : "C”}, {_id : 3, host : "D", hidden : true}, {_id : 4, host : "E", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf)
  • 17. Configuration Options > conf = { _id : "mySet”, members : [ {_id : 0, host : "A”, priority : 3}, Analytics {_id : 1, host : "B", priority : 2}, node {_id : 2, host : "C”}, {_id : 3, host : "D", hidden : true}, {_id : 4, host : "E", hidden : true, slaveDelay : 3600} ] } > rs.initiate(conf)
  • 18. Configuration Options > conf = { _id : "mySet”, members : [ {_id : 0, host : "A”, priority : 3}, {_id : 1, host : "B", priority : 2}, {_id : 2, host : "C”}, {_id : 3, host : "D", hidden : true}, {_id : 4, host : "E", hidden : true, slaveDelay : 3600} ] } Backup node > rs.initiate(conf)
  • 20. Client Application Driver Write Read Primary Secondary Secondary Strong Consistency
  • 21. Client Application Driver Write ad Re Re ad Primary Secondary Secondary Delayed Consistency
  • 22. Write Concern •  Network acknowledgement •  Wait for error •  Wait for journal sync •  Wait for replication
  • 23. Driver write Primary apply in memory Unacknowledged
  • 24. Driver getLastError Primary apply in memory MongoDB Acknowledged (wait for error)
  • 25. Driver getLastError j:true write Primary apply in write to memory journal Wait for Journal Sync
  • 26. Driver getLastError write w:2 Primary replicate apply in memory Secondary Wait for Replication
  • 27. Tagging •  Control where data is written to, and read from •  Each member can have one or more tags –  tags: {dc: "ny"} –  tags: {dc: "ny", subnet: "192.168", rack: "row3rk7"} •  Replica set defines rules for write concerns •  Rules can change without changing app code
  • 28. Tagging Example { _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 : "someDCs"})
  • 29. Driver getLastError W:allDCs write Primary (SF) replicate apply in memory Secondary (NY) replicate Secondary (Cloud) Wait for Replication (Tagging)
  • 30. Read Preference Modes •  5 modes –  primary (only) - Default –  primaryPreferred –  secondary –  secondaryPreferred –  Nearest When more than one node is possible, closest node is used for reads (all modes but primary)
  • 31. Tagged Read Preference •  Custom read preferences •  Control where you read from by (node) tags –  E.g. { "disk": "ssd", "use": "reporting" } •  Use in conjunction with standard read preferences –  Except primary
  • 33. Maintenance and Upgrade •  No downtime •  Rolling upgrade/maintenance –  Start with Secondary –  Primary last
  • 34. Replica Set – 1 Data Center •  Single datacenter Datacenter •  Single switch & power Member 1 •  Points of failure: –  Power Member 2 –  Network –  Data center Datacenter 2 Member 3 –  Two node failure •  Automatic recovery of single node crash
  • 35. Replica Set – 2 Data Centers •  Multi data center Datacenter 1 •  DR node for safety Member 1 •  Can’t do multi data Member 2 center durable write safely since only 1 node in distant DC Datacenter 2 Member 3
  • 36. Replica Set – 3 Data Centers Datacenter 1 •  Three data centers Member 1 Member 2 •  Can survive full data center loss Datacenter 2 Member 3 •  Can do w= { dc : 2 } to Member 4 guarantee write in 2 data centers (with tags) Datacenter 3 Member 5
  • 38. Implementation details •  Heartbeat every 2 seconds –  Times out in 10 seconds •  Local DB (not replicated) –  system.replset –  oplog.rs •  Capped collection •  Idempotent version of operation stored
  • 39. Op(erations) Log is idempotent > db.replsettest.insert({_id:1,value:1}) { "ts" : Timestamp(1350539727000, 1), "h" : NumberLong("6375186941486301201"), "op" : "i", "ns" : "test.replsettest", "o" : { "_id" : 1, "value" : 1 } } > db.replsettest.update({_id:1},{$inc:{value:10}}) { "ts" : Timestamp(1350539786000, 1), "h" : NumberLong("5484673652472424968"), "op" : "u", "ns" : "test.replsettest", "o2" : { "_id" : 1 }, "o" : { "$set" : { "value" : 11 } } }
  • 40. Single operation can have many entries > db.replsettest.update({},{$set:{name : ”foo”}, false, true}) { "ts" : Timestamp(1350540395000, 1), "h" : NumberLong("-4727576249368135876"), "op" : "u", "ns" : "test.replsettest", "o2" : { "_id" : 2 }, "o" : { "$set" : { "name" : "foo" } } } { "ts" : Timestamp(1350540395000, 2), "h" : NumberLong("-7292949613259260138"), "op" : "u", "ns" : "test.replsettest", "o2" : { "_id" : 3 }, "o" : { "$set" : { "name" : "foo" } } } { "ts" : Timestamp(1350540395000, 3), "h" : NumberLong("-1888768148831990635"), "op" : "u", "ns" : "test.replsettest", "o2" : { "_id" : 1 }, "o" : { "$set" : { "name" : "foo" } } }
  • 41. Recent improvements •  Read preference support with sharding –  Drivers too •  Improved replication over WAN/high-latency networks •  rs.syncFrom command •  buildIndexes setting •  replIndexPrefetch setting
  • 42. Just Use It •  Use replica sets •  Easy to setup –  Try on a single machine •  Check doc page for RS tutorials –  http://docs.mongodb.org/manual/replication/#tutorials
  • 43. #MongoDBDays - @m4rcsch Thank You Marc Schwering Solutions Architect, 10gen