From 3fa3661cad1bb1ea1d6d00c31d755dd911bcbc1c Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 19 Nov 2020 15:56:10 +0300 Subject: [PATCH] [#188] shard: Implement SetMode method Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/shard/mode.go | 12 ++++++++++++ pkg/local_object_storage/shard/shard.go | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/pkg/local_object_storage/shard/mode.go b/pkg/local_object_storage/shard/mode.go index 75377248e..fa264846e 100644 --- a/pkg/local_object_storage/shard/mode.go +++ b/pkg/local_object_storage/shard/mode.go @@ -40,3 +40,15 @@ func (m Mode) String() string { return "EVACUATE" } } + +// SetMode sets mode of the shard. +// +// Returns any error encountered that did not allow +// to set shard mode. +func (s *Shard) SetMode(m Mode) error { + s.mode.Store(uint32(m)) +} + +func (s *Shard) getMode() Mode { + return Mode(s.mode.Load()) +} diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index 54bcb7336..14773de6e 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -4,12 +4,15 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-node/pkg/util/logger" + "go.uber.org/atomic" ) // Shard represents single shard of NeoFS Local Storage Engine. type Shard struct { *cfg + mode *atomic.Uint32 + weight WeightValues blobStor *blobstor.BlobStor @@ -44,6 +47,7 @@ func New(opts ...Option) *Shard { return &Shard{ cfg: c, + mode: atomic.NewUint32(0), // TODO: init with particular mode blobStor: blobstor.New(c.blobOpts...), metaBase: meta.NewDB(c.metaOpts...), }