cluster_config.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package server
  2. import (
  3. "time"
  4. )
  5. const (
  6. // DefaultActiveSize is the default number of active followers allowed.
  7. DefaultActiveSize = 9
  8. // MinActiveSize is the minimum active size allowed.
  9. MinActiveSize = 3
  10. // DefaultRemoveDelay is the default elapsed time before removal.
  11. DefaultRemoveDelay = float64((30 * time.Minute) / time.Second)
  12. // MinRemoveDelay is the minimum remove delay allowed.
  13. MinRemoveDelay = float64((2 * time.Second) / time.Second)
  14. // DefaultSyncInterval is the default interval for cluster sync.
  15. DefaultSyncInterval = float64((5 * time.Second) / time.Second)
  16. // MinSyncInterval is the minimum sync interval allowed.
  17. MinSyncInterval = float64((1 * time.Second) / time.Second)
  18. )
  19. // ClusterConfig represents cluster-wide configuration settings.
  20. type ClusterConfig struct {
  21. // ActiveSize is the maximum number of node that can join as Raft followers.
  22. // Nodes that join the cluster after the limit is reached are standbys.
  23. ActiveSize int `json:"activeSize"`
  24. // RemoveDelay is the amount of time, in seconds, after a node is
  25. // unreachable that it will be swapped out as a standby node.
  26. RemoveDelay float64 `json:"removeDelay"`
  27. // SyncInterval is the amount of time, in seconds, between
  28. // cluster sync when it runs in standby mode.
  29. SyncInterval float64 `json:"syncInterval"`
  30. }
  31. // NewClusterConfig returns a cluster configuration with default settings.
  32. func NewClusterConfig() *ClusterConfig {
  33. return &ClusterConfig{
  34. ActiveSize: DefaultActiveSize,
  35. RemoveDelay: DefaultRemoveDelay,
  36. SyncInterval: DefaultSyncInterval,
  37. }
  38. }