frostfs-node/pkg/local_object_storage/shard/mode.go
Pavel Karpy 375394dc99 [#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>
2021-12-30 14:14:48 +03:00

54 lines
1.1 KiB
Go

package shard
import "errors"
// Mode represents enumeration of Shard work modes.
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.
const (
// ModeReadWrite is a Mode value for shard that is available
// for read and write operations. Default shard mode.
ModeReadWrite Mode = iota
// ModeReadOnly is a Mode value for shard that does not
// accept write operation but is readable.
ModeReadOnly
)
func (m Mode) String() string {
switch m {
default:
return "UNDEFINED"
case ModeReadWrite:
return "READ_WRITE"
case ModeReadOnly:
return "READ_ONLY"
}
}
// SetMode sets mode of the shard.
//
// Returns any error encountered that did not allow
// setting shard mode.
func (s *Shard) SetMode(m Mode) error {
s.m.Lock()
defer s.m.Unlock()
s.info.Mode = m
return nil
}
// GetMode returns mode of the shard.
func (s *Shard) GetMode() Mode {
s.m.RLock()
defer s.m.RUnlock()
return s.info.Mode
}