[#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>
remotes/fyrchik/single-rand
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
// blobStor.
func (s *Shard) Delete(prm *DeletePrm) (*DeleteRes, error) {
if s.getMode() == ModeReadOnly {
if s.GetMode() == ModeReadOnly {
return nil, ErrReadOnlyMode
}

View File

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

View File

@ -11,6 +11,9 @@ type Info struct {
// Identifier of the shard.
ID *ID
// Shard mode.
Mode Mode
// Information about the metabase.
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.
func (s *Shard) Inhume(prm *InhumePrm) (*InhumeRes, error) {
if s.getMode() == ModeReadOnly {
if s.GetMode() == ModeReadOnly {
return nil, ErrReadOnlyMode
}

View File

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

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
// another shard.
func (s *Shard) ToMoveIt(prm *ToMoveItPrm) (*ToMoveItRes, error) {
if s.getMode() == ModeReadOnly {
if s.GetMode() == ModeReadOnly {
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.
func (s *Shard) Put(prm *PutPrm) (*PutRes, error) {
if s.getMode() == ModeReadOnly {
if s.GetMode() == ModeReadOnly {
return nil, ErrReadOnlyMode
}

View File

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