I have recently started on MongodDb and I'm trying to explore on replica sets and crash recovery.
I have read it like journal file are write a head redo log file. oplog files are those where every write activity will be written to.
What is the difference between these two...? Do we have oplogs on both the master and the slave...? Please post any web links that shed some light on this area.
MongoDB uses write ahead logging to an on-disk journal to guarantee write operation durability. The WiredTiger storage engine does not require journaling to guarantee a consistent state after a crash. The database will be restored to the last consistent checkpoint during recovery.
The Oplog (operations log) is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. MongoDB applies database operations on the primary and then records the operations on the primary's oplog.
To view the current size of the oplog, switch to the local database and run db. collection. stats() against the oplog.rs collection. stats() displays the oplog size as maxSize .
MongoDB first applies write operations to the private view. MongoDB then applies the changes in the private view to the on-disk journal files in the journal directory roughly every 100 milliseconds.
Oplog stores high-level transactions that modify the database (queries are not stored for example), like insert this document, update that, etc. Oplog is kept on the master and slaves will periodically poll the master to get newly performed operations (since the last poll). Operations sometimes get transformed before being stored in the oplog so that they are idempotent (and can be safely applied many times).
Journal on the other hand can be switched on/off on any node (master or slave), and is a low-level log of an operation for the purpose of crash recovery and durability of a single mongo instance. You can read low-level op like 'write these bytes to this file at this position'.
NOTE: Starting in MongoDB 4.0, you cannot turn journaling off for replica set members that use the WiredTiger storage engine. Source: https://docs.mongodb.com/manual/tutorial/manage-journaling/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With