Skip to content

Commit

Permalink
add comment about read-only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesnikovae committed Nov 19, 2024
1 parent 86727e3 commit f99ad46
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/experiment/metastore/fsm/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ func newDB(logger log.Logger, metrics *metrics, dir string) *boltdb {
}
}

// open creates a new or opens an existing boltdb database.
//
// The only case when we open the database in read-only mode is when we
// restore it from a snapshot: before closing the database being in-use,
// we open the snapshot in read-only mode to verify its integrity.
//
// Read-only mode guarantees the snapshot won't be corrupted by the current
// process, and allows loading the database more quickly (by skipping the
// free page list preload).
func (db *boltdb) open(readOnly bool) (err error) {
defer func() {
if err != nil {
Expand All @@ -53,7 +62,6 @@ func (db *boltdb) open(readOnly bool) (err error) {
}

opts := *bbolt.DefaultOptions
// open is called with readOnly=true to verify the snapshot integrity.
opts.ReadOnly = readOnly
opts.PreLoadFreelist = !readOnly
opts.InitialMmapSize = boltDBInitialMmapSize
Expand Down

0 comments on commit f99ad46

Please sign in to comment.