diff --git a/pkg/local_object_storage/shard/delete.go b/pkg/local_object_storage/shard/delete.go index 6ea7897b6..2b162ce45 100644 --- a/pkg/local_object_storage/shard/delete.go +++ b/pkg/local_object_storage/shard/delete.go @@ -33,7 +33,7 @@ func (p *DeletePrm) WithAddresses(addr ...*objectSDK.Address) *DeletePrm { // Delete removes data from the shard's writeCache, metaBase and // blobStor. func (s *Shard) Delete(prm *DeletePrm) (*DeleteRes, error) { - if s.getMode() == ModeReadOnly { + if s.GetMode() == ModeReadOnly { return nil, ErrReadOnlyMode } diff --git a/pkg/local_object_storage/shard/gc.go b/pkg/local_object_storage/shard/gc.go index b29029fb6..7222d8307 100644 --- a/pkg/local_object_storage/shard/gc.go +++ b/pkg/local_object_storage/shard/gc.go @@ -173,7 +173,7 @@ func (gc *gc) stop() { // with GC-marked graves. // Does nothing if shard is in "read-only" mode. func (s *Shard) removeGarbage() { - if s.getMode() == ModeReadOnly { + if s.GetMode() == ModeReadOnly { return } diff --git a/pkg/local_object_storage/shard/info.go b/pkg/local_object_storage/shard/info.go index 4c59e6172..962dca29b 100644 --- a/pkg/local_object_storage/shard/info.go +++ b/pkg/local_object_storage/shard/info.go @@ -11,6 +11,9 @@ type Info struct { // Identifier of the shard. ID *ID + // Shard mode. + Mode Mode + // Information about the metabase. MetaBaseInfo meta.Info diff --git a/pkg/local_object_storage/shard/inhume.go b/pkg/local_object_storage/shard/inhume.go index 4a17831dc..7bcad9d86 100644 --- a/pkg/local_object_storage/shard/inhume.go +++ b/pkg/local_object_storage/shard/inhume.go @@ -46,7 +46,7 @@ func (p *InhumePrm) MarkAsGarbage(addr ...*objectSDK.Address) *InhumePrm { // // Returns ErrReadOnlyMode error if shard is in "read-only" mode. func (s *Shard) Inhume(prm *InhumePrm) (*InhumeRes, error) { - if s.getMode() == ModeReadOnly { + if s.GetMode() == ModeReadOnly { return nil, ErrReadOnlyMode } diff --git a/pkg/local_object_storage/shard/mode.go b/pkg/local_object_storage/shard/mode.go index d1e370cf2..428850e19 100644 --- a/pkg/local_object_storage/shard/mode.go +++ b/pkg/local_object_storage/shard/mode.go @@ -37,11 +37,18 @@ func (m Mode) String() string { // Returns any error encountered that did not allow // setting shard mode. func (s *Shard) SetMode(m Mode) error { - s.mode.Store(uint32(m)) + s.m.Lock() + defer s.m.Unlock() + + s.info.Mode = m return nil } -func (s *Shard) getMode() Mode { - return Mode(s.mode.Load()) +// GetMode returns mode of the shard. +func (s *Shard) GetMode() Mode { + s.m.RLock() + defer s.m.RUnlock() + + return s.info.Mode } diff --git a/pkg/local_object_storage/shard/move.go b/pkg/local_object_storage/shard/move.go index f9b963c5c..d34c8eb03 100644 --- a/pkg/local_object_storage/shard/move.go +++ b/pkg/local_object_storage/shard/move.go @@ -27,7 +27,7 @@ func (p *ToMoveItPrm) WithAddress(addr *objectSDK.Address) *ToMoveItPrm { // ToMoveIt calls metabase.ToMoveIt method to mark object as relocatable to // another shard. func (s *Shard) ToMoveIt(prm *ToMoveItPrm) (*ToMoveItRes, error) { - if s.getMode() == ModeReadOnly { + if s.GetMode() == ModeReadOnly { return nil, ErrReadOnlyMode } diff --git a/pkg/local_object_storage/shard/put.go b/pkg/local_object_storage/shard/put.go index 2a17eae00..06bcc6dc2 100644 --- a/pkg/local_object_storage/shard/put.go +++ b/pkg/local_object_storage/shard/put.go @@ -33,7 +33,7 @@ func (p *PutPrm) WithObject(obj *object.Object) *PutPrm { // // Returns ErrReadOnlyMode error if shard is in "read-only" mode. func (s *Shard) Put(prm *PutPrm) (*PutRes, error) { - if s.getMode() == ModeReadOnly { + if s.GetMode() == ModeReadOnly { return nil, ErrReadOnlyMode } diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index 32f4affcc..d097d7b24 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -2,6 +2,7 @@ package shard import ( "context" + "sync" "time" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" @@ -10,7 +11,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-sdk-go/object" - "go.uber.org/atomic" "go.uber.org/zap" ) @@ -34,7 +34,7 @@ type Option func(*cfg) type ExpiredObjectsCallback func(context.Context, []*object.Address) type cfg struct { - mode *atomic.Uint32 + m sync.RWMutex refillMetabase bool @@ -59,7 +59,6 @@ type cfg struct { func defaultCfg() *cfg { return &cfg{ - mode: atomic.NewUint32(uint32(ModeReadWrite)), rmBatchSize: 100, log: zap.L(), gcCfg: defaultGCCfg(), @@ -202,13 +201,14 @@ func WithRefillMetabase(v bool) Option { // - ModeReadOnly. func WithMode(v Mode) Option { return func(c *cfg) { - c.mode.Store(uint32(v)) + c.info.Mode = v } } func (s *Shard) fillInfo() { s.cfg.info.MetaBaseInfo = s.metaBase.DumpInfo() s.cfg.info.BlobStorInfo = s.blobStor.DumpInfo() + s.cfg.info.Mode = s.GetMode() if s.cfg.useWriteCache { s.cfg.info.WriteCacheInfo = s.writeCache.DumpInfo()