feat(cluster_config): change field from int to float64

This is modified for better flexibility, especially for testing.
This commit is contained in:
Yicheng Qin
2014-05-12 22:42:18 -04:00
parent 5367c1c998
commit c0027bfc78
6 changed files with 73 additions and 22 deletions

View File

@@ -12,16 +12,16 @@ const (
MinActiveSize = 3
// DefaultRemoveDelay is the default elapsed time before removal.
DefaultRemoveDelay = int((30 * time.Minute) / time.Second)
DefaultRemoveDelay = float64((30 * time.Minute) / time.Second)
// MinRemoveDelay is the minimum remove delay allowed.
MinRemoveDelay = int((2 * time.Second) / time.Second)
MinRemoveDelay = float64((2 * time.Second) / time.Second)
// DefaultSyncInterval is the default interval for cluster sync.
DefaultSyncInterval = int((30 * time.Minute) / time.Second)
DefaultSyncInterval = float64((30 * time.Minute) / time.Second)
// MinSyncInterval is the minimum sync interval allowed.
MinSyncInterval = int((1 * time.Second) / time.Second)
MinSyncInterval = float64((1 * time.Second) / time.Second)
)
// ClusterConfig represents cluster-wide configuration settings.
@@ -33,11 +33,11 @@ type ClusterConfig struct {
// RemoveDelay is the amount of time, in seconds, after a node is
// unreachable that it will be swapped out as a standby node.
RemoveDelay int `json:"removeDelay"`
RemoveDelay float64 `json:"removeDelay"`
// SyncInterval is the amount of time, in seconds, between
// cluster sync when it runs in standby mode.
SyncInterval int `json:"syncInterval"`
SyncInterval float64 `json:"syncInterval"`
}
// NewClusterConfig returns a cluster configuration with default settings.

View File

@@ -817,7 +817,7 @@ func (s *PeerServer) monitorPeerActivity() {
// Check last activity for all peers.
now := time.Now()
removeDelay := time.Duration(s.ClusterConfig().RemoveDelay) * time.Second
removeDelay := time.Duration(int64(s.ClusterConfig().RemoveDelay * float64(time.Second)))
peers := s.raftServer.Peers()
for _, peer := range peers {
// If the last response from the peer is longer than the remove delay

View File

@@ -206,10 +206,10 @@ func (ps *PeerServer) setClusterConfigHttpHandler(w http.ResponseWriter, req *ht
config.ActiveSize = int(activeSize)
}
if removeDelay, ok := m["removeDelay"].(float64); ok {
config.RemoveDelay = int(removeDelay)
config.RemoveDelay = removeDelay
}
if syncInterval, ok := m["syncInterval"].(float64); ok {
config.SyncInterval = int(syncInterval)
config.SyncInterval = syncInterval
}
// Issue command to update.

View File

@@ -119,8 +119,8 @@ func (s *StandbyServer) SyncCluster(peers []string) error {
return nil
}
func (s *StandbyServer) SetSyncInterval(second int) {
s.syncInterval = time.Duration(second) * time.Second
func (s *StandbyServer) SetSyncInterval(second float64) {
s.syncInterval = time.Duration(int64(second * float64(time.Second)))
}
func (s *StandbyServer) ClusterLeader() *machineMessage {