Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MongoDB Replication
Search
Sridhar Nanjundeswaran
September 14, 2012
Programming
1
110
MongoDB Replication
Presented at MongoDB Seattle Sept 2012.
Sridhar Nanjundeswaran
September 14, 2012
Tweet
Share
More Decks by Sridhar Nanjundeswaran
See All by Sridhar Nanjundeswaran
MongoDB Introduction
sridharnanjundeswaran
2
99
Built to scale – Cloud Computing and NoSQL databases
sridharnanjundeswaran
0
48
Replication and Replica Sets
sridharnanjundeswaran
1
100
MongoDB Roadmap
sridharnanjundeswaran
1
120
MongoDB Replication and Replica Sets
sridharnanjundeswaran
1
54
MongoDB Roadmap
sridharnanjundeswaran
1
52
Building your first MongoDB app
sridharnanjundeswaran
0
55
MongoDB and Windows Azure
sridharnanjundeswaran
0
66
MongoDB 2.2 New Features
sridharnanjundeswaran
2
200
Other Decks in Programming
See All in Programming
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
730
shadcn/uiを使ってReactでの開発を加速させよう!
lef237
0
210
テストコード書いてみませんか?
onopon
2
280
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
130
Zoneless Testing
rainerhahnekamp
0
150
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
200
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
8
1.8k
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
360
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
380
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
230
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
340
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
210
Featured
See All Featured
How GitHub (no longer) Works
holman
312
140k
Agile that works and the tools we love
rasmusluckow
328
21k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
940
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
Code Reviewing Like a Champion
maltzj
521
39k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
The Cult of Friendly URLs
andyhume
78
6.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Transcript
1 Sridhar Nanjundeswaran, 10gen
[email protected]
@snanjund
2 • Introduction to Replica Sets • Developing with Replica
Sets • Operational Considerations • Miscellaneous
Introduction to Replica Sets What is it? Configuration Options
4 Node 1 Node 2 Node 3
5 Node 1 Secondary Node 2 Secondary Node 3 Primary
Replication Replication Heartbeat
6 Node 1 Secondary Node 2 Secondary Node 3 Primary
Heartbeat Primary Election
7 Node 1 Secondary Node 2 Primary Node 3 Primary
Heartbeat Replication
8 Node 1 Secondary Node 2 Primary Node 3 Secondary
Replication Heartbeat Replication
9 • Priorities – Help control election – Secondary only
• Slave Delay – Purposely delay replication • Hidden – Not seen as part client connection • Tagging
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
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"})
Developing with Replica Sets Consistency Write Preference Read Preference
13 Primary Secondary Secondary Read Write Driver Client
14 Primary Read Write Driver Read Secondary Secondary Client Application
15 • Fire and forget • Wait for error •
Wait for journal sync • Wait for replication
16 Driver Primary write apply in memory
17 Driver Primary getLastError apply in memory
18 Driver Primary getLastError apply in memory write j:true Write
to journal
19 Driver Primary getLastError apply in memory write w:2 Secondary
replicate
20 • 5 modes – primary (only) - Default –
primaryPreferred – secondary – secondaryPreferred – nearest
21 • Custom read preferences • Control where you read
from – E.g. { "disk": "ssd", "use": "reporting" } • Use in conjunction with standard read preferences – Except primary
Operational Considerations Upgrade/Maintenance Common Deployment Scenarios
23 • No downtime • Rolling upgrade/maintenance – Start with
Secondary – Primary last
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
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
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
Miscellaneous Behind the scenes What’s new in 2.2
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 } } }
29 • Full read preference support in mongos – Drivers
too • Improved RS lag logging • rs.syncFrom command • buildIndexes setting • replIndexPrefetch setting
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
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