lease: fix memory leak in LeaseGrant when node is follower

This commit is contained in:
tangcong 2020-03-29 08:09:46 +08:00 committed by Gyuho Lee
parent e784ba73c2
commit b0bdaaa449

View File

@ -291,14 +291,14 @@ func (le *lessor) Grant(id LeaseID, ttl int64) (*Lease, error) {
} }
le.leaseMap[id] = l le.leaseMap[id] = l
item := &LeaseWithTime{id: l.ID, time: l.expiry.UnixNano()}
le.leaseExpiredNotifier.RegisterOrUpdate(item)
l.persistTo(le.b) l.persistTo(le.b)
leaseTotalTTLs.Observe(float64(l.ttl)) leaseTotalTTLs.Observe(float64(l.ttl))
leaseGranted.Inc() leaseGranted.Inc()
if le.isPrimary() { if le.isPrimary() {
item := &LeaseWithTime{id: l.ID, time: l.expiry.UnixNano()}
le.leaseExpiredNotifier.RegisterOrUpdate(item)
le.scheduleCheckpointIfNeeded(l) le.scheduleCheckpointIfNeeded(l)
} }
@ -505,6 +505,7 @@ func (le *lessor) Demote() {
} }
le.clearScheduledLeasesCheckpoints() le.clearScheduledLeasesCheckpoints()
le.clearLeaseExpiredNotifier()
if le.demotec != nil { if le.demotec != nil {
close(le.demotec) close(le.demotec)
@ -648,6 +649,10 @@ func (le *lessor) clearScheduledLeasesCheckpoints() {
le.leaseCheckpointHeap = make(LeaseQueue, 0) le.leaseCheckpointHeap = make(LeaseQueue, 0)
} }
func (le *lessor) clearLeaseExpiredNotifier() {
le.leaseExpiredNotifier = newLeaseExpiredNotifier()
}
// expireExists returns true if expiry items exist. // expireExists returns true if expiry items exist.
// It pops only when expiry item exists. // It pops only when expiry item exists.
// "next" is true, to indicate that it may exist in next attempt. // "next" is true, to indicate that it may exist in next attempt.