cluster_config.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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((5 * time.Second) / 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. // These settings can only be changed through Raft.
  21. type ClusterConfig struct {
  22. // ActiveSize is the maximum number of node that can join as Raft followers.
  23. // Nodes that join the cluster after the limit is reached are standbys.
  24. ActiveSize int `json:"activeSize"`
  25. // RemoveDelay is the amount of time, in seconds, after a node is
  26. // unreachable that it will be swapped out as a standby node.
  27. RemoveDelay float64 `json:"removeDelay"`
  28. // SyncInterval is the amount of time, in seconds, between
  29. // cluster sync when it runs in standby mode.
  30. SyncInterval float64 `json:"syncInterval"`
  31. }
  32. // NewClusterConfig returns a cluster configuration with default settings.
  33. func NewClusterConfig() *ClusterConfig {
  34. return &ClusterConfig{
  35. ActiveSize: DefaultActiveSize,
  36. RemoveDelay: DefaultRemoveDelay,
  37. SyncInterval: DefaultSyncInterval,
  38. }
  39. }