Q. MongoDB's Data Storage Method

While studying MongoDB, I got to know Flush, Journal, and Oplog.

  • Flush is once the memory stores the data, it stores it on disk after a certain period of time (default 60 seconds).

  • Journal is before saving data to disk, save it to a Journal record and save it to disk.

  • Oplog is after storing the data completely, store the details of the work in the form of a log in the oplog.

Then, when the data write operation comes into the primary node,
does it proceed in the order of flush → journal → oplog?

Can you tell me in detail what is the order of the these processes?

Hi @Kim_Hakseon,

This sounds a lot like the good old MMapV1 storage engine. With WiredTiger, things are a bit different now. It’s well explained in this doc : https://www.mongodb.com/docs/manual/core/wiredtiger/. At least that’s as far as my knowledge goes. Then it’s really low level operations that I don’t know about.

Note that snapshots & checkpoints is also one of the fundamental brick that allow MongoDB to perform multi-document ACID transactions.

Cheers,
Maxime.

What happens when you write to a document is we write to the document and we write a special format of this write to the oplog in memory “simultaneously”. Then, only the oplog is flushed to the journal. This is because the journal is used to replay operations after a crash onto the most recent saved “checkpoint” (what you are calling flush). Only the oplog format is necessary to recreate any writes that happened after the last checkpoint. So the order is really the opposite of what you have - “oplog” → “journal” and then relatively infrequently by comparison “flush” aka checkpoint.

Asya

2 Likes

Thank you.
I will study hard about the page.:smiley:

Oh, my God!
If I may use your words to recapitulate,

  1. Save task as an oplog in memory
  2. Flush the corresponding Oplog to the journal
  3. Store Oplog and intact data on disk

Right?

And the Secondary is replicating the Primary’s Oplog on the memory?
(In the above process, number 1)

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.