[#1057] shard: Make shard to have only two mode

Shard's mode was not used in the Node, so added only two modes whose roles
are clear. More modes will be added in the future.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-12-27 14:03:15 +03:00 committed by Pavel Karpy
parent 2109211c55
commit 4f756bf121

View file

@ -1,50 +1,41 @@
package shard package shard
import "errors"
// Mode represents enumeration of Shard work modes. // Mode represents enumeration of Shard work modes.
type Mode uint32 type Mode uint32
// ErrReadOnlyMode is returned when it is impossible to apply operation
// that changes shard's memory due to the "read-only" shard's mode.
var ErrReadOnlyMode = errors.New("shard is in read-only mode")
// TODO: more detailed description of shard modes. // TODO: more detailed description of shard modes.
const ( const (
_ Mode = iota // ModeReadWrite is a Mode value for shard that is available
// for read and write operations. Default shard mode.
ModeReadWrite Mode = iota
// ModeActive is a Mode value for active shard. // ModeReadOnly is a Mode value for shard that does not
ModeActive // accept write operation but is readable.
// ModeInactive is a Mode value for inactive shard.
ModeInactive
// ModeReadOnly is a Mode value for read-only shard.
ModeReadOnly ModeReadOnly
// ModeFault is a Mode value for faulty shard.
ModeFault
// ModeEvacuate is a Mode value for evacuating shard.
ModeEvacuate
) )
func (m Mode) String() string { func (m Mode) String() string {
switch m { switch m {
default: default:
return "UNDEFINED" return "UNDEFINED"
case ModeActive: case ModeReadWrite:
return "ACTIVE" return "READ_WRITE"
case ModeInactive:
return "INACTIVE"
case ModeReadOnly: case ModeReadOnly:
return "READ_ONLY" return "READ_ONLY"
case ModeFault:
return "FAULT"
case ModeEvacuate:
return "EVACUATE"
} }
} }
// SetMode sets mode of the shard. // SetMode sets mode of the shard.
// //
// Returns any error encountered that did not allow // Returns any error encountered that did not allow
// to set 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.mode.Store(uint32(m))