Esempio n. 1
0
func newCoordinator(clusterName string, c *Config) *Coordinator {
	return &Coordinator{
		clusterName: clusterName,
		state:       NewState,
		config:      c,
		watchers:    make(map[string]chan byte),
		partitions:  make(map[int]string),
		workers:     donut.NewSafeMap(nil),
		rpcClients:  make(map[string]*rpc.Client),
	}
}
Esempio n. 2
0
func (c *Coordinator) createBarrier(name string, onChange func(*donut.SafeMap)) {
	bPath := path.Join(c.barriersPath, name)
	if _, ok := c.watchers[bPath]; !ok {
		if _, err := c.zk.Create(bPath, "", 0, zookeeper.WorldACL(zookeeper.PERM_ALL)); err == nil {
			log.Printf("Created barrier %s", bPath)
		} else {
			// XXX should check to make sure its a "node already exists error"
			log.Printf("Failed to create barrier %s: %v", bPath, err)
		}
		kill, err := watchZKChildren(c.zk, bPath, donut.NewSafeMap(make(map[string]interface{})), onChange)
		if err != nil {
			log.Fatalln(err)
		}
		c.watchers[name] = kill
	}
}