[#1059] shard: Add shard mode to shard Info

Provide shard mode information via `DumpInfo()`. Delete atomic field from
Shard structure since it duplicates new field.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-12-27 21:07:02 +03:00 committed by Alex Vanin
parent 86b90eb944
commit 375394dc99
8 changed files with 22 additions and 12 deletions

View file

@ -33,7 +33,7 @@ func (p *DeletePrm) WithAddresses(addr ...*objectSDK.Address) *DeletePrm {
// Delete removes data from the shard's writeCache, metaBase and // Delete removes data from the shard's writeCache, metaBase and
// blobStor. // blobStor.
func (s *Shard) Delete(prm *DeletePrm) (*DeleteRes, error) { func (s *Shard) Delete(prm *DeletePrm) (*DeleteRes, error) {
if s.getMode() == ModeReadOnly { if s.GetMode() == ModeReadOnly {
return nil, ErrReadOnlyMode return nil, ErrReadOnlyMode
} }

View file

@ -173,7 +173,7 @@ func (gc *gc) stop() {
// with GC-marked graves. // with GC-marked graves.
// Does nothing if shard is in "read-only" mode. // Does nothing if shard is in "read-only" mode.
func (s *Shard) removeGarbage() { func (s *Shard) removeGarbage() {
if s.getMode() == ModeReadOnly { if s.GetMode() == ModeReadOnly {
return return
} }

View file

@ -11,6 +11,9 @@ type Info struct {
// Identifier of the shard. // Identifier of the shard.
ID *ID ID *ID
// Shard mode.
Mode Mode
// Information about the metabase. // Information about the metabase.
MetaBaseInfo meta.Info MetaBaseInfo meta.Info

View file

@ -46,7 +46,7 @@ func (p *InhumePrm) MarkAsGarbage(addr ...*objectSDK.Address) *InhumePrm {
// //
// Returns ErrReadOnlyMode error if shard is in "read-only" mode. // Returns ErrReadOnlyMode error if shard is in "read-only" mode.
func (s *Shard) Inhume(prm *InhumePrm) (*InhumeRes, error) { func (s *Shard) Inhume(prm *InhumePrm) (*InhumeRes, error) {
if s.getMode() == ModeReadOnly { if s.GetMode() == ModeReadOnly {
return nil, ErrReadOnlyMode return nil, ErrReadOnlyMode
} }

View file

@ -37,11 +37,18 @@ func (m Mode) String() string {
// Returns any error encountered that did not allow // Returns any error encountered that did not allow
// setting shard mode. // setting shard mode.
func (s *Shard) SetMode(m Mode) error { 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 return nil
} }
func (s *Shard) getMode() Mode { // GetMode returns mode of the shard.
return Mode(s.mode.Load()) func (s *Shard) GetMode() Mode {
s.m.RLock()
defer s.m.RUnlock()
return s.info.Mode
} }

View file

@ -27,7 +27,7 @@ func (p *ToMoveItPrm) WithAddress(addr *objectSDK.Address) *ToMoveItPrm {
// ToMoveIt calls metabase.ToMoveIt method to mark object as relocatable to // ToMoveIt calls metabase.ToMoveIt method to mark object as relocatable to
// another shard. // another shard.
func (s *Shard) ToMoveIt(prm *ToMoveItPrm) (*ToMoveItRes, error) { func (s *Shard) ToMoveIt(prm *ToMoveItPrm) (*ToMoveItRes, error) {
if s.getMode() == ModeReadOnly { if s.GetMode() == ModeReadOnly {
return nil, ErrReadOnlyMode return nil, ErrReadOnlyMode
} }

View file

@ -33,7 +33,7 @@ func (p *PutPrm) WithObject(obj *object.Object) *PutPrm {
// //
// Returns ErrReadOnlyMode error if shard is in "read-only" mode. // Returns ErrReadOnlyMode error if shard is in "read-only" mode.
func (s *Shard) Put(prm *PutPrm) (*PutRes, error) { func (s *Shard) Put(prm *PutPrm) (*PutRes, error) {
if s.getMode() == ModeReadOnly { if s.GetMode() == ModeReadOnly {
return nil, ErrReadOnlyMode return nil, ErrReadOnlyMode
} }

View file

@ -2,6 +2,7 @@ package shard
import ( import (
"context" "context"
"sync"
"time" "time"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" "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"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
"go.uber.org/atomic"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -34,7 +34,7 @@ type Option func(*cfg)
type ExpiredObjectsCallback func(context.Context, []*object.Address) type ExpiredObjectsCallback func(context.Context, []*object.Address)
type cfg struct { type cfg struct {
mode *atomic.Uint32 m sync.RWMutex
refillMetabase bool refillMetabase bool
@ -59,7 +59,6 @@ type cfg struct {
func defaultCfg() *cfg { func defaultCfg() *cfg {
return &cfg{ return &cfg{
mode: atomic.NewUint32(uint32(ModeReadWrite)),
rmBatchSize: 100, rmBatchSize: 100,
log: zap.L(), log: zap.L(),
gcCfg: defaultGCCfg(), gcCfg: defaultGCCfg(),
@ -202,13 +201,14 @@ func WithRefillMetabase(v bool) Option {
// - ModeReadOnly. // - ModeReadOnly.
func WithMode(v Mode) Option { func WithMode(v Mode) Option {
return func(c *cfg) { return func(c *cfg) {
c.mode.Store(uint32(v)) c.info.Mode = v
} }
} }
func (s *Shard) fillInfo() { func (s *Shard) fillInfo() {
s.cfg.info.MetaBaseInfo = s.metaBase.DumpInfo() s.cfg.info.MetaBaseInfo = s.metaBase.DumpInfo()
s.cfg.info.BlobStorInfo = s.blobStor.DumpInfo() s.cfg.info.BlobStorInfo = s.blobStor.DumpInfo()
s.cfg.info.Mode = s.GetMode()
if s.cfg.useWriteCache { if s.cfg.useWriteCache {
s.cfg.info.WriteCacheInfo = s.writeCache.DumpInfo() s.cfg.info.WriteCacheInfo = s.writeCache.DumpInfo()