Your SlideShare is downloading. ×

Repl internals

1,132
views

Published on

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,132
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
24
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Replication Internals
    • MongoBerlin 2010-10-4
    • Mathias Stearn
    • [email_address]
  • 2. Replication is Good!
    • Use it!
    • mongod --master
    • mongod --slave --source host:port
    • 30 second demo…
  • 3. Basic Phases of a Slave
    • If not empty skip to step 4 (--fastsync)
    • Note master's position in OpLog
    • Copy data from master ($snapshot)
    • Replay OpLog to catch up
    • Continue watching OpLog for new changes
    • ???
    • Profit
  • 4. The OpLog
    • “ local.oplog.$main” for Master/Slave
      • Only on Master
    • “ local.oplog.rs” for ReplicaSets
      • On all nodes
    • Uses a capped collection (--oplogSize)
      • “ Wraps” when full (LRI)
      • Make sure it's large enough
      • You can query it like any other collection
  • 5. OpLog Entries
    • { "ts" : { "t" : 1286179802000, "i" : 1 }, "op" : "i", "ns" : "test.foo", "o" : { "_id":1, "a" : 1 } }
    • Operations:
      • I : insert
      • U : update (modified to be idempotent)
      • D : delete (one per object)
      • C : command
      • N : No-op (ignore these)
  • 6. OpLog demo
    • Insert and update an object
    • Look at OpLog
      • Use local
      • db.oplog.$main.find({op:{$ne:'n'}})
      • sort({$natural:-1})
    • Show data on slave
    • Add new slave and show data
  • 7. Replication Optimizations
    • All of these QueryOptions are used internally
    • Exaust – Sends all data w/o GetMores
    • Tailable – Leaves cursor open
    • AwaitData – Query blocks for data (push)
    • OplogReplay – Optimizes scan for entries newer than supplied timestamp so we don't need an index
  • 8. Replica Pairs
    • Deprecated by ReplSets in 1.6
    • Don't use!
  • 9. Replica Sets
    • Evolution of Replica Pairs
      • Reflects “lessons learned”
    • Any number of nodes
      • All keep a copy of the OpLog
      • At any time one node is Primay
      • If Primary fails, remaining nodes elect a new Primary with newest data
  • 10. Replica Set Gotchas
    • When Primary fails, short period of time with no Primary
    • Election requires a majority of nodes up
      • Works best with 3 failure domains
    • Writes not commited to quorum can be rolled-back
      • Use getLastError with “W”
    • Cascading not support yet (planned)
  • 11. Questions?
    • Ask away!
    • #mongodb on irc.freenode.net
    • [email_address]
    • [email_address]
    • Thanks for coming!

×