mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
leases: Move lease sorting outside of lock
Because the leases were sorted inside UnsafeLeases() the lessor mutex ended up being locked while the whole map was sorted. This pulls the soring outside of the lock, per feedback on https://github.com/coreos/etcd/pull/9699
This commit is contained in:
parent
ab19dee5ce
commit
aa02ceb2e5
@ -335,7 +335,6 @@ func (le *lessor) unsafeLeases() []*Lease {
|
||||
for _, l := range le.leaseMap {
|
||||
leases = append(leases, l)
|
||||
}
|
||||
sort.Sort(leasesByExpiry(leases))
|
||||
return leases
|
||||
}
|
||||
|
||||
@ -343,6 +342,7 @@ func (le *lessor) Leases() []*Lease {
|
||||
le.mu.RLock()
|
||||
ls := le.unsafeLeases()
|
||||
le.mu.RUnlock()
|
||||
sort.Sort(leasesByExpiry(ls))
|
||||
return ls
|
||||
}
|
||||
|
||||
@ -366,6 +366,7 @@ func (le *lessor) Promote(extend time.Duration) {
|
||||
|
||||
// adjust expiries in case of overlap
|
||||
leases := le.unsafeLeases()
|
||||
sort.Sort(leasesByExpiry(leases))
|
||||
|
||||
baseWindow := leases[0].Remaining()
|
||||
nextWindow := baseWindow + time.Second
|
||||
|
Loading…
x
Reference in New Issue
Block a user