What is Journalling File System and Journalling in MongoDB?
3 min readFeb 4, 2019
I am going through mongo internal architecture it uses journalling. I thought why not i also add some points to it.
What is Journalling?
- Journalling is another file system where we keep records which are not yet updated or committed to file system’s main part (where all the data for particular application resides in the disc, example MongoDB writes in /data/db). Records are known as a journal. which is another circular records or logs.
- As we all know to access data from the disc, disc head(read or write head) to move to that corresponding track and sector. (how Disc reading and writing works ? is out of scope. Google it). so the time taken to move from one track to another track called as seek time. If data is randomly distributed then seek time will be more.
- In journaling, all the records or journals written in consecutive tracks (similar as an arrays data structure)so that seek time will be very less as compared to random access. this is the main benefit of journalling.
- If we write data to file system’s main part then it will be slow and slows down overall processing.
- So in MongoDB first data is written to journal and periodically it gets flushed on main MongoDB memory.
- The main benefit of this is increase processing time and if system or application(MongoDB) is crashed then it starts again frequently.
Now you have a basic understanding of Journalling, will jump into how journalling works in MongoDB.
Journalling in MongoDB:
- When writes operation is done in MongoDB, first changes is done in private view, after a specified interval, which is called a journal commit interval, the private view writes those operations in journal directory (residing in the disc).
- After journal commit happens or written in journal memory then MongoDB pushes data in the shared view. After a specified interval of time (default 60 secs). it copied to the main directory of MongoDB.
- After data is flushed in the main MongoDB directory then it is marked as processed and removed from journal memory.
- So whenever any crash occurs then data MongoDB starts very frequently because data is cached in journal memory.
- Private view and shared view are allocated space in RAM. (Memory mapped file) or main memory. Say for example if your file is 2000 byte on disk then it will map it to memory address 1000–1000010, so you can read the file directly from memory address. Any change in the file from memory address will be flushed back to file in your disk.
This is the basic concepts behind the journalling of MongoDB. Private view add another level of caching data so that MongoDB reboots faster.