mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Add minimum active size and promote delay.
This commit is contained in:
@@ -8,8 +8,14 @@ const (
|
||||
// DefaultActiveSize is the default number of active followers allowed.
|
||||
DefaultActiveSize = 9
|
||||
|
||||
// MinActiveSize is the minimum active size allowed.
|
||||
MinActiveSize = 3
|
||||
|
||||
// DefaultPromoteDelay is the default elapsed time before promotion.
|
||||
DefaultPromoteDelay = int((30 * time.Minute) / time.Second)
|
||||
|
||||
// MinPromoteDelay is the minimum promote delay allowed.
|
||||
MinPromoteDelay = int((2 * time.Second) / time.Second)
|
||||
)
|
||||
|
||||
// ClusterConfig represents cluster-wide configuration settings.
|
||||
|
||||
@@ -158,17 +158,16 @@ func (s *PeerServer) ClusterConfig() *ClusterConfig {
|
||||
// SetClusterConfig updates the current cluster configuration.
|
||||
// Adjusting the active size will cause the PeerServer to demote peers or
|
||||
// promote proxies to match the new size.
|
||||
func (s *PeerServer) SetClusterConfig(c *ClusterConfig) error {
|
||||
// Validate configuration.
|
||||
if c.ActiveSize < 1 {
|
||||
return etcdErr.NewError(etcdErr.EcodeInvalidActiveSize, "Post", 0)
|
||||
} else if c.PromoteDelay < 0 {
|
||||
return etcdErr.NewError(etcdErr.EcodeInvalidPromoteDelay, "Post", 0)
|
||||
func (s *PeerServer) SetClusterConfig(c *ClusterConfig) {
|
||||
// Set minimums.
|
||||
if c.ActiveSize < MinActiveSize {
|
||||
c.ActiveSize = MinActiveSize
|
||||
}
|
||||
if c.PromoteDelay < MinPromoteDelay {
|
||||
c.PromoteDelay = MinPromoteDelay
|
||||
}
|
||||
|
||||
s.clusterConfig = c
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Helper function to do discovery and return results in expected format
|
||||
|
||||
@@ -21,5 +21,6 @@ func (c *SetClusterConfigCommand) CommandName() string {
|
||||
// Apply updates the cluster configuration.
|
||||
func (c *SetClusterConfigCommand) Apply(context raft.Context) (interface{}, error) {
|
||||
ps, _ := context.Server().Context().(*PeerServer)
|
||||
return nil, ps.SetClusterConfig(c.Config)
|
||||
ps.SetClusterConfig(c.Config)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user