Browse Source

Add minimum active size and promote delay.

Ben Johnson 11 years ago
parent
commit
c0a59b3a27

+ 6 - 0
server/cluster_config.go

@@ -8,8 +8,14 @@ const (
 	// DefaultActiveSize is the default number of active followers allowed.
 	// DefaultActiveSize is the default number of active followers allowed.
 	DefaultActiveSize = 9
 	DefaultActiveSize = 9
 
 
+	// MinActiveSize is the minimum active size allowed.
+	MinActiveSize = 3
+
 	// DefaultPromoteDelay is the default elapsed time before promotion.
 	// DefaultPromoteDelay is the default elapsed time before promotion.
 	DefaultPromoteDelay = int((30 * time.Minute) / time.Second)
 	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.
 // ClusterConfig represents cluster-wide configuration settings.

+ 7 - 8
server/peer_server.go

@@ -158,17 +158,16 @@ func (s *PeerServer) ClusterConfig() *ClusterConfig {
 // SetClusterConfig updates the current cluster configuration.
 // SetClusterConfig updates the current cluster configuration.
 // Adjusting the active size will cause the PeerServer to demote peers or
 // Adjusting the active size will cause the PeerServer to demote peers or
 // promote proxies to match the new size.
 // 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
 	s.clusterConfig = c
-
-	return nil
 }
 }
 
 
 // Helper function to do discovery and return results in expected format
 // Helper function to do discovery and return results in expected format

+ 2 - 1
server/set_cluster_config_command.go

@@ -21,5 +21,6 @@ func (c *SetClusterConfigCommand) CommandName() string {
 // Apply updates the cluster configuration.
 // Apply updates the cluster configuration.
 func (c *SetClusterConfigCommand) Apply(context raft.Context) (interface{}, error) {
 func (c *SetClusterConfigCommand) Apply(context raft.Context) (interface{}, error) {
 	ps, _ := context.Server().Context().(*PeerServer)
 	ps, _ := context.Server().Context().(*PeerServer)
-	return nil, ps.SetClusterConfig(c.Config)
+	ps.SetClusterConfig(c.Config)
+	return nil, nil
 }
 }

+ 4 - 4
tests/functional/proxy_test.go

@@ -106,8 +106,8 @@ func TestProxyAutoPromote(t *testing.T) {
 	assert.NoError(t, err)
 	assert.NoError(t, err)
 	assert.Equal(t, len(result.Node.Nodes), 1)
 	assert.Equal(t, len(result.Node.Nodes), 1)
 
 
-	// Reconfigure with a short promote delay (1 second).
-	resp, _ := tests.Put("http://localhost:7001/config", "application/json", bytes.NewBufferString(`{"activeSize":9, "promoteDelay":1}`))
+	// Reconfigure with a short promote delay (2 second).
+	resp, _ := tests.Put("http://localhost:7001/config", "application/json", bytes.NewBufferString(`{"activeSize":9, "promoteDelay":2}`))
 	if !assert.Equal(t, resp.StatusCode, 200) {
 	if !assert.Equal(t, resp.StatusCode, 200) {
 		t.FailNow()
 		t.FailNow()
 	}
 	}
@@ -121,10 +121,10 @@ func TestProxyAutoPromote(t *testing.T) {
 	etcd.Release()
 	etcd.Release()
 
 
 	// Wait for it to get dropped.
 	// Wait for it to get dropped.
-	time.Sleep(server.PeerActivityMonitorTimeout + (1 * time.Second))
+	time.Sleep(server.PeerActivityMonitorTimeout + (2 * time.Second))
 
 
 	// Wait for the proxy to be promoted.
 	// Wait for the proxy to be promoted.
-	time.Sleep(server.ActiveMonitorTimeout + (1 * time.Second))
+	time.Sleep(server.ActiveMonitorTimeout + (2 * time.Second))
 
 
 	// Verify that we have 9 peers.
 	// Verify that we have 9 peers.
 	result, err = c.Get("_etcd/machines", true, true)
 	result, err = c.Get("_etcd/machines", true, true)