From 5b84b30fce6c82ae48db8a7a801ae898b48bbb87 Mon Sep 17 00:00:00 2001 From: ls-2018 Date: Wed, 6 Apr 2022 17:38:46 +0800 Subject: [PATCH] fix unexpose todo Signed-off-by: ls-2018 --- server/lease/lessor.go | 7 +++---- server/lease/lessor_test.go | 12 ++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/server/lease/lessor.go b/server/lease/lessor.go index 0a77fd669da..cb6f0d6ec80 100644 --- a/server/lease/lessor.go +++ b/server/lease/lessor.go @@ -744,7 +744,7 @@ func (le *lessor) scheduleCheckpointIfNeeded(lease *Lease) { return } - if lease.RemainingTTL() > int64(le.checkpointInterval.Seconds()) { + if lease.getRemainingTTL() > int64(le.checkpointInterval.Seconds()) { if le.lg != nil { le.lg.Debug("Scheduling lease checkpoint", zap.Int64("leaseID", int64(lease.ID)), @@ -856,8 +856,7 @@ func (l *Lease) TTL() int64 { } // RemainingTTL returns the last checkpointed remaining TTL of the lease. -// TODO(jpbetz): do not expose this utility method -func (l *Lease) RemainingTTL() int64 { +func (l *Lease) getRemainingTTL() int64 { if l.remainingTTL > 0 { return l.remainingTTL } @@ -866,7 +865,7 @@ func (l *Lease) RemainingTTL() int64 { // refresh refreshes the expiry of the lease. func (l *Lease) refresh(extend time.Duration) { - newExpiry := time.Now().Add(extend + time.Duration(l.RemainingTTL())*time.Second) + newExpiry := time.Now().Add(extend + time.Duration(l.getRemainingTTL())*time.Second) l.expiryMu.Lock() defer l.expiryMu.Unlock() l.expiry = newExpiry diff --git a/server/lease/lessor_test.go b/server/lease/lessor_test.go index 1879549f34b..58a36e61232 100644 --- a/server/lease/lessor_test.go +++ b/server/lease/lessor_test.go @@ -634,18 +634,18 @@ func TestLessorCheckpointPersistenceAfterRestart(t *testing.T) { if err != nil { t.Fatal(err) } - if l.RemainingTTL() != ttl { - t.Errorf("remainingTTL() = %d, expected: %d", l.RemainingTTL(), ttl) + if l.getRemainingTTL() != ttl { + t.Errorf("getRemainingTTL() = %d, expected: %d", l.getRemainingTTL(), ttl) } le.Checkpoint(2, checkpointTTL) - if l.RemainingTTL() != checkpointTTL { - t.Errorf("remainingTTL() = %d, expected: %d", l.RemainingTTL(), checkpointTTL) + if l.getRemainingTTL() != checkpointTTL { + t.Errorf("getRemainingTTL() = %d, expected: %d", l.getRemainingTTL(), checkpointTTL) } le.Stop() le2 := newLessor(lg, be, clusterLatest(), cfg) l = le2.Lookup(2) - if l.RemainingTTL() != tc.expectRemainingTTL { - t.Errorf("remainingTTL() = %d, expected: %d", l.RemainingTTL(), tc.expectRemainingTTL) + if l.getRemainingTTL() != tc.expectRemainingTTL { + t.Errorf("getRemainingTTL() = %d, expected: %d", l.getRemainingTTL(), tc.expectRemainingTTL) } }) }