Ejemplo n.º 1
0
func (c *cluster) refreshNodeList(nodeID, self string) {
	found := false

	c.nodesLock.Lock()

	// Expire unreachable nodes
	for i := 0; i < len(c.nodes); i++ {
		if utils.ElapsedSec(c.nodes[i].LastAnnounce, 5) && c.nodes[i].ID != nodeID && c.nodes[i].ID != self {
			log.Noticef("<- Node %s left the cluster", c.nodes[i].ID)
			c.nodes = append(c.nodes[:i], c.nodes[i+1:]...)
			i--
		} else if c.nodes[i].ID == nodeID {
			found = true
			c.nodes[i].LastAnnounce = time.Now().UTC().Unix()
		}
	}

	// Join new node
	if !found {
		if nodeID != self {
			log.Noticef("-> Node %s joined the cluster", nodeID)
		}
		n := Node{
			ID:           nodeID,
			LastAnnounce: time.Now().UTC().Unix(),
		}
		// TODO use binary search here
		// See https://golang.org/pkg/sort/#Search
		c.nodes = append(c.nodes, n)
		sort.Sort(ByNodeID(c.nodes))
	}

	c.nodeTotal = len(c.nodes)

	// TODO use binary search here
	// See https://golang.org/pkg/sort/#Search
	for i, n := range c.nodes {
		if n.ID == self {
			c.nodeIndex = i
			break
		}
	}

	c.nodesLock.Unlock()
}
Ejemplo n.º 2
0
func (m *Mirror) NeedSync() bool {
	return utils.ElapsedSec(m.LastSync, int64(60*GetConfig().ScanInterval))
}
Ejemplo n.º 3
0
func (m *Mirror) NeedHealthCheck() bool {
	return utils.ElapsedSec(m.lastCheck, int64(60*GetConfig().CheckInterval))
}