Ejemplo n.º 1
0
func getIdx(addr string, pid string, role string) (int, error) {
	key := fmt.Sprintf("%s_%s_%s", "upgrade_index", pid, role)
	idx, err := redis.RedisCli(addr, "get", key)
	if idx == "" {
		return -1, nil
	}
	iidx, _ := strconv.Atoi(idx.(string))
	return iidx, err
}
Ejemplo n.º 2
0
func configAofAndRdb(node *topo.Node, state bool) error {
	addr := node.Addr()
	var err error
	var err1 error
	var err2 error
	if state {
		_, err = redis.RedisCli(addr, "config", "set", "appendonly", "yes")
		_, err1 = redis.RedisCli(addr, "config", "set", "dbfilename", "dump.rdb")
	} else {
		_, err = redis.RedisCli(addr, "config", "set", "appendonly", "no")
		_, err1 = redis.RedisCli(addr, "config", "set", "dbfilename", "tmp.rdb")
	}
	_, err2 = redis.RedisCli(addr, "config", "rewrite")
	if err != nil {
		return err
	}
	if err1 != nil {
		return err1
	}
	if err2 != nil {
		return err2
	}
	return nil
}
Ejemplo n.º 3
0
func pdoAction(c *cli.Context) {
	addr := context.GetLeaderAddr()
	url := "http://" + addr + api.FetchReplicaSetsPath

	resp, err := utils.HttpGet(url, nil, 5*time.Second)
	if err != nil {
		fmt.Println(err)
		return
	}

	var rss command.FetchReplicaSetsResult
	err = utils.InterfaceToStruct(resp.Body, &rss)
	if err != nil {
		fmt.Println(err)
		return
	}

	cmd := c.Args()[0]
	var args []interface{}
	for _, arg := range c.Args()[1:] {
		args = append(args, arg)
	}

	totalNodes := 0

	resChan := make(chan string, 2048)

	for _, rs := range rss.ReplicaSets {
		totalNodes += len(rs.AllNodes())
		for _, n := range rs.AllNodes() {
			go func(addr string) {
				res, _ := redis.RedisCli(addr, cmd, args...)
				ret := fmt.Sprintf("%s %s", addr, res)
				resChan <- ret
			}(n.Addr())
		}
	}
	for i := 0; i < totalNodes; i++ {
		ret := <-resChan
		fmt.Println(ret)
	}
	fmt.Println("Total nodes:", totalNodes)

}
Ejemplo n.º 4
0
func saveIdx(addr string, pid string, role string, replica_idx int) error {
	key := fmt.Sprintf("%s_%s_%s", "upgrade_index", pid, role)
	_, err := redis.RedisCli(addr, "set", key, replica_idx)
	return err
}
Ejemplo n.º 5
0
func shutdownServer(node *topo.Node) error {
	addr := node.Addr()
	_, err := redis.RedisCli(addr, "shutdown", "nosave")
	return err
}