From 7cc0986e0cf8b205e04e70ded92a9de917a1d654 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 15 Nov 2022 17:53:23 +0300 Subject: [PATCH] [#2057] meta: Fail write operations in R/O mode Signed-off-by: Pavel Karpy --- pkg/local_object_storage/metabase/control.go | 5 +++++ pkg/local_object_storage/metabase/delete.go | 2 ++ pkg/local_object_storage/metabase/graveyard.go | 2 ++ pkg/local_object_storage/metabase/inhume.go | 2 ++ pkg/local_object_storage/metabase/lock.go | 2 ++ pkg/local_object_storage/metabase/movable.go | 4 ++++ pkg/local_object_storage/metabase/put.go | 2 ++ pkg/local_object_storage/metabase/shard_id.go | 2 ++ pkg/local_object_storage/metabase/storage_id.go | 2 ++ 9 files changed, 23 insertions(+) diff --git a/pkg/local_object_storage/metabase/control.go b/pkg/local_object_storage/metabase/control.go index 23e99a4fb..7292827e5 100644 --- a/pkg/local_object_storage/metabase/control.go +++ b/pkg/local_object_storage/metabase/control.go @@ -15,6 +15,9 @@ import ( // ErrDegradedMode is returned when metabase is in a degraded mode. var ErrDegradedMode = logicerr.New("metabase is in a degraded mode") +// ErrReadOnlyMode is returned when metabase is in a read-only mode. +var ErrReadOnlyMode = logicerr.New("metabase is in a read-only mode") + // Open boltDB instance for metabase. func (db *DB) Open(readOnly bool) error { err := util.MkdirAllX(filepath.Dir(db.info.Path), db.info.Permission) @@ -159,6 +162,8 @@ func (db *DB) SyncCounters() error { if db.mode.NoMetabase() { return ErrDegradedMode + } else if db.mode.ReadOnly() { + return ErrReadOnlyMode } return db.boltDB.Update(func(tx *bbolt.Tx) error { diff --git a/pkg/local_object_storage/metabase/delete.go b/pkg/local_object_storage/metabase/delete.go index c990844c7..772abb15a 100644 --- a/pkg/local_object_storage/metabase/delete.go +++ b/pkg/local_object_storage/metabase/delete.go @@ -59,6 +59,8 @@ func (db *DB) Delete(prm DeletePrm) (DeleteRes, error) { if db.mode.NoMetabase() { return DeleteRes{}, ErrDegradedMode + } else if db.mode.ReadOnly() { + return DeleteRes{}, ErrReadOnlyMode } var rawRemoved uint64 diff --git a/pkg/local_object_storage/metabase/graveyard.go b/pkg/local_object_storage/metabase/graveyard.go index f079119b8..00320c1f8 100644 --- a/pkg/local_object_storage/metabase/graveyard.go +++ b/pkg/local_object_storage/metabase/graveyard.go @@ -237,6 +237,8 @@ func (db *DB) DropGraves(tss []TombstonedObject) error { if db.mode.NoMetabase() { return ErrDegradedMode + } else if db.mode.ReadOnly() { + return ErrReadOnlyMode } buf := make([]byte, addressKeySize) diff --git a/pkg/local_object_storage/metabase/inhume.go b/pkg/local_object_storage/metabase/inhume.go index 7e6ec0914..ab00ddd95 100644 --- a/pkg/local_object_storage/metabase/inhume.go +++ b/pkg/local_object_storage/metabase/inhume.go @@ -95,6 +95,8 @@ func (db *DB) Inhume(prm InhumePrm) (res InhumeRes, err error) { if db.mode.NoMetabase() { return InhumeRes{}, ErrDegradedMode + } else if db.mode.ReadOnly() { + return InhumeRes{}, ErrReadOnlyMode } currEpoch := db.epochState.CurrentEpoch() diff --git a/pkg/local_object_storage/metabase/lock.go b/pkg/local_object_storage/metabase/lock.go index dbd37a8cf..4c167f4a9 100644 --- a/pkg/local_object_storage/metabase/lock.go +++ b/pkg/local_object_storage/metabase/lock.go @@ -31,6 +31,8 @@ func (db *DB) Lock(cnr cid.ID, locker oid.ID, locked []oid.ID) error { if db.mode.NoMetabase() { return ErrDegradedMode + } else if db.mode.ReadOnly() { + return ErrReadOnlyMode } if len(locked) == 0 { diff --git a/pkg/local_object_storage/metabase/movable.go b/pkg/local_object_storage/metabase/movable.go index 22538d0b2..42e9689cb 100644 --- a/pkg/local_object_storage/metabase/movable.go +++ b/pkg/local_object_storage/metabase/movable.go @@ -54,6 +54,8 @@ func (db *DB) ToMoveIt(prm ToMoveItPrm) (res ToMoveItRes, err error) { if db.mode.NoMetabase() { return res, ErrDegradedMode + } else if db.mode.ReadOnly() { + return res, ErrReadOnlyMode } key := make([]byte, addressKeySize) @@ -74,6 +76,8 @@ func (db *DB) DoNotMove(prm DoNotMovePrm) (res DoNotMoveRes, err error) { if db.mode.NoMetabase() { return res, ErrDegradedMode + } else if db.mode.ReadOnly() { + return res, ErrReadOnlyMode } key := make([]byte, addressKeySize) diff --git a/pkg/local_object_storage/metabase/put.go b/pkg/local_object_storage/metabase/put.go index 5d4787805..c5ab5cfde 100644 --- a/pkg/local_object_storage/metabase/put.go +++ b/pkg/local_object_storage/metabase/put.go @@ -58,6 +58,8 @@ func (db *DB) Put(prm PutPrm) (res PutRes, err error) { if db.mode.NoMetabase() { return res, ErrDegradedMode + } else if db.mode.ReadOnly() { + return res, ErrReadOnlyMode } currEpoch := db.epochState.CurrentEpoch() diff --git a/pkg/local_object_storage/metabase/shard_id.go b/pkg/local_object_storage/metabase/shard_id.go index 5a4afe413..fac8a079f 100644 --- a/pkg/local_object_storage/metabase/shard_id.go +++ b/pkg/local_object_storage/metabase/shard_id.go @@ -38,6 +38,8 @@ func (db *DB) WriteShardID(id []byte) error { if db.mode.NoMetabase() { return ErrDegradedMode + } else if db.mode.ReadOnly() { + return ErrReadOnlyMode } return db.boltDB.Update(func(tx *bbolt.Tx) error { diff --git a/pkg/local_object_storage/metabase/storage_id.go b/pkg/local_object_storage/metabase/storage_id.go index 3fed824c5..1c628a1eb 100644 --- a/pkg/local_object_storage/metabase/storage_id.go +++ b/pkg/local_object_storage/metabase/storage_id.go @@ -86,6 +86,8 @@ func (db *DB) UpdateStorageID(prm UpdateStorageIDPrm) (res UpdateStorageIDRes, e if db.mode.NoMetabase() { return res, ErrDegradedMode + } else if db.mode.ReadOnly() { + return res, ErrReadOnlyMode } currEpoch := db.epochState.CurrentEpoch()