Replica Sets Painless scaling and High Availability (HA) Viktor - - PowerPoint PPT Presentation

replica sets
SMART_READER_LITE
LIVE PREVIEW

Replica Sets Painless scaling and High Availability (HA) Viktor - - PowerPoint PPT Presentation

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,


slide-1
SLIDE 1

Replica Sets

Painless scaling and High Availability (HA)

Viktor Petersson

@vpetersson

slide-2
SLIDE 2

Who am I?

{ name : ‘Viktor Petersson’, description : [ ‘geek’, ‘entrepreneur’ ], founder_of : ‘wireload’, twitter : ‘@vpetersson’, email : ‘vpetersson@wireload.net’, }

@vpetersson

slide-3
SLIDE 3

What is MongoDB?

@vpetersson

  • Key-value store
  • Schemas less
  • Distributed file system (GridFS)
  • Built-in Map/Reduce
  • Built to scale
slide-4
SLIDE 4

MongoDB 101

Relational Database MongoDB Database Database Table Collection Row Document Database structure (simplified)

@vpetersson

slide-5
SLIDE 5

MongoDB 101

Relational Database MongoDB Master Primary Slave Secondary Arbiter (Hidden) Node types

@vpetersson

slide-6
SLIDE 6

What are Replica Sets and why should I care?

@vpetersson

slide-7
SLIDE 7

Typical failover with relational databases

Master Slave

Failover IP

Master Slave

Failover IP

Master Normal Degraded

@vpetersson (two servers, can lose one)

slide-8
SLIDE 8

More complex failover with relational databases

Failover IP

Normal

@vpetersson

Proxies Database servers

Failover IP

Degraded

(four servers, can lose one of each kind)

slide-9
SLIDE 9

Failover with MongoDB

Primary Secondary Normal Degraded Secondary

Driver

Primary Secondary Secondary

Driver

Primary

@vpetersson (three servers, can lose two)

slide-10
SLIDE 10

Primary Secondary Down -> Recovering Recovering -> Secondary Secondary

Driver

Primary Secondary Secondary

Driver

Primary Secondary Primary Recovering

Automatic recovery

@vpetersson

slide-11
SLIDE 11

Real life example: Taking down the primary for maintenance. No dropped connections.

Primary Secondary

@vpetersson

slide-12
SLIDE 12

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’)

  • 1. After adding “replSet=myRepSet” and “rest = true” to mongo.conf

@vpetersson

slide-13
SLIDE 13

Live demo!

3 servers with 1 client

@vpetersson

slide-14
SLIDE 14

Election

@vpetersson

  • 1. Most up to date
  • 2. Highest priority
  • 3. Less than 10s behind Primary
slide-15
SLIDE 15

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

slide-16
SLIDE 16

Leverage your secondary-nodes

Warning: Secondaries may be out-of-date.

Read preference

  • Primary (default)
  • Secondary
  • Secondary_only

@vpetersson

slide-17
SLIDE 17

What happens when I’ve

  • utgrown my Replica Set?

@vpetersson

slide-18
SLIDE 18

@vpetersson

mongos repset0 repset1 repsetN

Sharding

slide-19
SLIDE 19

Useful commands

View server status $ db.serverStatus() View the replication status $ rs.status() Step down as Primary $ rs.stepDown(n)

@vpetersson

slide-20
SLIDE 20
  • Improved location awareness
  • Improved concurrent capacity
  • TTL collections

@vpetersson

What’s new in MongoDB 2.2?

Full release notes: http://docs.mongodb.org/manual/release-notes/2.2/

(released yesterday)

slide-21
SLIDE 21

Summary

@vpetersson

  • Replica Sets are extremely easy to set up
  • Doesn’t require failover IPs or custom scripts
  • Minimal maintenance
  • Built to scale
slide-22
SLIDE 22

Questions?

@vpetersson

slide-23
SLIDE 23

Thanks to

@vpetersson

slide-24
SLIDE 24

Contact me!

email: info@viktorpetersson.com www: viktorpetersson.com twitter: @vpetersson

Also visit WireLoad.net YippieMove.com

@vpetersson

This deck will be available at ViktorPetersson.com.

slide-25
SLIDE 25
  • 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

Useful resources