Skip to content

Commit

Permalink
leases: Move lease sorting outside of lock
Browse files Browse the repository at this point in the history
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
etcd-io#9699
  • Loading branch information
Micah Gates authored and braintreeps committed Jun 7, 2018
1 parent 4b26772 commit 0561372
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lease/lessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ func (le *lessor) unsafeLeases() []*Lease {
for _, l := range le.leaseMap {
leases = append(leases, l)
}
sort.Sort(leasesByExpiry(leases))
return leases
}

func (le *lessor) Leases() []*Lease {
le.mu.RLock()
ls := le.unsafeLeases()
le.mu.RUnlock()
sort.Sort(leasesByExpiry(ls))
return ls
}

Expand All @@ -360,6 +360,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
Expand Down

0 comments on commit 0561372

Please sign in to comment.