2022-06-28 14:05:08 +00:00
|
|
|
package mode
|
|
|
|
|
2022-10-05 11:40:37 +00:00
|
|
|
import "math"
|
|
|
|
|
2022-06-28 14:05:08 +00:00
|
|
|
// Mode represents enumeration of Shard work modes.
|
|
|
|
type Mode uint32
|
|
|
|
|
2022-07-18 11:44:29 +00:00
|
|
|
const (
|
|
|
|
// ReadWrite is a Mode value for shard that is available
|
|
|
|
// for read and write operations. Default shard mode.
|
|
|
|
ReadWrite Mode = 0
|
|
|
|
|
|
|
|
// DegradedReadOnly is a Mode value for shard that is set automatically
|
|
|
|
// after a certain number of errors is encountered. It is the same as
|
2022-07-19 13:12:37 +00:00
|
|
|
// `mode.Degraded` but also is read-only.
|
2022-07-18 11:44:29 +00:00
|
|
|
DegradedReadOnly = Degraded | ReadOnly
|
2022-10-05 11:40:37 +00:00
|
|
|
|
|
|
|
// Disabled mode is a mode where a shard is disabled.
|
|
|
|
// An existing shard can't have this mode, but it can be used in
|
|
|
|
// the configuration or control service commands.
|
|
|
|
Disabled = math.MaxUint32
|
2022-07-18 11:44:29 +00:00
|
|
|
)
|
2022-06-28 14:05:08 +00:00
|
|
|
|
2022-06-29 11:27:36 +00:00
|
|
|
const (
|
2022-06-28 14:05:08 +00:00
|
|
|
// ReadOnly is a Mode value for shard that does not
|
|
|
|
// accept write operation but is readable.
|
2022-06-29 11:27:36 +00:00
|
|
|
ReadOnly Mode = 1 << iota
|
2022-06-28 14:05:08 +00:00
|
|
|
|
2022-07-18 11:44:29 +00:00
|
|
|
// Degraded is a Mode value for shard when the metabase is unavailable.
|
|
|
|
// It is hard to perform some modifying operations in this mode, thus it can only be set by an administrator.
|
2022-06-28 14:05:08 +00:00
|
|
|
Degraded
|
|
|
|
)
|
|
|
|
|
|
|
|
func (m Mode) String() string {
|
|
|
|
switch m {
|
|
|
|
default:
|
|
|
|
return "UNDEFINED"
|
|
|
|
case ReadWrite:
|
|
|
|
return "READ_WRITE"
|
|
|
|
case ReadOnly:
|
|
|
|
return "READ_ONLY"
|
|
|
|
case Degraded:
|
2022-07-19 13:12:37 +00:00
|
|
|
return "DEGRADED_READ_WRITE"
|
2022-07-18 11:44:29 +00:00
|
|
|
case DegradedReadOnly:
|
|
|
|
return "DEGRADED_READ_ONLY"
|
2022-10-05 11:40:37 +00:00
|
|
|
case Disabled:
|
|
|
|
return "DISABLED"
|
2022-06-28 14:05:08 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-29 11:27:36 +00:00
|
|
|
|
|
|
|
// NoMetabase returns true iff m is operating without the metabase.
|
|
|
|
func (m Mode) NoMetabase() bool {
|
|
|
|
return m&Degraded != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadOnly returns true iff m prohibits modifying operations with shard.
|
|
|
|
func (m Mode) ReadOnly() bool {
|
|
|
|
return m&ReadOnly != 0
|
|
|
|
}
|
2023-06-20 08:59:18 +00:00
|
|
|
|
|
|
|
func (m Mode) Disabled() bool {
|
|
|
|
return m == Disabled
|
|
|
|
}
|