Skip to content

Commit

Permalink
lease/lessor: recheck if exprired lease is revoked
Browse files Browse the repository at this point in the history
  • Loading branch information
nolouch committed Apr 29, 2019
1 parent efcc108 commit 1bde799
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lease/lease_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestLeaseQueue(t *testing.T) {
t.Fatal("expect no more expiry lease")
}

if le.leaseHeap.Len() != 49 {
if le.leaseHeap.Len() != 50 {
t.Fatalf("expected lease heap pop, got %d", le.leaseHeap.Len())
}
}
11 changes: 9 additions & 2 deletions lease/lessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ var (
// maximum number of lease checkpoints to batch into a single consensus log entry
maxLeaseCheckpointBatchSize = 1000

// interval to check if the expired lease is revoked
expiredleaseRetryInterval = 3 * time.Second

ErrNotPrimary = errors.New("not a primary lessor")
ErrLeaseNotFound = errors.New("lease not found")
ErrLeaseExists = errors.New("lease already exists")
Expand Down Expand Up @@ -650,15 +653,19 @@ func (le *lessor) expireExists() (l *Lease, ok bool, next bool) {
heap.Pop(&le.leaseHeap) // O(log N)
return nil, false, true
}

if time.Now().UnixNano() < item.time /* expiration time */ {
now := time.Now()
if now.UnixNano() < item.time /* expiration time */ {
// Candidate expirations are caught up, reinsert this item
// and no need to revoke (nothing is expiry)
return l, false, false
}
// if the lease is actually expired, add to the removal list. If it is not expired, we can ignore it because another entry will have been inserted into the heap

heap.Pop(&le.leaseHeap) // O(log N)

// recheck if revoke is complete after retry interval
item.time = now.Add(expiredleaseRetryInterval).UnixNano()
heap.Push(&le.leaseHeap, item)
return l, true, false
}

Expand Down

0 comments on commit 1bde799

Please sign in to comment.