Mongodb Data File Format

Source: Internet
Author: User
This article is suitable for users who have some knowledge about mongodb. Mongodb data files are stored in the directory specified by the dbpath option. Each database has a series of Files: dbname. ns, dbname.0, dbname.1,... the data file is also called pdfile, meaning PortableDataFile. Dbname. ns file dbname. ns file storage name is blank

This article is suitable for users who have some knowledge about mongodb. Mongodb data files are stored in the directory specified by the dbpath option. Each database has a series of Files: dbname. ns, dbname.0, dbname.1,... the Data File is also called pdfile, meaning Portable Data File. Dbname. ns file dbname. ns file storage name is blank

This article is suitable for users who have some knowledge about mongodb.

Mongodb data files are stored in the directory specified by the dbpath option. Each database has a series of Files: dbname. ns, dbname.0, dbname.1,... the Data File is also called pdfile, meaning Portable Data File.

Dbname. ns File

Dbname. ns file storage namespace information. In mongodb, each collection has a namespace named dbname. collection_name. The dbname. ns file stores an array of hash table nodes. The key is based on the namespace name, and the value is the namespace information. The size of the hash table node is 628 bytes, and the Hong Kong server is rented. The default size of the dbname. ns file is 16 Mb. The Hong Kong VM can store a total of 26715 namespaces. The nssize option can be used to set the size of the dbname. ns file.

Related code

Dbname. <#> series files

Dbname. <#> A series of files store all the data in each database. The file format is

--------------------------------------------
DataFileHeader
--------------------------------------------
Extent (for a participant namespace)
Record
...
Record (some chained for unused space)
--------------------------------------------
More Extents...
--------------------------------------------

DataFileHeader is the header of the data file, followed by Extent. The file space is allocated in Extent. The Applied Extent of each namespace forms a two-way linked list. The header and end of the table are included in the namespace information. Record is a Record, which is allocated in Extent. All records in each Extent form a two-way linked list. The header and the end of the table have the Extent header. You can think of the following method to traverse all the Record in the namespace: traverse the Extent linked list and traverse the Record linked list for each Extent. Idle Record (the remaining space in Extent, or the Record is deleted). The Record-free space is called DeleteRecord. Based on its size, 19 one-way linked lists are formed (the table header also exists in the namespace ). You can think of the method to apply for a Record: First find it from the idle Record; if it cannot be found, allocate a new Extent.

When a namespace is deleted, all its Extent will be mounted to the Extent linked list of the collection named $ freelist. When Extent is allocated, it is first searched from the Extent linked list of $ freelist. If not, apply for a new Extent.

Related code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.