MANIFEST
MANIFEST
handles the organization of VersionSet
and VersionEdit
into files. It is stored with names like MANIFEST-000000
.
The MANIFEST filename changes during LevelDB operations. The CURRENT
file contains the name of the MANIFEST file that LevelDB will use in the current session.
VersionSet and VersionEdit
Both VersionSet
and VersionEdit
manage version-related information.
VersionSet
and VersionEdit
are friend classes to each other.
Each class has one specific function for writing to and using the MANIFEST file:
VersionSet::LogAndApply
: Prepares version data for storage in MANIFEST and ultimately writes the data usingVersionEdit::EncodeTo
to save it to the MANIFEST file.
VersionEdit::EncodeTo
: Writes the actual data in binary format.
During DB Creation
When initially creating the DB, the MANIFEST file is generated through the above process. Initially, a VersionEdit
is created with the following values and written to the MANIFEST-000001
file:
comparator
:"leveldb.BytewiseComparator"
log_number
:0
next_file_number
:2
last_sequence
:0
These contents are then recorded through the log::Writer
function.
During DB Shutdown
When LevelDB shuts down, ~DBImpl
is called. This deletes the existing VersionSet
and writes the data about the current version to the MANIFEST file. This written MANIFEST file allows LevelDB to recover the previous version when it starts up next time.