-
Notifications
You must be signed in to change notification settings - Fork 8
/
set-timeout.go
75 lines (64 loc) · 2.13 KB
/
set-timeout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"errors"
"fmt"
"strconv"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
// set-timeout host:port milliseconds
var setTimeoutCommand = cli.Command{
Name: "set-timeout",
Usage: "set timeout configure for redis cluster.",
ArgsUsage: `host:port milliseconds`,
Description: `The set-timeout command set a timeout for redis cluster.`,
Action: func(context *cli.Context) error {
if context.NArg() != 2 {
fmt.Printf("Incorrect Usage.\n\n")
cli.ShowCommandHelp(context, "set-timeout")
logrus.Fatalf("Must provide \"host:port milliseconds\" for set-timeout command!")
}
rt := NewRedisTrib()
if err := rt.SetTimeoutClusterCmd(context); err != nil {
return err
}
return nil
},
}
func (self *RedisTrib) SetTimeoutClusterCmd(context *cli.Context) error {
var addr string
if addr = context.Args().Get(0); addr == "" {
return errors.New("please check host:port for info command")
}
timeout := context.Args().Get(1)
millisec, err := strconv.ParseInt(timeout, 0, 32)
if err != nil {
logrus.Fatalf("Please check the timeout format is number: %s", err.Error())
} else if millisec < 100 {
logrus.Fatalf("Setting a node timeout of less than 100 milliseconds is a bad idea.")
}
// Load cluster information
if err := self.LoadClusterInfoFromNode(addr); err != nil {
return err
}
okCount := 0
errCount := 0
// Send CLUSTER FORGET to all the nodes but the node to remove
logrus.Printf(">>> Reconfiguring node timeout in every cluster node...")
for _, node := range self.Nodes() {
if _, err := node.Call("CONFIG", "set", "cluster-node-timeout", millisec); err != nil {
logrus.Errorf("ERR setting node-timeot in set operation for %s: %s", node.String(), err.Error())
errCount += 1
} else {
if _, err := node.Call("CONFIG", "rewrite"); err != nil {
logrus.Errorf("ERR setting node-timeot in rewrite operation for %s: %s", node.String(), err.Error())
errCount += 1
} else {
logrus.Printf("*** New timeout set for %s", node.NodeString())
okCount += 1
}
}
}
logrus.Printf(">>> New node timeout set. %d OK, %d ERR.", okCount, errCount)
return nil
}