This is a created article in which the information may have evolved or changed.
Boltdb Startup and initialization
Based on the previous summary, boltdb
only a single file is used for persistence, and at boltdb
startup, the corresponding persistence file is opened, and then the file lock is obtained based on whether it is read-only mode. When it is not read-only, boltdb
an exclusive file lock is used to ensure that only one process can manipulate the file, preventing multiple processes from operating simultaneously, resulting in data corruption.
When the persisted file size is 0 o'clock, boltdb
the database is considered to be newly created, then initialized (writing 4 initial page), then the file is mapped to memory space and finally read from the mapped memory, meta0
meta1
data.
The Freelist pgid data is then read from the current Freelist page identified in the meta data, and the free page cache is then freelist based on that data. That is, a map is used to record which page is free.
This completes the startup and initialization.
Because the boltdb
key-value operation is updated directly through the B-tree index, the data is written directly to the specified file page, so there is only one write and no log to maintain boltdb
the crash consistency.