[#1559] local_object_storage: Move shard.Mode to a separate package

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-28 17:05:08 +03:00 committed by fyrchik
parent d8ba954aff
commit 339864b720
26 changed files with 134 additions and 133 deletions

View file

@ -3,20 +3,8 @@ package writecache
import (
"errors"
"time"
)
// Mode represents write-cache mode of operation.
type Mode uint32
const (
// ModeReadWrite is a default mode allowing objects to be flushed.
ModeReadWrite Mode = iota
// ModeReadOnly is a mode in which write-cache doesn't flush anything to a metabase.
ModeReadOnly
// ModeDegraded is similar to a shard's degraded mode.
ModeDegraded
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
)
// ErrReadOnly is returned when Put/Write is performed in a read-only mode.
@ -25,7 +13,7 @@ var ErrReadOnly = errors.New("write-cache is in read-only mode")
// SetMode sets write-cache mode of operation.
// When shard is put in read-only mode all objects in memory are flushed to disk
// and all background jobs are suspended.
func (c *cache) SetMode(m Mode) {
func (c *cache) SetMode(m mode.Mode) {
c.modeMtx.Lock()
defer c.modeMtx.Unlock()
if c.mode == m {
@ -33,7 +21,7 @@ func (c *cache) SetMode(m Mode) {
}
c.mode = m
if m == ModeReadWrite {
if m == mode.ReadWrite {
return
}
@ -57,5 +45,5 @@ func (c *cache) SetMode(m Mode) {
// readOnly returns true if current mode is read-only.
// `c.modeMtx` must be taken.
func (c *cache) readOnly() bool {
return c.mode != ModeReadWrite
return c.mode != mode.ReadWrite
}

View file

@ -4,6 +4,7 @@ import (
"sync"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"go.etcd.io/bbolt"
@ -23,7 +24,7 @@ type Cache interface {
Delete(oid.Address) error
Iterate(IterationPrm) error
Put(*object.Object) error
SetMode(Mode)
SetMode(mode.Mode)
SetLogger(*zap.Logger)
DumpInfo() Info
@ -39,7 +40,7 @@ type cache struct {
mtx sync.RWMutex
mem []objectInfo
mode Mode
mode mode.Mode
modeMtx sync.RWMutex
// compressFlags maps address of a big object to boolean value indicating
@ -90,7 +91,7 @@ func New(opts ...Option) Cache {
metaCh: make(chan *object.Object),
closeCh: make(chan struct{}),
evictCh: make(chan []byte),
mode: ModeReadWrite,
mode: mode.ReadWrite,
compressFlags: make(map[string]struct{}),
options: options{
@ -152,7 +153,7 @@ func (c *cache) Init() error {
// Close closes db connection and stops services. Executes ObjectCounters.FlushAndClose op.
func (c *cache) Close() error {
// Finish all in-progress operations.
c.SetMode(ModeReadOnly)
c.SetMode(mode.ReadOnly)
close(c.closeCh)
c.objCounters.FlushAndClose()