SlideShare a Scribd company logo
#MongoDBDays - @m4rcsch




Advanced Replication
Marc Schwering
Solutions Architect, 10gen
Roles & Configuration
Replica Set Roles
Configuration Options
> conf = {
    _id : "mySet",
    members : [
        {_id : 0, host : "A"},
        {_id : 1, host : "B"},
        {_id : 2, host : "C", "arbiter" : true}
    ]
}


> rs.initiate(conf)
Simple Setup Demo
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
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 } } }
oplog and multi-updates
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" } } }
Operations
Maintenance and Upgrade
• No downtime
• Rolling upgrade/maintenance
  – Start with Secondary
  – Primary last

  – Commands:
     • rs.stepDown(<secs>)
     • db.version()
     • db.serverBuildInfo()
Upgrade Demo
Replica Set – 1 Data Center
                • Single datacenter
                • Single switch & power
                • Points of failure:
                   –   Power
                   –   Network
                   –   Data center
                   –   Two node failure
                • Automatic recovery of
                 single node crash
Replica Set – 2 Data Centers
               • Multi data center
               • DR node for safety
               • Can’t do multi data
                 center durable write
                 safely since only 1
                 node in distant DC
Replica Set – 2 Data Centers
                            • Analytics
                            • Disaster Recovery
                            • Batch Jobs



 • Options
   – low or zero priority
   – hidden
   – slaveDelay
Replica Set – 3 Data Centers
               • Three data centers
               • Can survive full data
                 center loss
               • Can do w= { dc : 2 } to
                 guarantee write in 2
                 data centers (with tags)
Replica Set – 3+ Data Centers

                            Secondary

                             Primary

                                        Secondary
                                                    Secondary
    Secondary                            delayed




                Secondary

                                                      Secondary
Commands
• Managing
   – rs.conf()
   – rs.initiate(<conf>) & rs.reconfig(<conf>)
   – rs.add(host:<port>) & rs.addArb(host:<port>)
   – rs.status()
   – rs.stepDown(<secs>)

• Minority reconfig
   – rs.reconfig( cfg, { force : true} )
Options
• Priorities
• Hidden
• Slave Delay
• Disable indexes (on secondaries)
• Default write concerns
Developing with Replica
Sets
Strong Consistency
Delayed Consistency
Write Concern
• Network acknowledgement
• Wait for error
• Wait for journal sync
• Wait for replication
   – number
   – majority
   – Tags
Write Concern Demo
Datacenter awareness (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"})
> db.getLastErrorObj({"someDCs"})
Wait for Replication
Write Concern with timeout
settings : {
     getLastErrorModes : {
        allDCs : {"dc" : 3},
        someDCs : {"dc" : 2}} }
}
> db.getLastErrorObj({"allDCs"},100);
> db.getLastErrorObj({”someDCs"},500);
> db.getLastErrorObj(1,500);
Read Preference Modes
• 5 modes (new in 2.2)
  –   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
Tags

{"dc.va": "rack1", disk:"ssd", ssd: "installed" }
{"dc.va": "rack2", disk:"raid"}
{"dc.gto": "rack1", disk:"ssd", ssd: "installed" }
{"dc.gto": "rack2", disk:"raid”}


> conf.settings = { getLastErrorModes: { MultipleDC : { "dc.va":
1, "dc.gto": 1}}


> conf.settings = {
           "getLastErrorModes" : {
                   "ssd" : {
                           "ssd" : 1
                   },...
Tagged Read Preference
{ disk: "ssd" }


JAVA:
ReadPreference tagged_pref =
  ReadPreference.secondaryPreferred(
       new BasicDBObject("disk", "ssd")
  );


DBObject result =
  coll.findOne(query, null, tagged_pref);
Tagged Read Preference
• Grouping / Failover
 {dc : "LON", loc : "EU"}
 {dc : "FRA", loc : "EU"}
 {dc : "NY", loc : "US”}
 DBObject t1 = new BasicDBObject("dc", "LON");
 DBObject t2 = new BasicDBObject("loc", "EU");


 ReadPreference pref =
   ReadPreference.primaryPreferred(t1, t2);
Conclusion
Best practices and tips
• Odd number of set members
• Read from the primary except for
   – Geographically distribution
   – Analytics (separate workload)

• Use logical names not IP Addresses in configs
• Set WriteConcern appropriately for what you are
 doing
• Monitor secondaries for lag (Alerts in MMS)
#MongoDBDays - @m4rcsch




Thank You
Marc Schwering
Solutions Architect, 10gen

More Related Content

PDF
MongoDB Database Replication
PDF
Setting up mongo replica set
PDF
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
PDF
MongoDb scalability and high availability with Replica-Set
PPT
Replica Sets (NYC NoSQL Meetup)
PDF
Haproxy - zastosowania
PPTX
My sql failover test using orchestrator
MongoDB Database Replication
Setting up mongo replica set
Javantura v2 - Replication with MongoDB - what could go wrong... - Philipp Krenn
MongoDb scalability and high availability with Replica-Set
Replica Sets (NYC NoSQL Meetup)
Haproxy - zastosowania
My sql failover test using orchestrator

What's hot (20)

PDF
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
PDF
MySQL Slow Query log Monitoring using Beats & ELK
PDF
Ceph issue 해결 사례
PDF
Container security: seccomp, network e namespaces
PPTX
Query logging with proxysql
PPTX
Postgres-BDR with Google Cloud Platform
PDF
Percona Toolkit for Effective MySQL Administration
PPTX
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
ODP
MySQL 101 PHPTek 2017
PDF
MySQL replication & cluster
PDF
MySQL async message subscription platform
PPTX
От sysV к systemd
PPSX
Logical volume manager xfs
PPTX
Getting started with replica set in MongoDB
PDF
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
PDF
Oracle cluster installation with grid and nfs
PDF
MySQL Tokudb engine benchmark
PDF
Oracle cluster installation with grid and iscsi
PPTX
Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...
PDF
1 m+ qps on mysql galera cluster
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
MySQL Slow Query log Monitoring using Beats & ELK
Ceph issue 해결 사례
Container security: seccomp, network e namespaces
Query logging with proxysql
Postgres-BDR with Google Cloud Platform
Percona Toolkit for Effective MySQL Administration
MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering...
MySQL 101 PHPTek 2017
MySQL replication & cluster
MySQL async message subscription platform
От sysV к systemd
Logical volume manager xfs
Getting started with replica set in MongoDB
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Oracle cluster installation with grid and nfs
MySQL Tokudb engine benchmark
Oracle cluster installation with grid and iscsi
Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...
1 m+ qps on mysql galera cluster
Ad

Viewers also liked (20)

PPT
MongoDB Replica Sets
PPTX
Back to Basics: Build Something Big With MongoDB
PPTX
MongoDB Replication (Dwight Merriman)
PDF
MongoDB Administration 101
PPTX
Webinar: MongoDB 2.4 Feature Demo and Q&A on Hash-based Sharding
PDF
Setting up mongodb sharded cluster in 30 minutes
PDF
PPTX
Sharding Methods for MongoDB
PPTX
Lightning Talk: What You Need to Know Before You Shard in 20 Minutes
PDF
Spring Data MongoDB Webiner
PDF
MongoDB Shard Cluster
PPTX
Webinar: Replication and Replica Sets
PDF
Development to Production with Sharded MongoDB Clusters
PDF
Replication and Synchronization Algorithms for Distributed Databases - Lena W...
PDF
Configuring MongoDB HA Replica Set on AWS EC2
PPT
Everything You Need to Know About Sharding
PPT
High Availabiltity & Replica Sets with mongoDB
PDF
TCP/IP Ağlarda İleri Seviye Paket Analizi – Tshark
PPT
Synchronization in distributed systems
PDF
Database Sharding At Netlog
MongoDB Replica Sets
Back to Basics: Build Something Big With MongoDB
MongoDB Replication (Dwight Merriman)
MongoDB Administration 101
Webinar: MongoDB 2.4 Feature Demo and Q&A on Hash-based Sharding
Setting up mongodb sharded cluster in 30 minutes
Sharding Methods for MongoDB
Lightning Talk: What You Need to Know Before You Shard in 20 Minutes
Spring Data MongoDB Webiner
MongoDB Shard Cluster
Webinar: Replication and Replica Sets
Development to Production with Sharded MongoDB Clusters
Replication and Synchronization Algorithms for Distributed Databases - Lena W...
Configuring MongoDB HA Replica Set on AWS EC2
Everything You Need to Know About Sharding
High Availabiltity & Replica Sets with mongoDB
TCP/IP Ağlarda İleri Seviye Paket Analizi – Tshark
Synchronization in distributed systems
Database Sharding At Netlog
Ad

Similar to Advanced Replication (20)

PDF
2013 london advanced-replication
PPTX
Replication and Replica Sets
PPTX
Replication and Replica Sets
PPTX
Webinar: Replication and Replica Sets
PPTX
Basic Replication in MongoDB
PPTX
Replication and replica sets
PDF
Replication MongoDB Days 2013
PDF
MongoDB: Optimising for Performance, Scale & Analytics
PPTX
MongoDB for Time Series Data Part 3: Sharding
PDF
NoSQL Infrastructure
PDF
Replication
PDF
Replication and Replica Sets
PPTX
2015 02-09 - NoSQL Vorlesung Mosbach
PDF
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
PDF
Monitoring with Prometheus
PPTX
Exactly once with spark streaming
PDF
OSDC 2012 | Scaling with MongoDB by Ross Lawley
PDF
10 Key MongoDB Performance Indicators
PDF
Developing with Cassandra
PDF
The powerful toolset of the go-mysql library
2013 london advanced-replication
Replication and Replica Sets
Replication and Replica Sets
Webinar: Replication and Replica Sets
Basic Replication in MongoDB
Replication and replica sets
Replication MongoDB Days 2013
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB for Time Series Data Part 3: Sharding
NoSQL Infrastructure
Replication
Replication and Replica Sets
2015 02-09 - NoSQL Vorlesung Mosbach
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Monitoring with Prometheus
Exactly once with spark streaming
OSDC 2012 | Scaling with MongoDB by Ross Lawley
10 Key MongoDB Performance Indicators
Developing with Cassandra
The powerful toolset of the go-mysql library

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...

Recently uploaded (20)

PPTX
1. Introduction to Computer Programming.pptx
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPT
What is a Computer? Input Devices /output devices
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
Modernising the Digital Integration Hub
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Getting Started with Data Integration: FME Form 101
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Chapter 5: Probability Theory and Statistics
1. Introduction to Computer Programming.pptx
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
O2C Customer Invoices to Receipt V15A.pptx
Developing a website for English-speaking practice to English as a foreign la...
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
WOOl fibre morphology and structure.pdf for textiles
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
A comparative study of natural language inference in Swahili using monolingua...
What is a Computer? Input Devices /output devices
1 - Historical Antecedents, Social Consideration.pdf
TLE Review Electricity (Electricity).pptx
observCloud-Native Containerability and monitoring.pptx
NewMind AI Weekly Chronicles - August'25-Week II
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Modernising the Digital Integration Hub
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Getting Started with Data Integration: FME Form 101
Enhancing emotion recognition model for a student engagement use case through...
Assigned Numbers - 2025 - Bluetooth® Document
Chapter 5: Probability Theory and Statistics

Advanced Replication

  • 1. #MongoDBDays - @m4rcsch Advanced Replication Marc Schwering Solutions Architect, 10gen
  • 4. Configuration Options > conf = { _id : "mySet", members : [ {_id : 0, host : "A"}, {_id : 1, host : "B"}, {_id : 2, host : "C", "arbiter" : true} ] } > rs.initiate(conf)
  • 7. 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
  • 9. 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 } } }
  • 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" } } }
  • 13. Maintenance and Upgrade • No downtime • Rolling upgrade/maintenance – Start with Secondary – Primary last – Commands: • rs.stepDown(<secs>) • db.version() • db.serverBuildInfo()
  • 15. Replica Set – 1 Data Center • Single datacenter • Single switch & power • Points of failure: – Power – Network – Data center – Two node failure • Automatic recovery of single node crash
  • 16. Replica Set – 2 Data Centers • Multi data center • DR node for safety • Can’t do multi data center durable write safely since only 1 node in distant DC
  • 17. Replica Set – 2 Data Centers • Analytics • Disaster Recovery • Batch Jobs • Options – low or zero priority – hidden – slaveDelay
  • 18. Replica Set – 3 Data Centers • Three data centers • Can survive full data center loss • Can do w= { dc : 2 } to guarantee write in 2 data centers (with tags)
  • 19. Replica Set – 3+ Data Centers Secondary Primary Secondary Secondary Secondary delayed Secondary Secondary
  • 20. Commands • Managing – rs.conf() – rs.initiate(<conf>) & rs.reconfig(<conf>) – rs.add(host:<port>) & rs.addArb(host:<port>) – rs.status() – rs.stepDown(<secs>) • Minority reconfig – rs.reconfig( cfg, { force : true} )
  • 21. Options • Priorities • Hidden • Slave Delay • Disable indexes (on secondaries) • Default write concerns
  • 25. Write Concern • Network acknowledgement • Wait for error • Wait for journal sync • Wait for replication – number – majority – Tags
  • 27. Datacenter awareness (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"}) > db.getLastErrorObj({"someDCs"})
  • 30. Write Concern with timeout settings : { getLastErrorModes : { allDCs : {"dc" : 3}, someDCs : {"dc" : 2}} } } > db.getLastErrorObj({"allDCs"},100); > db.getLastErrorObj({”someDCs"},500); > db.getLastErrorObj(1,500);
  • 31. Read Preference Modes • 5 modes (new in 2.2) – primary (only) - Default – primaryPreferred – secondary – secondaryPreferred – Nearest When more than one node is possible, closest node is used for reads (all modes but primary)
  • 32. 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. Tags {"dc.va": "rack1", disk:"ssd", ssd: "installed" } {"dc.va": "rack2", disk:"raid"} {"dc.gto": "rack1", disk:"ssd", ssd: "installed" } {"dc.gto": "rack2", disk:"raid”} > conf.settings = { getLastErrorModes: { MultipleDC : { "dc.va": 1, "dc.gto": 1}} > conf.settings = { "getLastErrorModes" : { "ssd" : { "ssd" : 1 },...
  • 34. Tagged Read Preference { disk: "ssd" } JAVA: ReadPreference tagged_pref = ReadPreference.secondaryPreferred( new BasicDBObject("disk", "ssd") ); DBObject result = coll.findOne(query, null, tagged_pref);
  • 35. Tagged Read Preference • Grouping / Failover {dc : "LON", loc : "EU"} {dc : "FRA", loc : "EU"} {dc : "NY", loc : "US”} DBObject t1 = new BasicDBObject("dc", "LON"); DBObject t2 = new BasicDBObject("loc", "EU"); ReadPreference pref = ReadPreference.primaryPreferred(t1, t2);
  • 37. Best practices and tips • Odd number of set members • Read from the primary except for – Geographically distribution – Analytics (separate workload) • Use logical names not IP Addresses in configs • Set WriteConcern appropriately for what you are doing • Monitor secondaries for lag (Alerts in MMS)
  • 38. #MongoDBDays - @m4rcsch Thank You Marc Schwering Solutions Architect, 10gen

Editor's Notes

  • #5: PrimaryData memberSecondaryHot standbyArbitersVoting member
  • #6: Remind the audience, that there are more options, multi dc failure etc. but this is for single machine failurePriorityFloating point number between 0..100Highest member that is up to date wins Up to date == within 10 seconds of primaryIf a higher priority member catches up, it will force election and win Slave DelayLags behind master by configurable time delay Automatically hidden from clientsProtects against operator errorsFat fingeringApplication corrupts data
  • #8: Schemaoplog, design considerations of MongoDB.. Not only master slave.Tunable: based on your needs.
  • #14: Upgrade/maintenanceCommon deployment scenarios
  • #20: TODO: How people really using it? …Get Data from secodaries (chaining)A good question to ask the audience : &apos;Why wouldn&apos;t you set w={dc:3}&apos;… Why would you ever do that? What would be the complications?
  • #24: ConsistencyWrite preferencesRead preferences
  • #30: Using &apos;someDCs&apos; so that in the event of an outage, at least a majority of the DCs would receive the change. This favors availability over durability.
  • #31: Using &apos;allDCs&apos; because we want to make certain all DCs have this piece of data. If any of the DCs are down, this would timeout. This favors durability over availability.
  • #35: Using &apos;someDCs&apos; so that in the event of an outage, at least a majority of the DCs would receive the change. This favors availability over durability.