2017-02-16 18:37:21 +00:00
|
|
|
package consts
|
|
|
|
|
2019-03-04 18:35:22 +00:00
|
|
|
const (
|
2021-04-08 16:43:39 +00:00
|
|
|
// N.B. This needs to be excluded from replication despite the name; it's
|
|
|
|
// merely saying that this is cluster information for the replicated
|
|
|
|
// cluster.
|
2019-03-04 18:35:22 +00:00
|
|
|
CoreReplicatedClusterPrefix = "core/cluster/replicated/"
|
|
|
|
CoreReplicatedClusterPrefixDR = "core/cluster/replicated-dr/"
|
|
|
|
|
|
|
|
CoreReplicatedClusterInfoPath = CoreReplicatedClusterPrefix + "info"
|
|
|
|
CoreReplicatedClusterSecondariesPrefix = CoreReplicatedClusterPrefix + "secondaries/"
|
|
|
|
CoreReplicatedClusterInfoPathDR = CoreReplicatedClusterPrefixDR + "info"
|
|
|
|
CoreReplicatedClusterSecondariesPrefixDR = CoreReplicatedClusterPrefixDR + "secondaries/"
|
2019-03-15 13:25:05 +00:00
|
|
|
|
|
|
|
// This is an identifier for the current secondary in the replicated paths
|
|
|
|
// manager. It should contain a character that is not allowed in secondary
|
|
|
|
// ids to ensure it doesn't collide.
|
|
|
|
CurrentReplicatedSecondaryIdentifier = ".current"
|
2020-02-19 23:06:53 +00:00
|
|
|
CoreFeatureFlagPath = "core/cluster/feature-flags"
|
2019-03-04 18:35:22 +00:00
|
|
|
)
|
|
|
|
|
2017-02-16 18:37:21 +00:00
|
|
|
type ReplicationState uint32
|
|
|
|
|
|
|
|
const (
|
2017-09-04 23:38:37 +00:00
|
|
|
_ ReplicationState = iota
|
|
|
|
OldReplicationPrimary
|
|
|
|
OldReplicationSecondary
|
|
|
|
OldReplicationBootstrapping
|
2018-02-23 02:38:52 +00:00
|
|
|
// Don't add anything here. Adding anything to this Old block would cause
|
|
|
|
// the rest of the values to change below. This was done originally to
|
|
|
|
// ensure no overlap between old and new values.
|
2017-09-04 23:38:37 +00:00
|
|
|
|
2018-01-23 02:44:38 +00:00
|
|
|
ReplicationUnknown ReplicationState = 0
|
2019-02-06 02:01:18 +00:00
|
|
|
ReplicationPerformancePrimary ReplicationState = 1 << iota // Note -- iota is 5 here!
|
2017-09-04 23:38:37 +00:00
|
|
|
ReplicationPerformanceSecondary
|
2018-01-23 02:44:38 +00:00
|
|
|
OldSplitReplicationBootstrapping
|
2017-09-04 23:38:37 +00:00
|
|
|
ReplicationDRPrimary
|
|
|
|
ReplicationDRSecondary
|
2018-01-23 02:44:38 +00:00
|
|
|
ReplicationPerformanceBootstrapping
|
|
|
|
ReplicationDRBootstrapping
|
|
|
|
ReplicationPerformanceDisabled
|
|
|
|
ReplicationDRDisabled
|
2018-08-24 16:09:03 +00:00
|
|
|
ReplicationPerformanceStandby
|
2017-02-16 18:37:21 +00:00
|
|
|
)
|
|
|
|
|
2019-03-04 18:35:22 +00:00
|
|
|
// We verify no change to the above values are made
|
|
|
|
func init() {
|
|
|
|
if OldReplicationBootstrapping != 3 {
|
|
|
|
panic("Replication Constants have changed")
|
|
|
|
}
|
|
|
|
|
|
|
|
if ReplicationPerformancePrimary != 1<<5 {
|
|
|
|
panic("Replication Constants have changed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-23 02:44:38 +00:00
|
|
|
func (r ReplicationState) string() string {
|
2017-02-16 18:37:21 +00:00
|
|
|
switch r {
|
2017-09-04 23:38:37 +00:00
|
|
|
case ReplicationPerformanceSecondary:
|
2018-01-23 02:44:38 +00:00
|
|
|
return "secondary"
|
2017-09-04 23:38:37 +00:00
|
|
|
case ReplicationPerformancePrimary:
|
2018-01-23 02:44:38 +00:00
|
|
|
return "primary"
|
|
|
|
case ReplicationPerformanceBootstrapping:
|
2017-09-04 23:38:37 +00:00
|
|
|
return "bootstrapping"
|
2018-01-23 02:44:38 +00:00
|
|
|
case ReplicationPerformanceDisabled:
|
|
|
|
return "disabled"
|
2017-09-04 23:38:37 +00:00
|
|
|
case ReplicationDRPrimary:
|
2018-01-23 02:44:38 +00:00
|
|
|
return "primary"
|
2017-09-04 23:38:37 +00:00
|
|
|
case ReplicationDRSecondary:
|
2018-01-23 02:44:38 +00:00
|
|
|
return "secondary"
|
|
|
|
case ReplicationDRBootstrapping:
|
|
|
|
return "bootstrapping"
|
|
|
|
case ReplicationDRDisabled:
|
|
|
|
return "disabled"
|
2017-02-16 18:37:21 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 02:44:38 +00:00
|
|
|
return "unknown"
|
2017-02-16 18:37:21 +00:00
|
|
|
}
|
2017-09-04 23:38:37 +00:00
|
|
|
|
2019-02-06 02:01:18 +00:00
|
|
|
func (r ReplicationState) StateStrings() []string {
|
|
|
|
var ret []string
|
|
|
|
if r.HasState(ReplicationPerformanceSecondary) {
|
|
|
|
ret = append(ret, "perf-secondary")
|
|
|
|
}
|
|
|
|
if r.HasState(ReplicationPerformancePrimary) {
|
|
|
|
ret = append(ret, "perf-primary")
|
|
|
|
}
|
|
|
|
if r.HasState(ReplicationPerformanceBootstrapping) {
|
|
|
|
ret = append(ret, "perf-bootstrapping")
|
|
|
|
}
|
|
|
|
if r.HasState(ReplicationPerformanceDisabled) {
|
|
|
|
ret = append(ret, "perf-disabled")
|
|
|
|
}
|
|
|
|
if r.HasState(ReplicationDRPrimary) {
|
|
|
|
ret = append(ret, "dr-primary")
|
|
|
|
}
|
|
|
|
if r.HasState(ReplicationDRSecondary) {
|
|
|
|
ret = append(ret, "dr-secondary")
|
|
|
|
}
|
|
|
|
if r.HasState(ReplicationDRBootstrapping) {
|
|
|
|
ret = append(ret, "dr-bootstrapping")
|
|
|
|
}
|
|
|
|
if r.HasState(ReplicationDRDisabled) {
|
|
|
|
ret = append(ret, "dr-disabled")
|
|
|
|
}
|
|
|
|
if r.HasState(ReplicationPerformanceStandby) {
|
|
|
|
ret = append(ret, "perfstandby")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2017-10-23 20:42:56 +00:00
|
|
|
func (r ReplicationState) GetDRString() string {
|
|
|
|
switch {
|
2018-01-23 02:44:38 +00:00
|
|
|
case r.HasState(ReplicationDRBootstrapping):
|
|
|
|
return ReplicationDRBootstrapping.string()
|
2017-10-23 20:42:56 +00:00
|
|
|
case r.HasState(ReplicationDRPrimary):
|
2018-01-23 02:44:38 +00:00
|
|
|
return ReplicationDRPrimary.string()
|
2017-10-23 20:42:56 +00:00
|
|
|
case r.HasState(ReplicationDRSecondary):
|
2018-01-23 02:44:38 +00:00
|
|
|
return ReplicationDRSecondary.string()
|
|
|
|
case r.HasState(ReplicationDRDisabled):
|
|
|
|
return ReplicationDRDisabled.string()
|
2017-10-23 20:42:56 +00:00
|
|
|
default:
|
2018-01-23 02:44:38 +00:00
|
|
|
return "unknown"
|
2017-10-23 20:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r ReplicationState) GetPerformanceString() string {
|
|
|
|
switch {
|
2018-01-23 02:44:38 +00:00
|
|
|
case r.HasState(ReplicationPerformanceBootstrapping):
|
|
|
|
return ReplicationPerformanceBootstrapping.string()
|
2017-10-23 20:42:56 +00:00
|
|
|
case r.HasState(ReplicationPerformancePrimary):
|
2018-01-23 02:44:38 +00:00
|
|
|
return ReplicationPerformancePrimary.string()
|
2017-10-23 20:42:56 +00:00
|
|
|
case r.HasState(ReplicationPerformanceSecondary):
|
2018-01-23 02:44:38 +00:00
|
|
|
return ReplicationPerformanceSecondary.string()
|
|
|
|
case r.HasState(ReplicationPerformanceDisabled):
|
|
|
|
return ReplicationPerformanceDisabled.string()
|
2017-10-23 20:42:56 +00:00
|
|
|
default:
|
2018-01-23 02:44:38 +00:00
|
|
|
return "unknown"
|
2017-10-23 20:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 00:39:13 +00:00
|
|
|
func (r ReplicationState) IsPrimaryState() bool {
|
|
|
|
return r.HasState(ReplicationPerformancePrimary | ReplicationDRPrimary)
|
|
|
|
}
|
|
|
|
|
2017-09-04 23:38:37 +00:00
|
|
|
func (r ReplicationState) HasState(flag ReplicationState) bool { return r&flag != 0 }
|
|
|
|
func (r *ReplicationState) AddState(flag ReplicationState) { *r |= flag }
|
|
|
|
func (r *ReplicationState) ClearState(flag ReplicationState) { *r &= ^flag }
|
|
|
|
func (r *ReplicationState) ToggleState(flag ReplicationState) { *r ^= flag }
|
2021-08-30 19:31:11 +00:00
|
|
|
|
|
|
|
type HAState uint32
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ HAState = iota
|
|
|
|
Standby
|
|
|
|
PerfStandby
|
|
|
|
Active
|
|
|
|
)
|