// This Function initialize the parameters of Raft Object
func New(id int, f string) Replicator {
	server := cluster.New(id, f)
	nextindex := make([]int, MAX_SERVER)
	matchindex := make([]int, MAX_SERVER)
	for i := 0; i < MAX_SERVER; i++ {
		nextindex[i] = 1
		matchindex[i] = 0
	}
	first_log_index := 0
	last_Index := 0
	last_Term := 0
	count = 0
	for i := range send {
		send[i] = make(chan bool)
		success[i] = make(chan bool)

	}
	//handle if we restart server
	raft := Replicator{Id: id, server: server, currentTerm: last_Term, leader: false, commitIndex: first_log_index, lastApplied: first_log_index, nextIndex: nextindex, matchIndex: matchindex, logEntry: make(map[int]string), lastLogIndex: last_Index, lastLogTerm: last_Term}

	return raft
}
Example #2
0
// This Function initialize the parameters of Raft Object
func New(id int, f string) Replicator {
	server := cluster.New(id, f)
	raft := Replicator{server: server, term: 0, leader: false}

	return raft
}