Mongodb – How to check the pre-allocated database file of MongoDB is Used or not

mongodb

We have been using MongoDB for a few weeks. One thing we could not understood is Pre-allocated file. Is there any way to check whether the pre-allocated file is currently used by MongoDB or not?

We have planned to implement "Quota File". So we need to ensure the pre-allocated file is currently used or not.

For Example, I have the database file as follows:

sgserver.0 ---> 16MB
sgserver.1 ---> 128MB
sgserver.2 ---> 256MB
sgserver.3 ---> 512MB

How do I check the pre-allocated file sgserver.3 is used by MongoDB (for example, this database is used by any BSON or its Un-used)?

Best Answer

I am not very familiar with MongoDB, but from this link:

As soon as a datafile starts to be used, the next one will be preallocated.

It seems to me that (on *nix at least), MongoDB will always have a datafile that is empty, or mostly empty. If it's writing heavy and filling up the file, the last file might have some data in it before a new empty file can be created.

Additionally, on Unix, mongod will preallocate an additional datafile in the background and do background initialization of this file. These files are prefilled with zero bytes.

So to determine if it's used, check the file for non-zero bytes.