Transcript
Page 1: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Solutions Architect, 10gen

Marc Schwering

#MongoDBDays - @m4rcsch

Replication and Replica Sets

Page 2: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Agenda

• Replica Sets Lifecycle

• Developing with Replica Sets

• Operational Considerations

Page 3: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

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

Page 4: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

ReplicaSet Lifecycle

Page 5: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Replica Set – Creation

Page 6: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Replica Set – Initialize

Page 7: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Replica Set – Failure

Page 8: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Replica Set – Failover

Page 9: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Replica Set – Recovery

Page 10: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Replica Set – Recovered

Page 11: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

ReplicaSet Roles & Configuration

Page 12: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Replica Set Roles

Page 13: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

> 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

Page 14: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

> 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

Primary DC

Page 15: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

> 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

Secondary DCDefault Priority = 1

Page 16: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

> 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

Analytics

node

Page 17: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

> 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

Backup node

Page 18: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Developing with Replica Sets

Page 19: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Strong Consistency

Page 20: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Delayed Consistency

Page 21: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Write Concern

• Network acknowledgement

• Wait for error

• Wait for journal sync

• Wait for replication

Page 22: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Unacknowledged

Page 23: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

MongoDB Acknowledged (wait for error)

Page 24: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Wait for Journal Sync

Page 25: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Wait for Replication

Page 26: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Tagging

• New in 2.0.0

• 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

Page 27: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

{

_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"})

Tagging Example

Page 28: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Wait for Replication (Tagging)

Page 29: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

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)

Page 30: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

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

Page 31: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Operational Considerations

Page 32: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Maintenance and Upgrade

• No downtime

• Rolling upgrade/maintenance– Start with Secondary– Primary last

Page 33: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

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

Page 34: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

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

Page 35: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

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)

Page 36: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Recent improvements

• Read preference support with sharding– Drivers too

• Improved replication over WAN/high-latency networks

• rs.syncFrom command

• buildIndexes setting

• replIndexPrefetch setting

Page 37: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

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

Page 38: MongoDB London 2013: Basic Replication in MongoDB presented by Marc Schwering, 10gen

Solutions Architect, 10gen

Marc Schwering

#MongoDBDays - @m4rcsch

Thank You


Recommended