Can Protect Your Data! Mathias Stearn @mathias_mongo #MongoNYC Find this presentation at speakerdeck.com/u/mathias Mathias Stearn @mathias_mongo Data Safety in MongoDB
is up to you to use them Don’t assume defaults are best There is no one size fits all What conditions do you want to protect against? Performance vs Safety vs Cost Tradeoffs Mathias Stearn @mathias_mongo Data Safety in MongoDB
Availability Zone 1 US West Region Replica 1 Availability Zone 3 Replica 3 Availability Zone 2 Replica 2 Mathias Stearn @mathias_mongo Data Safety in MongoDB
a slave to be rolling backup Rollbacks Writes not written to majority of nodes may be rolled back Multi-document operation Each document is independently replicated Mathias Stearn @mathias_mongo Data Safety in MongoDB
data files are garbage after unclean shutdown But I read a blog that said I’m safe if I . . . No! See item 1! Mathias Stearn @mathias_mongo Data Safety in MongoDB
Journaling Off You can recreate the data Initial Import Mongo as a cache Replicating across many data centers If 3 DCs in different continents go down simultaneously, you probably have bigger problems When a host has an unclean shutdown you must delete the data files and restore or resync Otherwise, just leave it on. Mathias Stearn @mathias_mongo Data Safety in MongoDB
Connection ( ) db = connection [ ’ t e s t ’ ] # No GetLastError db . s t u f f . i n s e r t ( { ’ hello ’ : ’ world ’ } ) # Sends GetLastError ( Safe−mode) db . s t u f f . i n s e r t ( { ’ hello ’ : ’ world ’ } , safe=True ) # Waits f o r r e p l i c a t i o n db . s t u f f . i n s e r t ( { ’ hello ’ : ’ world ’ } , w= ’ majority ’ ) Mathias Stearn @mathias_mongo Data Safety in MongoDB
safety at many leve ls connection = pymongo . Connection ( safe=True ) db . set_lasterror_options (w=2) db . cache . safe = False db . on_disk . set_lasterror_options ( j =True ) # No GetLastError db . cache . i n s e r t ( { ’ hello ’ : ’ world ’ } ) # Waits f o r r e p l i c a t i o n db . r e p l i c a t e d . i n s e r t ( { ’ hello ’ : ’ world ’ } ) # Waits f o r journ a l but not r e p l i c a t i o n db . on_disk . i n s e r t ( { ’ hello ’ : ’ world ’ } ) Mathias Stearn @mathias_mongo Data Safety in MongoDB