Skip to content

Commit

Permalink
lease: randomize TTL on recovery
Browse files Browse the repository at this point in the history
Address etcd-io#8096.

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Jun 14, 2017
1 parent e6d2667 commit 3d1cfa5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lease/lessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/binary"
"errors"
"math"
"math/rand"
"sort"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -475,6 +476,9 @@ func (le *lessor) initAndRecover() {
if lpb.TTL < le.minLeaseTTL {
lpb.TTL = le.minLeaseTTL
}
// randomize +/-10%, so that recovered leases with same TTL
// do not expire all at the same time
lpb.TTL += rand.Int63n(lpb.TTL/10) * int64((-(i & 1))|1)
le.leaseMap[ID] = &Lease{
ID: ID,
ttl: lpb.TTL,
Expand Down

0 comments on commit 3d1cfa5

Please sign in to comment.