Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do the MongoDB journal file and oplog differ?

Tags:

mongodb

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.

like image 627
Uday Avatar asked Jan 23 '12 11:01

Uday


People also ask

What is a MongoDB Journal file?

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.

What is Oplog in MongoDB?

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.

Where is Oplog size in MongoDB?

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 .

How much time is the journal written in MongoDB?

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.


1 Answers

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/

like image 74
milan Avatar answered Nov 13 '22 23:11

milan