fix unexpose todo

Signed-off-by: ls-2018 <acejilam@gmail.com>
This commit is contained in:
ls-2018 2022-04-06 17:38:46 +08:00
parent ad03f2076a
commit 5b84b30fce
2 changed files with 9 additions and 10 deletions

View File

@ -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

View File

@ -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)
}
})
}