2014-01-15 22:17:40 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
2014-01-15 22:34:17 +00:00
|
|
|
"math/rand"
|
2014-08-21 21:28:16 +00:00
|
|
|
"os/exec"
|
|
|
|
"runtime"
|
2014-01-15 22:17:40 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// This scale factor means we will add a minute after we
|
|
|
|
// cross 128 nodes, another at 256, another at 512, etc.
|
|
|
|
// By 8192 nodes, we will scale up by a factor of 8
|
|
|
|
aeScaleThreshold = 128
|
|
|
|
)
|
|
|
|
|
|
|
|
// aeScale is used to scale the time interval at which anti-entropy
|
|
|
|
// take place. It is used to prevent saturation as the cluster size grows
|
|
|
|
func aeScale(interval time.Duration, n int) time.Duration {
|
|
|
|
// Don't scale until we cross the threshold
|
|
|
|
if n <= aeScaleThreshold {
|
|
|
|
return interval
|
|
|
|
}
|
|
|
|
|
|
|
|
multiplier := math.Ceil(math.Log2(float64(n))-math.Log2(aeScaleThreshold)) + 1.0
|
|
|
|
return time.Duration(multiplier) * interval
|
|
|
|
}
|
2014-01-15 22:34:17 +00:00
|
|
|
|
|
|
|
// Returns a random stagger interval between 0 and the duration
|
|
|
|
func randomStagger(intv time.Duration) time.Duration {
|
|
|
|
return time.Duration(uint64(rand.Int63()) % uint64(intv))
|
|
|
|
}
|
2014-04-03 19:12:23 +00:00
|
|
|
|
|
|
|
// strContains checks if a list contains a string
|
|
|
|
func strContains(l []string, s string) bool {
|
|
|
|
for _, v := range l {
|
|
|
|
if v == s {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2014-08-21 21:28:16 +00:00
|
|
|
|
|
|
|
// ExecScript returns a command to execute a script
|
|
|
|
func ExecScript(script string) (*exec.Cmd, error) {
|
|
|
|
var shell, flag string
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
shell = "cmd"
|
|
|
|
flag = "/C"
|
|
|
|
} else {
|
|
|
|
shell = "/bin/sh"
|
|
|
|
flag = "-c"
|
|
|
|
}
|
|
|
|
cmd := exec.Command(shell, flag, script)
|
|
|
|
return cmd, nil
|
|
|
|
}
|