[#1559] local_object_storage: Provide readOnly flag to Open

We should be able to reopen storage in readonly in runtime.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-28 16:42:50 +03:00 committed by fyrchik
parent e38b0aa4ba
commit 1e786233bf
20 changed files with 70 additions and 49 deletions

View file

@ -10,7 +10,7 @@ import (
)
// Open boltDB instance for metabase.
func (db *DB) Open() error {
func (db *DB) Open(readOnly bool) error {
err := util.MkdirAllX(filepath.Dir(db.info.Path), db.info.Permission)
if err != nil {
return fmt.Errorf("can't create dir %s for metabase: %w", db.info.Path, err)
@ -18,6 +18,11 @@ func (db *DB) Open() error {
db.log.Debug("created directory for Metabase", zap.String("path", db.info.Path))
if db.boltOptions == nil {
db.boltOptions = bbolt.DefaultOptions
}
db.boltOptions.ReadOnly = readOnly
db.boltDB, err = bbolt.Open(db.info.Path, db.info.Permission, db.boltOptions)
if err != nil {
return fmt.Errorf("can't open boltDB database: %w", err)