Replica Sets Painless scaling and High Availability (HA) Viktor Petersson @vpetersson
Who am I? { name : ‘Viktor Petersson’, description : [ ‘geek’, ‘entrepreneur’ ], founder_of : ‘wireload’, twitter : ‘@vpetersson’, email : ‘vpetersson@wireload.net’, } @vpetersson
What is MongoDB? • Key-value store • Schemas less • Distributed file system (GridFS) • Built-in Map/Reduce • Built to scale @vpetersson
MongoDB 101 Database structure (simplified) Relational Database MongoDB Database Database Table Collection Row Document @vpetersson
MongoDB 101 Node types Relational Database MongoDB Master Primary Slave Secondary Arbiter (Hidden) @vpetersson
What are Replica Sets and why should I care? @vpetersson
Typical failover with relational databases (two servers, can lose one) Normal Degraded Failover IP Failover IP Master Slave Master Slave Master @vpetersson
More complex failover with relational databases (four servers, can lose one of each kind) Degraded Normal Failover IP Failover IP Proxies Database servers @vpetersson
Failover with MongoDB (three servers, can lose two) Normal Degraded Driver Driver Primary Secondary Secondary Primary Secondary Secondary Primary @vpetersson
Automatic recovery Down -> Recovering Recovering -> Secondary Driver Driver Primary Secondary Secondary Primary Secondary Secondary Recovering Primary Primary Secondary @vpetersson
Real life example: Taking down the primary for maintenance. No dropped connections. Primary Secondary @vpetersson
Creating a Replica Set is dead simple. All it takes is three servers (s0, s1, s2) and three commands ¹ . $ mongo > rs.initiate() > rs.add(‘s1’) > rs.add(‘s2’) @vpetersson 1. After adding “replSet=myRepSet” and “rest = true” to mongo.conf
Live demo! 3 servers with 1 client @vpetersson
Election 1. Most up to date 2. Highest priority 3. Less than 10s behind Primary @vpetersson
Configure node priority $ cfg = rs.conf() $ cfg.members[x].priority = n $ rs.reconfig(cfg) x = Member id, n = Priority (0 - 100), default is 1. @vpetersson
Leverage your secondary-nodes Read preference • Primary (default) • Secondary • Secondary_only @vpetersson Warning: Secondaries may be out-of-date.
What happens when I’ve outgrown my Replica Set? @vpetersson
Sharding mongos repset0 repset1 repsetN @vpetersson
Useful commands View server status $ db.serverStatus() View the replication status $ rs.status() Step down as Primary $ rs.stepDown(n) @vpetersson
What’s new in MongoDB 2.2? (released yesterday) • Improved location awareness • Improved concurrent capacity • TTL collections Full release notes: @vpetersson http://docs.mongodb.org/manual/release-notes/2.2/
Summary • Replica Sets are extremely easy to set up • Doesn’t require failover IPs or custom scripts • Minimal maintenance • Built to scale @vpetersson
Questions? @vpetersson
Thanks to @vpetersson
Contact me! email: info@viktorpetersson.com www: viktorpetersson.com twitter: @vpetersson This deck will be available at ViktorPetersson.com. Also visit WireLoad.net YippieMove.com @vpetersson
Useful resources • MongoDB: GridFS, sharding and deploying in the cloud (http://goo.gl/1QAV1) • MongoDB Replica Set (http://goo.gl/D2pkq) • 10gen (http://goo.gl/3m4Kn) @vpetersson
Recommend
More recommend