Exemplo n.º 1
0
func Reset(pod *parser.PodConfig) error {
	// loop over list of sentinels, issue a reset
	sentinels, err := pod.GetSentinels()
	if err != nil {
		log.Print(err.Error())
	}
	resets := 0
	for _, s := range sentinels {
		sc, err := client.DialAddress(s)
		if err != nil {
			log.Print(err.Error())
			continue
		}
		err = sc.SentinelReset(pod.Name)
		if err != nil {
			log.Print(err.Error())
			continue
		}
		resets++
	}
	if resets != len(sentinels) {
		return fmt.Errorf("Only %d of %d sentinels were successfully reset", resets, len(sentinels))
	}
	return nil
}
Exemplo n.º 2
0
// ValidateSentinels() iterates over KnownSentinels, connecting to each This is
// useufl for confirming the number of known sentinels matches the number of
// sentinels available
func ValidateSentinels(pod *parser.PodConfig) (bool, error) {
	sentinels, err := pod.GetSentinels()
	if err != nil {
		return false, err
	}
	failed := 0
	connected := 0
	for _, s := range sentinels {
		sc, err := client.DialAddress(s)
		if err != nil {
			log.Print(s, err.Error())
			failed++
			continue
		}
		master, err := sc.SentinelMaster(pod.Name)
		if err != nil {
			log.Printf("[%s] %s", s, err.Error())
			failed++
			continue
		}
		if master.Name != pod.Name {
			log.Printf("Wierd, request master for pod '%s', got master for pod '%s'", pod.Name, master.Name)
			failed++
			continue
		} else {
			connected++
		}
	}
	if len(sentinels) > connected {
		return false, fmt.Errorf("%d of %d sentinels were contacted and has this pod in their list", connected, len(sentinels))
	}
	return true, nil
}
Exemplo n.º 3
0
func enslaveOneForOne(c *cli.Context) {
	for x, saddr := range slaves {
		target := primarypool[x]
		slc, err := client.DialAddress(saddr)
		if err != nil {
			log.Printf("SLAVEPOOL ERROR [%s] %+v\n", saddr, err)
			break
		}
		err = slc.SlaveOf(target.Host, fmt.Sprintf("%d", target.Port))
		if err != nil {
			log.Printf("SLAVEOF ERROR [%s] %+v:\n", saddr, err)
		}
		log.Printf("Enslaved %s to %s:%d\n", saddr, target.Host, target.Port)
	}
}
Exemplo n.º 4
0
func SetSentinelPod(c *cli.Context) {
	sentinel_directive := c.String("directive")
	value := c.String("value")
	sentinels, err := pod.GetSentinels()
	bailOnError(err)
	for _, s := range sentinels {
		//log.Printf("Updating Sentinel %s", s)
		sentinel, err := client.DialAddress(s)
		if err != nil {
			log.Printf("Unable to connect to %s! You will need to manually adjust the directive's value for this sentinel.", s)
			continue
		}
		sentinel.SentinelSetString(pod.Name, sentinel_directive, value)
	}
}
Exemplo n.º 5
0
func enslaveSingleSlave(c *cli.Context) {
	//TODO: make it random?
	target := primarypool[0]
	for _, saddr := range slaves {
		slc, err := client.DialAddress(saddr)
		if err != nil {
			log.Printf("SLAVEPOOL ERROR [%s] %+v\n", saddr, err)
			break
		}
		err = slc.SlaveOf(target.Host, fmt.Sprintf("%d", target.Port))
		if err != nil {
			log.Printf("SLAVEOF ERROR [%s] %+v\n", saddr, err)
		}
		log.Printf("Enslaved %s to %s:%d\n", saddr, target.Host, target.Port)
	}
}
Exemplo n.º 6
0
func enslaveRing(c *cli.Context) {
	added := 1
	var target structures.SlaveInfo
	for x, saddr := range slaves {
		index := x % len(primarypool)
		target = primarypool[index]
		slc, err := client.DialAddress(saddr)
		if err != nil {
			log.Printf("SLAVEPOOL ERROR [%s] %+v\n", saddr, err)
			break
		}
		err = slc.SlaveOf(target.Host, fmt.Sprintf("%d", target.Port))
		if err != nil {
			log.Printf("SLAVEOF ERROR [%s] %+v:\n", saddr, err)
		}
		log.Printf("Enslaved %s to %s:%d\n", saddr, target.Host, target.Port)
		added++
	}
}
Exemplo n.º 7
0
func getSentinelConnection(c *cli.Context) (err error) {
	log.Print("Getting Sentinel connection")
	sentinelconn, err = client.DialAddress(c.GlobalString("sentinel"))
	return err
}
Exemplo n.º 8
0
func getSentinel(c *cli.Context) (sentinel *client.Redis) {
	saddr := fmt.Sprintf("%s:%d", c.GlobalString("address"), c.GlobalInt("port"))
	sentinel, err := client.DialAddress(saddr)
	bailOnError(err)
	return
}