From 8f4ee1aded25f28f86f070ce4cd3131e4e170468 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 16 May 2022 16:02:35 +0300 Subject: [PATCH] [#1333] local_object_storage: Support ReadOnly mode in pilorama The tricky part here is the engine itself: we stop iteration on `ErrReadOnly` because it is better to synchronize the shard later than to have partial trees stored in 2 shards. Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/engine/tree.go | 12 ++++++++++++ pkg/local_object_storage/shard/tree.go | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/local_object_storage/engine/tree.go b/pkg/local_object_storage/engine/tree.go index 43ac27f5..41576132 100644 --- a/pkg/local_object_storage/engine/tree.go +++ b/pkg/local_object_storage/engine/tree.go @@ -1,7 +1,10 @@ package engine import ( + "errors" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id" "go.uber.org/zap" ) @@ -19,6 +22,9 @@ func (e *StorageEngine) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pil zap.Stringer("cid", d.CID), zap.String("tree", treeID), zap.String("err", err.Error())) + if errors.Is(err, shard.ErrReadOnlyMode) { + return nil, err + } continue } return lm, nil @@ -37,6 +43,9 @@ func (e *StorageEngine) TreeAddByPath(d pilorama.CIDDescriptor, treeID string, a zap.Stringer("cid", d.CID), zap.String("tree", treeID), zap.String("err", err.Error())) + if errors.Is(err, shard.ErrReadOnlyMode) { + return nil, err + } continue } return lm, nil @@ -54,6 +63,9 @@ func (e *StorageEngine) TreeApply(d pilorama.CIDDescriptor, treeID string, m *pi zap.Stringer("cid", d.CID), zap.String("tree", treeID), zap.String("err", err.Error())) + if errors.Is(err, shard.ErrReadOnlyMode) { + return err + } continue } return nil diff --git a/pkg/local_object_storage/shard/tree.go b/pkg/local_object_storage/shard/tree.go index fae5e534..33f120a9 100644 --- a/pkg/local_object_storage/shard/tree.go +++ b/pkg/local_object_storage/shard/tree.go @@ -9,16 +9,25 @@ var _ pilorama.Forest = (*Shard)(nil) // TreeMove implements the pilorama.Forest interface. func (s *Shard) TreeMove(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) (*pilorama.LogMove, error) { + if s.GetMode() != ModeReadWrite { + return nil, ErrReadOnlyMode + } return s.pilorama.TreeMove(d, treeID, m) } // TreeAddByPath implements the pilorama.Forest interface. func (s *Shard) TreeAddByPath(d pilorama.CIDDescriptor, treeID string, attr string, path []string, meta []pilorama.KeyValue) ([]pilorama.LogMove, error) { + if s.GetMode() != ModeReadWrite { + return nil, ErrReadOnlyMode + } return s.pilorama.TreeAddByPath(d, treeID, attr, path, meta) } // TreeApply implements the pilorama.Forest interface. func (s *Shard) TreeApply(d pilorama.CIDDescriptor, treeID string, m *pilorama.Move) error { + if s.GetMode() != ModeReadWrite { + return ErrReadOnlyMode + } return s.pilorama.TreeApply(d, treeID, m) }