-
Notifications
You must be signed in to change notification settings - Fork 180
K8SPSMDB-1643: prevent concurrent backup and restore operations #2318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ import ( | |
| pbmErrors "github.com/percona/percona-backup-mongodb/pbm/errors" | ||
|
|
||
| psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1" | ||
| "github.com/percona/percona-server-mongodb-operator/pkg/k8s" | ||
| "github.com/percona/percona-server-mongodb-operator/pkg/naming" | ||
| "github.com/percona/percona-server-mongodb-operator/pkg/psmdb/backup" | ||
| ) | ||
|
|
||
|
|
@@ -59,6 +61,26 @@ func (r *ReconcilePerconaServerMongoDBRestore) reconcileLogicalRestore( | |
| return status, nil | ||
| } | ||
|
|
||
| leaseActive, err := k8s.IsLeaseActive(ctx, r.client, naming.BackupLeaseName(cluster.Name), cluster.Namespace) | ||
| if err != nil { | ||
| return status, errors.Wrap(err, "check backup lease") | ||
| } | ||
| if leaseActive { | ||
| log.Info("Waiting for active backup to complete before starting restore.") | ||
| status.State = psmdbv1.RestoreStateWaiting | ||
| return status, nil | ||
| } | ||
|
|
||
| hasActiveLocks, err := pbmc.HasLocks(ctx) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets add a new
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah otherwise restores would be blocked if oplog slicer for PiTR is running |
||
| if err != nil { | ||
| return status, errors.Wrap(err, "checking pbm locks") | ||
| } | ||
| if hasActiveLocks { | ||
| log.Info("Waiting for active PBM operation to complete.") | ||
| status.State = psmdbv1.RestoreStateWaiting | ||
| return status, nil | ||
| } | ||
|
Comment on lines
+64
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like @mayankshah1607 said, this should be moved to high level restore Reconcile function so it applies to all kinds of restores |
||
|
|
||
| log.Info("Starting restore", "backup", backupName) | ||
| status.PBMname, err = runRestore(ctx, backupName, pbmc, cr) | ||
| status.State = psmdbv1.RestoreStateRequested | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put the lease name in this log