cluster_config.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package cfg
  2. // ClusterConfig represents cluster-wide configuration settings.
  3. type ClusterConfig struct {
  4. // ActiveSize is the maximum number of node that can join as Raft followers.
  5. // Nodes that join the cluster after the limit is reached are standbys.
  6. ActiveSize int `json:"activeSize"`
  7. // RemoveDelay is the amount of time, in seconds, after a node is
  8. // unreachable that it will be swapped out as a standby node.
  9. RemoveDelay float64 `json:"removeDelay"`
  10. // SyncInterval is the amount of time, in seconds, between
  11. // cluster sync when it runs in standby mode.
  12. SyncInterval float64 `json:"syncInterval"`
  13. }
  14. // NewClusterConfig returns a cluster configuration with default settings.
  15. func NewClusterConfig() *ClusterConfig {
  16. return &ClusterConfig{
  17. ActiveSize: DefaultActiveSize,
  18. RemoveDelay: DefaultRemoveDelay,
  19. SyncInterval: DefaultSyncInterval,
  20. }
  21. }
  22. func (c *ClusterConfig) Sanitize() {
  23. if c.ActiveSize < MinActiveSize {
  24. c.ActiveSize = MinActiveSize
  25. }
  26. if c.RemoveDelay < MinRemoveDelay {
  27. c.RemoveDelay = MinRemoveDelay
  28. }
  29. if c.SyncInterval < MinSyncInterval {
  30. c.SyncInterval = MinSyncInterval
  31. }
  32. }