Skip to content

Commit

Permalink
etcdserver,integration: Store remaining TTL on checkpoint
Browse files Browse the repository at this point in the history
To extend lease checkpointing mechanism to cases when the whole etcd
cluster is restarted.

Signed-off-by: Marek Siarkowicz <[email protected]>
  • Loading branch information
michaljasionowski authored and serathius committed Jul 21, 2022
1 parent a30aba8 commit 8d83691
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 14 additions & 1 deletion integration/v3_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,15 @@ func TestV3LeaseCheckpoint(t *testing.T) {
ttl time.Duration
checkpointingInterval time.Duration
leaderChanges int
clusterSize int
expectTTLIsGT time.Duration
expectTTLIsLT time.Duration
}{
{
name: "Checkpointing disabled, lease TTL is reset",
ttl: 300 * time.Second,
leaderChanges: 1,
clusterSize: 3,
expectTTLIsGT: 298 * time.Second,
},
{
Expand All @@ -334,6 +336,16 @@ func TestV3LeaseCheckpoint(t *testing.T) {
checkpointingEnabled: true,
checkpointingInterval: 10 * time.Second,
leaderChanges: 1,
clusterSize: 3,
expectTTLIsLT: 290 * time.Second,
},
{
name: "Checkpointing enabled 10s, lease TTL is preserved after cluster restart",
ttl: 300 * time.Second,
checkpointingEnabled: true,
checkpointingInterval: 10 * time.Second,
leaderChanges: 1,
clusterSize: 1,
expectTTLIsLT: 290 * time.Second,
},
{
Expand All @@ -343,13 +355,14 @@ func TestV3LeaseCheckpoint(t *testing.T) {
checkpointingEnabled: true,
checkpointingInterval: 10 * time.Second,
leaderChanges: 2,
clusterSize: 3,
expectTTLIsLT: 280 * time.Second,
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
config := &ClusterConfig{
Size: 3,
Size: tc.clusterSize,
EnableLeaseCheckpoint: tc.checkpointingEnabled,
LeaseCheckpointInterval: tc.checkpointingInterval,
}
Expand Down
8 changes: 5 additions & 3 deletions lease/lessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func (le *lessor) Checkpoint(id LeaseID, remainingTTL int64) error {
if l, ok := le.leaseMap[id]; ok {
// when checkpointing, we only update the remainingTTL, Promote is responsible for applying this to lease expiry
l.remainingTTL = remainingTTL
l.persistTo(le.b)
if le.isPrimary() {
// schedule the next checkpoint as needed
le.scheduleCheckpointIfNeeded(l)
Expand Down Expand Up @@ -786,9 +787,10 @@ func (le *lessor) initAndRecover() {
ttl: lpb.TTL,
// itemSet will be filled in when recover key-value pairs
// set expiry to forever, refresh when promoted
itemSet: make(map[LeaseItem]struct{}),
expiry: forever,
revokec: make(chan struct{}),
itemSet: make(map[LeaseItem]struct{}),
expiry: forever,
revokec: make(chan struct{}),
remainingTTL: lpb.RemainingTTL,
}
}
le.leaseExpiredNotifier.Init()
Expand Down

0 comments on commit 8d83691

Please sign in to comment.