Anand Dayalan
Anand Dayalan

Reputation: 513

MongoDb creates additional data files before data size grows beyond the initial allocated files size

I'm running mongod with smallfiles option. Initially it created three files

  1. .ns ---16 MB
  2. .0 ---16 MB
  3. .1 ---32 MB

These files I know and I know why MongoDb creates them. I started adding records in two collection in the database after some time, MongoDb created another data file .2 ---64 MB. When I looked at the size of two collection and index, I found that the total size is just about 30 MB which should have easily fit into the initial two files .0 and .1, but why MongoDB is creating the third file?

Here is size details

  1. Collection1 count:5230 size: 9.5 MB Storage: 18.8 MB Index: 0.2 MB Padding: 1
  2. Collection2 count:1 size: 1 KB Storage: 64 KB Index: 7 KB Padding: 1
  3. system.indexes count:2 size: 0.2 KB Storage: 8 KB Index: 0 bytes Padding: 1

No other collection is the DB. As you can see the total storage size didn't exceed 30 MB. Why mongoDb created a third file when there are two data files already having size 16 + 32 MB?

Upvotes: 1

Views: 206

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230286

It's because mongodb preallocates storage files. Suppose, you fill those two files up pretty quickly. You don't want to wait while a new file is allocated, because on some filesystems it may take time. Instead, mongodb arranges so that at each moment there is an empty file, ready to be written to.

Upvotes: 1

Related Questions