etcdserver,integration: Store remaining TTL on checkpoint

To extend lease checkpointing mechanism to cases when the whole etcd
cluster is restarted.
This commit is contained in:
Michał Jasionowski 2021-11-19 15:02:25 +00:00 committed by Marek Siarkowicz
parent 48a360aad0
commit fd77b2700c
2 changed files with 19 additions and 4 deletions

View File

@ -351,6 +351,7 @@ func (le *lessor) Checkpoint(id LeaseID, remainingTTL int64) error {
if l, ok := le.leaseMap[id]; ok { if l, ok := le.leaseMap[id]; ok {
// when checkpointing, we only update the remainingTTL, Promote is responsible for applying this to lease expiry // when checkpointing, we only update the remainingTTL, Promote is responsible for applying this to lease expiry
l.remainingTTL = remainingTTL l.remainingTTL = remainingTTL
l.persistTo(le.b)
if le.isPrimary() { if le.isPrimary() {
// schedule the next checkpoint as needed // schedule the next checkpoint as needed
le.scheduleCheckpointIfNeeded(l) le.scheduleCheckpointIfNeeded(l)
@ -784,9 +785,10 @@ func (le *lessor) initAndRecover() {
ttl: lpb.TTL, ttl: lpb.TTL,
// itemSet will be filled in when recover key-value pairs // itemSet will be filled in when recover key-value pairs
// set expiry to forever, refresh when promoted // set expiry to forever, refresh when promoted
itemSet: make(map[LeaseItem]struct{}), itemSet: make(map[LeaseItem]struct{}),
expiry: forever, expiry: forever,
revokec: make(chan struct{}), revokec: make(chan struct{}),
remainingTTL: lpb.RemainingTTL,
} }
} }
le.leaseExpiredNotifier.Init() le.leaseExpiredNotifier.Init()

View File

@ -236,6 +236,7 @@ func TestV3LeaseCheckpoint(t *testing.T) {
ttl time.Duration ttl time.Duration
checkpointingInterval time.Duration checkpointingInterval time.Duration
leaderChanges int leaderChanges int
clusterSize int
expectTTLIsGT time.Duration expectTTLIsGT time.Duration
expectTTLIsLT time.Duration expectTTLIsLT time.Duration
}{ }{
@ -243,6 +244,7 @@ func TestV3LeaseCheckpoint(t *testing.T) {
name: "Checkpointing disabled, lease TTL is reset", name: "Checkpointing disabled, lease TTL is reset",
ttl: 300 * time.Second, ttl: 300 * time.Second,
leaderChanges: 1, leaderChanges: 1,
clusterSize: 3,
expectTTLIsGT: 298 * time.Second, expectTTLIsGT: 298 * time.Second,
}, },
{ {
@ -251,6 +253,16 @@ func TestV3LeaseCheckpoint(t *testing.T) {
checkpointingEnabled: true, checkpointingEnabled: true,
checkpointingInterval: 10 * time.Second, checkpointingInterval: 10 * time.Second,
leaderChanges: 1, 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, expectTTLIsLT: 290 * time.Second,
}, },
{ {
@ -260,6 +272,7 @@ func TestV3LeaseCheckpoint(t *testing.T) {
checkpointingEnabled: true, checkpointingEnabled: true,
checkpointingInterval: 10 * time.Second, checkpointingInterval: 10 * time.Second,
leaderChanges: 2, leaderChanges: 2,
clusterSize: 3,
expectTTLIsLT: 280 * time.Second, expectTTLIsLT: 280 * time.Second,
}, },
} }
@ -267,7 +280,7 @@ func TestV3LeaseCheckpoint(t *testing.T) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
integration.BeforeTest(t) integration.BeforeTest(t)
config := &integration.ClusterConfig{ config := &integration.ClusterConfig{
Size: 3, Size: tc.clusterSize,
EnableLeaseCheckpoint: tc.checkpointingEnabled, EnableLeaseCheckpoint: tc.checkpointingEnabled,
LeaseCheckpointInterval: tc.checkpointingInterval, LeaseCheckpointInterval: tc.checkpointingInterval,
} }