Skip to content

Commit

Permalink
Merge pull request #13893 from ls-2018/todo
Browse files Browse the repository at this point in the history
fix unexpose todo
  • Loading branch information
ptabor authored Apr 6, 2022
2 parents 047e61d + 5b84b30 commit d24ef3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
7 changes: 3 additions & 4 deletions server/lease/lessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions server/lease/lessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down

0 comments on commit d24ef3a

Please sign in to comment.