P. 1
MongoDB replica sets

MongoDB replica sets

|Views: 219|Likes:
Published by Alvin John Richards
How do you protect data and make it available? In this talk, we will cover the basics of Replica Sets in MongoDB and discuss how to use them to ensure that the data is available to your application and you can survive various forms of disaster from a machine crash to the the loss of a data center.
How do you protect data and make it available? In this talk, we will cover the basics of Replica Sets in MongoDB and discuss how to use them to ensure that the data is available to your application and you can survive various forms of disaster from a machine crash to the the loss of a data center.

More info:

Published by: Alvin John Richards on Sep 22, 2010
Copyright:Traditional Copyright: All rights reserved

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF or read online from Scribd
See more
See less

01/26/2011

Replica  Sets   (MongoDB  v1.

6)  
Alvin  Richards   10gen   alvin@10gen.com  

Basics  
•  MongoDB  replica?on  is  a  bit  like  MySQL   replica?on  
–  Asynchronous  master/slave  at  its  core  

•  Varia?ons:  
–  Master  /  slave   –  Replica  Pairs  (deprecated  –  use  replica  sets)   –  Replica  Sets  (today’s  topic)  

Replica  Sets  
•   A  cluster  of  N  servers   •   Any  (one)  node  can  be  primary   •   Consensus  elec?on  of  primary   •   Automa?c  failover   •   Automa?c  recovery   •   All  writes  to  primary   •   Reads  can  be  to  primary  (default)  or  a  secondary   •   v1.6  

With  Sharding  

Replica  Sets  –  Design  Concepts  
1.  A  write  is  only  truly  commiQed  once  it  has  replicated   to  a  majority  of  servers  in  the  set.      
Thus,  for  important  writes,  the  developer  waits  for  confirma7on  of  the   cluster-­‐wide  commit  with  the  getLastError  command.  

2.  Writes  which  are  commiQed  at  the  master  of  the  set   may  be  visible  before  the  true  cluster-­‐wide  commit   has  occurred.    This  property,  which  is  more  relaxed   than  some  tradi?onal  products,  makes  theore?cally   achievable  performance  and  availability  higher.   3.  On  a  failover,  if  there  is  data  which  has  not  replicated   form  the  primary,  the  data  is  dropped  (see  #1).      

A  Set  
Member  1   Member  3  

Member  2  

A  Set  
Member  1   Member  3  

Member  2   PRIMARY  

A  Set  
Member  1   nego?ate   new  master   Member  3   PRIMARY  

Member  2   DOWN  

A  Set  
Member  1   Member  3   PRIMARY  

Member  2   DOWN  

A  Set  
Member  1   Member  3   PRIMARY  

Member  2   RECOVER-­‐ ING  

A  Set  
Member  1   Member  3   PRIMARY  

Member  2  

Configura?on  
{ _id : <setname>, members: [ { _id : <ordinal>, host : <hostname[:port]>, [, priority: <priority>] [, arbiterOnly : true] [, votes : n] [, slaveDelay : s] [, hidden : true ] } , ... ], settings: { [getLastErrorDefaults: <lasterrdefaults>] [, heartbeatSleep : <seconds>] [, heartbeatTimeout : <seconds>] [, heartbeatConnRetries : <n>] } }

Ini?a?on  
> cfg = { ... _id : "acme_a", ... members : [ ... { _id : 0, host : "sf1.acme.com" }, ... { _id : 1, host : "sf2.acme.com" }, ... { _id : 2, host : "sf3.acme.com" } ] } > use admin > db.runCommand({replSetInitiate:cfg})

Set  Member  Types  
•  •  •  •  Normal  (priority  ==  1)   Passive  (priority  ==  0)   DR  (priority  <  1.0)  (coming  soon)   Arbiter  (no  data,  but  can  vote)  

Commands  
{  isMaster  :  1  }   {  replSetGetStatus  :  1  }   {  replSetIni?ate  :  <config>  }   {  replSetStepDown  :  true  }   {  replSetReconfig  :  <config>  }   > rs.help()

Demo  

Ques?ons?  
Contact  10gen  for  on-­‐site  advisory  sessions  on  MongoDB   architecture,  schema  design,  performance  tuning,  training…   info@10gen.com  

irc://irc.freenode.net/#mongodb   hJp://groups.google.com/group/mongodb-­‐user  

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->