Mongosv 2011 - Replication

28
Replication Jared Rosoff (@forjared)

description

Replication talk from MongoSV 2011

Transcript of Mongosv 2011 - Replication

Page 1: Mongosv 2011 - Replication

Replication

Jared Rosoff (@forjared)

Page 2: Mongosv 2011 - Replication

Overview

• Intro to replica sets• The oplog• Durability and Consistency• Common deployment scenarios • Advanced configuration

Page 3: Mongosv 2011 - Replication

INTRO TO REPLICA SETS

Page 4: Mongosv 2011 - Replication

Replica Sets

Primary

Secondary

Secondary

Asynchronous Replication

Read

Write

Read

Read

Driv

er

Page 5: Mongosv 2011 - Replication

Replica Sets

Primary

Secondary

Secondary

Read

Read

Driv

er

Page 6: Mongosv 2011 - Replication

Replica Sets

Primary

Primary

Secondary

Read

Write

Read

AutomaticLeader Election

Driv

er

Page 7: Mongosv 2011 - Replication

Replica Sets

Secondary

Primary

Secondary

Read

Write

Read

Read

Driv

er

Page 8: Mongosv 2011 - Replication

CONSISTENCY AND DURABILITY

Page 9: Mongosv 2011 - Replication

Strong Consistency

Primary

Secondary

Secondary

Read

Write

Driv

er

Page 10: Mongosv 2011 - Replication

Eventual Consistency

Primary

Secondary

Secondary

Read

Write

Driv

er

Read

Page 11: Mongosv 2011 - Replication

Durability

• Fire and forget• Wait for error • Wait for fsync• Wait for journal sync • Wait for replication

Page 12: Mongosv 2011 - Replication

Fire and forgetDriver Primary

write

apply in memory

Page 13: Mongosv 2011 - Replication

Get last errorDriver Primary

getLastErrorapply in memory

write

Page 14: Mongosv 2011 - Replication

Wait for Journal SyncDriver Primary

getLastErrorapply in memory

write

j:trueWrite to journal

Page 15: Mongosv 2011 - Replication

Wait for fsyncDriver Primary

getLastErrorapply in memory

write

fsync:true

fsync

Page 16: Mongosv 2011 - Replication

Wait for replicationDriver Primary

getLastErrorapply in memory

write

w:2

Secondary

replicate

Page 17: Mongosv 2011 - Replication

Write Concern Options

Value Meaning

<n:integer> Replicate to N members of replica set

“majority” Replicate to a majority of replica set members

<m:modeName> Use custom error mode name

Page 18: Mongosv 2011 - Replication

Tagging

{ _id: “someSet”, 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: { veryImportant: { dc: 3 }, sortOfImportant: { dc: 2 } } } }

These are the modes you can

use in write concern

Page 19: Mongosv 2011 - Replication

REPLICA SET OPTIONS

Page 20: Mongosv 2011 - Replication

Priorities

• Between 0..1000• Highest member that is up to date wins

– Up to date == within 10 seconds of primary

• If a higher priority member catches up, it will force election and win

Primarypriority = 100

Secondary

priority = 50

Secondary

priority = 20

Page 21: Mongosv 2011 - Replication

Slave Delay

• Lags behind master by configurable time delay

• Automatically hidden from clients• Protects against operator errors

– Accidentally delete database – Application corrupts data

Page 22: Mongosv 2011 - Replication

Arbiters

• Vote in elections• Don’t store a copy of data • Use as tie breaker

Page 23: Mongosv 2011 - Replication

COMMON DEPLOYMENT SCENARIOS

Page 24: Mongosv 2011 - Replication

Typical

Data Center

Primary Secondary

Secondary

Page 25: Mongosv 2011 - Replication

Backup Node

Data Center

Primary Secondary

hidden = true

Secondary

backups

Page 26: Mongosv 2011 - Replication

Disaster Recovery

Active Data Center Standby Data Center

Primarypriority = 1

Secondary

priority = 1

Secondary

Page 27: Mongosv 2011 - Replication

West Coast DC Central DC East Coast DC

Multi Data Center

Secondary

Secondary

Primarypriority = 1

Page 28: Mongosv 2011 - Replication