Walking the Walk: Developing the MongoDB Backup Service with MongoDB
1. Engineer, Cloud Team, 10gen
Steve Briskin
Walking the Walk:
Developing the MongoDB
Backup Service With MongoDB
2. Agenda
• Intro: The Project
• How the backup service was built
– Keeping State
– Storage of Oplog Documents
– De-duped Snapshot Storage
• Q&A
3. The Project
• Started in December 2011 – 1 person
• 3 Engineers + PM & Manager by June 2012
• Private Beta – September 2012
• Limited Release – April 2013
• 6 Engineers (and hiring) + PM & Manager –
Now
• Agile Principles
4. Data Flow
Reconstructed Replica Sets
Sharded
Cluster
BRS
Daemon
Backu
p
Agent
Replica
Set 1
Customer
Replica
Set 4
Replica
Set 3
Replica
Set 2
Backup
Ingestion
10GEN
Backup
Daemon(s)
Main DB
Block
Store
RS
1
RS
2
RS
3
RS
4
2. Initial
Sync3. OpLog Data
1. Configuration
4. Save
Sync/Oplog Data
5. Reconstruct
Replica Set
6. Persist
Snapshot
7. Retrieve
Snapshot
8. SCP Data
Files
9. Capture Oplog
• Use replication oplog to capture activity
• Oplog is a Capped Collection – local.oplog.rs
– We can tail Capped Collections
• Strategy
– Tail the Oplog
– Read 10 MB of Data
– Compress and Send to 10gen
10. Store Oplog – First Version
• Single Capped Collection
• Pros
– Easy
• Cons
– Doesn’t scale!
– Customers will have an impact on each other
11. Store Oplog – Good Version
• DB per customer and Collection per replica set
• TTL Index for cleanup
• Pros
– Logical and Physical separation of customer data
– Can scale quickly and easily
– Configurable by end user
13. Storage – First Version
• Archive and Compress MongoDB data files
• Scatter archives across machines
– Pros
• Fast and Easy
– Cons
• No Redundancy, Hard to Scale, Wastes Space
Machine 1
Snapshot_1.tar.gz
Snapshot_4.tar.gz
Machine 2
Snapshot_2.tar.gz
Snapshot_5.tar.gz
Machine 3
Snapshot_3.tar.gz
Snapshot_6.tar.gz
14. Goal 1: De-Duplicated
Storage
• Observation
– Data change is low and localized
– Data is compressible
• Huge benefits in de-duplicating
Worst Case
0% de-dupe
No compression
Best Case
100% de-dupe
10x compression
Typical Case
90% de-dupe
3x compression
100G
B
100G
B
100G
B
100G
B
100G
B
100G
B
10GB 0GB 100G
B
100G
B
33GB 3GB
19. Putting the file back together
• For each file
– For each block
• Retrieve block
• Uncompress
20. Block Store Garbage
Collection
• 1st Attempt
– Reference counting
– Slow and non-parallelizable
• 2nd Attempt
– Mark and Sweep
– Parallelizable
– Requires more space
A presentation on we build the MongoDB Backup Service in house. Not a sales pitch.
FixBackup Agent = Exernal program, similar to MMS Agent. Written in Go.Ingestion = RESTfulwebservices. Responsible for all agent communication (configuration and ingestion)Daemons = Actual processing
“Evolving Schema with MongoDB”Complexity crept in – complex rules,graceful recovery, accurate representation of data, additional state. “More bells And whistles”
Schema Talk – how the application will use data. Start simple and evolve.
Explain what a capped collection is – circular bufferExplain what the oplog is
500GB -> 1TB oplog.Timeline– why this chosen, how long it lasted, why and when it stopped working (can’t shard, single point of contention, lose dynamic schema, customers intertwined)Start with somethingTTL indexes did not exist“”
MongoDB 2.2 coincided with this stage of developmentAdded in 2.2. Time To Live index. DB-level locking, TTLand dynamic schemaAnd we can shard shardingTTL window – hard to manage at first, made easier later
Worst case – no worse than tar.gz of files
Be prepared to discusszfs and why it wasn’t chosen
Risk: CorruptionBig Idea: De-duping -> save the stuff that changed
Multiple slides with details – what went wrong, why. E.g. indexes we used, read vs. wright, disk io was the bottleneck