//Use NOP to detect the gap slots [from, to) func CatchUp(pn *paxosNode, from, to int) { pn.catchupMutex.Lock() pn.catchupCounter++ pn.catchupMutex.Unlock() for index := from; index < to; index++ { i := 1 c := new(command.Command) c.Type = command.NOP LOGV.Printf("node %d Try to catch up with slot %d\n", pn.nodeID, index) success, _, num := pn.DoReplicate(c, 0, index) for !success { LOGV.Printf("node %d last Paxos is not success, waiting to try again...\n", pn.nodeID) //TODO:maybe do not need to wait time.Sleep(time.Duration(rand.Int31n(1000)) * time.Millisecond) LOGV.Printf("node %d last Paxos is not success, try again...\n", pn.nodeID) //i++ LOGV.Printf("node %d Try to catch up with slot %d\n", pn.nodeID, index) i = (num/pn.numNodes + 1) success, _, num = pn.DoReplicate(c, i, index) } LOGV.Printf("Catched up with slot %d\n", index) } pn.catchupMutex.Lock() pn.catchupCounter-- pn.catchupMutex.Unlock() }