2020-11-19 12:41:10 +00:00
|
|
|
package shard
|
|
|
|
|
2021-12-27 11:03:15 +00:00
|
|
|
import "errors"
|
|
|
|
|
2020-11-19 12:41:10 +00:00
|
|
|
// Mode represents enumeration of Shard work modes.
|
|
|
|
type Mode uint32
|
|
|
|
|
2021-12-27 11:03:15 +00:00
|
|
|
// 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")
|
|
|
|
|
2020-11-19 12:41:10 +00:00
|
|
|
// TODO: more detailed description of shard modes.
|
|
|
|
|
|
|
|
const (
|
2021-12-27 11:03:15 +00:00
|
|
|
// ModeReadWrite is a Mode value for shard that is available
|
|
|
|
// for read and write operations. Default shard mode.
|
|
|
|
ModeReadWrite Mode = iota
|
2020-11-19 12:41:10 +00:00
|
|
|
|
2021-12-27 11:03:15 +00:00
|
|
|
// ModeReadOnly is a Mode value for shard that does not
|
|
|
|
// accept write operation but is readable.
|
2020-11-19 12:41:10 +00:00
|
|
|
ModeReadOnly
|
|
|
|
)
|
|
|
|
|
|
|
|
func (m Mode) String() string {
|
|
|
|
switch m {
|
|
|
|
default:
|
|
|
|
return "UNDEFINED"
|
2021-12-27 11:03:15 +00:00
|
|
|
case ModeReadWrite:
|
|
|
|
return "READ_WRITE"
|
2020-11-19 12:41:10 +00:00
|
|
|
case ModeReadOnly:
|
|
|
|
return "READ_ONLY"
|
|
|
|
}
|
|
|
|
}
|
2020-11-19 12:56:10 +00:00
|
|
|
|
|
|
|
// SetMode sets mode of the shard.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that did not allow
|
2021-12-27 11:03:15 +00:00
|
|
|
// setting shard mode.
|
2020-11-19 12:56:10 +00:00
|
|
|
func (s *Shard) SetMode(m Mode) error {
|
|
|
|
s.mode.Store(uint32(m))
|
2020-11-19 13:51:58 +00:00
|
|
|
|
|
|
|
return nil
|
2020-11-19 12:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) getMode() Mode {
|
|
|
|
return Mode(s.mode.Load())
|
|
|
|
}
|