From 1bde7997afe583d82afd13e57664c3334ba2bd03 Mon Sep 17 00:00:00 2001 From: nolouch Date: Tue, 30 Apr 2019 01:39:59 +0800 Subject: [PATCH] lease/lessor: recheck if exprired lease is revoked --- lease/lease_queue_test.go | 2 +- lease/lessor.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lease/lease_queue_test.go b/lease/lease_queue_test.go index 2387ae028150..8d228d16af0b 100644 --- a/lease/lease_queue_test.go +++ b/lease/lease_queue_test.go @@ -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()) } } diff --git a/lease/lessor.go b/lease/lessor.go index a208c82ea30e..5ca3a359af1a 100644 --- a/lease/lessor.go +++ b/lease/lessor.go @@ -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") @@ -650,8 +653,8 @@ 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 @@ -659,6 +662,10 @@ func (le *lessor) expireExists() (l *Lease, ok bool, next bool) { // 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 }