From f99ad4687866653069ea0e63c69a07e76eabf659 Mon Sep 17 00:00:00 2001 From: Anton Kolesnikov Date: Tue, 19 Nov 2024 11:27:10 +0800 Subject: [PATCH] add comment about read-only mode --- pkg/experiment/metastore/fsm/boltdb.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/experiment/metastore/fsm/boltdb.go b/pkg/experiment/metastore/fsm/boltdb.go index 09d67425cd..0b30e2ecdc 100644 --- a/pkg/experiment/metastore/fsm/boltdb.go +++ b/pkg/experiment/metastore/fsm/boltdb.go @@ -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 { @@ -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