in tx.go [576:616]
func (tx *Tx) tryCommitChangesToFile(
csWAL *walCommitState,
csAlloc *allocCommitState,
) (metaID int, err reason) {
newMetaBuf := tx.prepareMetaBuffer()
newMeta := newMetaBuf.cast()
newMeta.root.Set(tx.rootID) // update data root
// 2. allocate new file pages for new meta data to be written
if err := tx.file.wal.fileCommitAlloc(tx, csWAL); err != nil {
return metaID, err
}
csAlloc.updated = csAlloc.updated || len(csWAL.allocRegions) > 0
if err := tx.file.allocator.fileCommitAlloc(csAlloc); err != nil {
return metaID, err
}
// 3. serialize page mappings and new freelist
err = tx.file.wal.fileCommitSerialize(csWAL, uint(tx.PageSize()), tx.scheduleCommitMetaWrite)
if err != nil {
return metaID, err
}
err = tx.file.allocator.fileCommitSerialize(csAlloc, tx.scheduleCommitMetaWrite)
if err != nil {
return metaID, err
}
// 4. sync all new contents and metadata before updating the ondisk meta page.
tx.file.writer.Sync(tx.writeSync, syncDataOnly)
// 5. finalize on-disk transaction by writing new meta page.
tx.file.wal.fileCommitMeta(newMeta, csWAL)
tx.file.allocator.fileCommitMeta(newMeta, csAlloc)
metaID = tx.syncNewMeta(&newMetaBuf)
// 6. wait for all pages beeing written and synced,
// before updating in memory state.
return metaID, nil
}