-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fix: full snapshot lease update retry on failure with 1m interval (…
- Loading branch information
1 parent
dda25ea
commit dfcf84e
Showing
8 changed files
with
285 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package snapshotter | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/gardener/etcd-backup-restore/pkg/health/heartbeat" | ||
brtypes "github.com/gardener/etcd-backup-restore/pkg/types" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// RenewFullSnapshotLeasePeriodically has a timer and will periodically call FullSnapshotCaseLeaseUpdate to renew the fullsnapshot lease until it is updated or stopped. | ||
// The timer starts upon snapshotter initialization and is reset after every full snapshot is taken. | ||
func (ssr *Snapshotter) RenewFullSnapshotLeasePeriodically(FullSnapshotLeaseStopCh chan struct{}, fullSnapshotLeaseUpdateInterval time.Duration) { | ||
logger := logrus.NewEntry(logrus.New()).WithField("actor", "FullSnapLeaseUpdater") | ||
ssr.FullSnapshotLeaseUpdateTimer = time.NewTimer(fullSnapshotLeaseUpdateInterval) | ||
fullSnapshotLeaseUpdateCtx, fullSnapshotLeaseUpdateCancel := context.WithCancel(context.TODO()) | ||
defer func() { | ||
fullSnapshotLeaseUpdateCancel() | ||
if ssr.FullSnapshotLeaseUpdateTimer != nil { | ||
ssr.FullSnapshotLeaseUpdateTimer.Stop() | ||
ssr.FullSnapshotLeaseUpdateTimer = nil | ||
} | ||
}() | ||
logger.Infof("Starting the FullSnapshot lease renewal with interval %v", fullSnapshotLeaseUpdateInterval) | ||
for { | ||
select { | ||
case <-ssr.FullSnapshotLeaseUpdateTimer.C: | ||
if ssr.PrevFullSnapshot != nil { | ||
if err := func() error { | ||
ctx, cancel := context.WithTimeout(fullSnapshotLeaseUpdateCtx, brtypes.LeaseUpdateTimeoutDuration) | ||
defer cancel() | ||
return heartbeat.FullSnapshotCaseLeaseUpdate(ctx, logger, ssr.PrevFullSnapshot, ssr.K8sClientset, ssr.HealthConfig.FullSnapshotLeaseName) | ||
}(); err != nil { | ||
//FullSnapshot lease update failed. Retry after interval | ||
logger.Warnf("FullSnapshot lease update failed with error: %v", err) | ||
logger.Infof("Resetting the FullSnapshot lease to retry updating with revision %d after %v", ssr.PrevFullSnapshot.LastRevision, fullSnapshotLeaseUpdateInterval) | ||
ssr.FullSnapshotLeaseUpdateTimer.Stop() | ||
ssr.FullSnapshotLeaseUpdateTimer.Reset(fullSnapshotLeaseUpdateInterval) | ||
} else { | ||
//FullSnapshot lease successfully updated. Stop the timer | ||
logger.Infof("Stopping the FullSnapshot lease update") | ||
ssr.FullSnapshotLeaseUpdateTimer.Stop() | ||
} | ||
} else { | ||
//Skip the FullSnapshot lease update as no full snapshot has been taken yet. Reset the timer to retry after interval | ||
ssr.FullSnapshotLeaseUpdateTimer.Stop() | ||
ssr.FullSnapshotLeaseUpdateTimer.Reset(fullSnapshotLeaseUpdateInterval) | ||
} | ||
|
||
case <-FullSnapshotLeaseStopCh: | ||
logger.Info("Closing the full snapshot lease renewal") | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.