func (r *Replica) HandleQLeaseReply(ql *qlease.Lease, pr *qleaseproto.PromiseReply) { if pr.TimestampNs < ql.LatestTsSent { //old reply, ignore return } if pr.LeaseInstance > ql.PromisedByMeInst { ql.PromiseRejects++ if ql.PromiseRejects == r.N { ql.WriteInQuorumUntil = 0 } return } now := time.Now().UnixNano() max := now for i := int32(0); i < int32(r.N); i++ { if i == r.Id { continue } if i == pr.ReplicaId { ql.LatestRepliesReceived[i] = now + ql.Duration } if max < ql.LatestRepliesReceived[i] { max = ql.LatestRepliesReceived[i] } } ql.WriteInQuorumUntil = max r.LastReplyReceivedTimestamp[pr.ReplicaId] = now }
func (r *Replica) RenewQLease(ql *qlease.Lease, latestAccInst int32) { now := time.Now().UnixNano() ql.PromiseRejects = 0 p := &qleaseproto.Promise{r.Id, ql.PromisedByMeInst, now, ql.Duration, latestAccInst} for i := int32(0); i < int32(r.N); i++ { if i == r.Id || !r.Alive[i] { continue } ql.LatestRepliesReceived[i] += ql.Duration r.SendMsg(i, r.qleasePromiseRPC, p) } ql.LatestTsSent = now // sufficient to extend wait time by the duration of the lease, because // grantees must receive the lease refresh message before the previous lease expires // (otherwise they will dicount the refresh) ql.WriteInQuorumUntil += ql.Duration }
func (r *Replica) HandleQLeaseGuardReply(ql *qlease.Lease, gr *qleaseproto.GuardReply, latestAccInst int32) { if gr.TimestampNs < ql.LatestTsSent { //old reply, must ignore return } now := time.Now().UnixNano() p := &qleaseproto.Promise{r.Id, ql.PromisedByMeInst, now, ql.Duration, latestAccInst} ql.LatestRepliesReceived[gr.ReplicaId] = now + qlease.GUARD_DURATION_NS + ql.Duration if ql.WriteInQuorumUntil < ql.LatestRepliesReceived[gr.ReplicaId] { ql.WriteInQuorumUntil = ql.LatestRepliesReceived[gr.ReplicaId] } r.SendMsg(gr.ReplicaId, r.qleasePromiseRPC, p) }