[#1121] node: Change mode of shard components

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
Alexander Chuprov 2024-06-04 16:28:47 +03:00 committed by Evgenii Stratonikov
parent 6f2187a420
commit 806236da78
47 changed files with 194 additions and 100 deletions

View file

@ -3,12 +3,13 @@ package teststore
import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/compression"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
)
type cfg struct {
st common.Storage
overrides struct {
Open func(readOnly bool) error
Open func(mode mode.ComponentMode) error
Init func() error
Close func() error
@ -35,9 +36,9 @@ func WithSubstorage(st common.Storage) Option {
}
}
func WithOpen(f func(bool) error) Option { return func(c *cfg) { c.overrides.Open = f } }
func WithInit(f func() error) Option { return func(c *cfg) { c.overrides.Init = f } }
func WithClose(f func() error) Option { return func(c *cfg) { c.overrides.Close = f } }
func WithOpen(f func(mode.ComponentMode) error) Option { return func(c *cfg) { c.overrides.Open = f } }
func WithInit(f func() error) Option { return func(c *cfg) { c.overrides.Init = f } }
func WithClose(f func() error) Option { return func(c *cfg) { c.overrides.Close = f } }
func WithType(f func() string) Option { return func(c *cfg) { c.overrides.Type = f } }
func WithPath(f func() string) Option { return func(c *cfg) { c.overrides.Path = f } }

View file

@ -20,6 +20,7 @@ import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/compression"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
)
// TestStore is a common.Storage implementation for testing/mocking purposes.
@ -50,16 +51,16 @@ func (s *TestStore) SetOption(opt Option) {
opt(s.cfg)
}
func (s *TestStore) Open(readOnly bool) error {
func (s *TestStore) Open(mod mode.ComponentMode) error {
s.mu.RLock()
defer s.mu.RUnlock()
switch {
case s.overrides.Open != nil:
return s.overrides.Open(readOnly)
return s.overrides.Open(mod)
case s.st != nil:
return s.st.Open(readOnly)
return s.st.Open(mod)
default:
panic(fmt.Sprintf("unexpected storage call: Open(%v)", readOnly))
panic(fmt.Sprintf("unexpected storage call: Open(%v)", mod.String()))
}
}