Example #1
0
func (s *RaftServer) raftEventHandler(e raft.Event) {
	if e.Value() == "leader" {
		log.Info("(raft:%s) Selected as leader. Starting leader loop.", s.raftServer.Name())
		go s.raftLeaderLoop(time.NewTicker(1 * time.Second))
	}

	if e.PrevValue() == "leader" {
		log.Info("(raft:%s) Demoted from leader. Ending leader loop.", s.raftServer.Name())
		s.notLeader <- true
	}
}
Example #2
0
func (s *RaftServer) raftEventHandler(e raft.Event) {
	if e.Value() == "leader" {
		log.Info("(raft:%s) Selected as leader. Starting leader loop.", s.raftServer.Name())
		config := s.clusterConfig.GetLocalConfiguration()
		retentionSweepPeriod := config.StorageRetentionSweepPeriod.Duration
		retentionSweepTimer := time.NewTicker(retentionSweepPeriod)
		go s.raftLeaderLoop(time.NewTicker(1*time.Second),
			retentionSweepTimer)
	}

	if e.PrevValue() == "leader" {
		log.Info("(raft:%s) Demoted from leader. Ending leader loop.", s.raftServer.Name())
		s.notLeader <- true
	}
}