open-vault/helper/consts/replication.go

88 lines
2.5 KiB
Go
Raw Normal View History

2017-02-16 18:37:21 +00:00
package consts
2018-08-24 16:09:03 +00:00
import "time"
2017-02-16 18:37:21 +00:00
type ReplicationState uint32
2018-08-24 16:09:03 +00:00
var ReplicationStaleReadTimeout = 2 * time.Second
2017-02-16 18:37:21 +00:00
const (
_ 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.
2018-01-23 02:44:38 +00:00
ReplicationUnknown ReplicationState = 0
ReplicationPerformancePrimary ReplicationState = 1 << iota
ReplicationPerformanceSecondary
2018-01-23 02:44:38 +00:00
OldSplitReplicationBootstrapping
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
)
2018-01-23 02:44:38 +00:00
func (r ReplicationState) string() string {
2017-02-16 18:37:21 +00:00
switch r {
case ReplicationPerformanceSecondary:
2018-01-23 02:44:38 +00:00
return "secondary"
case ReplicationPerformancePrimary:
2018-01-23 02:44:38 +00:00
return "primary"
case ReplicationPerformanceBootstrapping:
return "bootstrapping"
2018-01-23 02:44:38 +00:00
case ReplicationPerformanceDisabled:
return "disabled"
case ReplicationDRPrimary:
2018-01-23 02:44:38 +00:00
return "primary"
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-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
}
}
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 }