[#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 <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-05-16 16:02:35 +03:00 committed by fyrchik
parent 735931c842
commit 8f4ee1aded
2 changed files with 21 additions and 0 deletions

View file

@ -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

View file

@ -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)
}