Exemple #1
0
// caughtUp checks if the follower has really caught up, and adds it to the
// broker's follower set.
func (f *Follower) caughtUp(broker *Broker) bool {

	broker.lock.Lock()
	defer broker.lock.Unlock()

	//log.Info("Obtained lock for %v", f.hostport)

	expected := broker.tails()
	for topic, offset := range expected {
		if offset != f.tails[topic] {
			log.Debug("Not fully caught up yet for %s. %d -> %d", topic, f.tails[topic], offset)
			return false
		}
	}

	// check if follower already in set. if so, delete prev entry.
	for follower, _ := range broker.followers {
		if f.hostport == follower.hostport {
			delete(broker.followers, follower)
		}
	}

	// add to set of followers
	broker.followers[f] = true

	// create struct to communicate with register
	var addFollow protocol.InsyncChange
	addFollow.Type = protocol.ADD
	addFollow.HostPort = f.hostport

	// add in-sync follower
	// check if disconnect from register. if so, exit.
	if err := websocket.JSON.Send(broker.regConn, addFollow); nil != err {
		log.Warn("Unable to update register: %s.", err.Error())
	}

	return true

}
Exemple #2
0
// removeFollower disconnects follower from followers set.
func (b *Broker) removeFollower(follower *Follower) {

	_, exists := b.followers[follower]
	if !exists {
		return
	}

	delete(b.followers, follower)

	// create struct to communicate with register
	var removeFollow protocol.InsyncChange
	removeFollow.Type = protocol.REMOVE
	removeFollow.HostPort = follower.hostport

	// add in-sync follower
	// check if disconnect from register. if so, exit.
	websocket.JSON.Send(b.regConn, removeFollow)
	// checkError(err) // FIXME: exiting is not the correct thing to do

	follower.quit <- nil

	log.Info("Removed follower %v from follower set.", follower.hostport)

}