-
Notifications
You must be signed in to change notification settings - Fork 197
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
USHIFT-4117: Auto Recovery: Restore #4061
base: main
Are you sure you want to change the base?
Conversation
@pmtk: This pull request references USHIFT-4117 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.18.0" version, but no target version was set. In response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
/test ? |
Skipping CI for Draft Pull Request. |
@pmtk: The following commands are available to trigger required jobs:
The following commands are available to trigger optional jobs:
Use
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
19024a5
to
0da4ef8
Compare
/test e2e-aws-tests e2e-aws-tests-bootc verify |
@pmtk: This pull request references USHIFT-4117 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.18.0" version, but no target version was set. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
pkg/util/atomic_copier.go
Outdated
} | ||
) | ||
|
||
// AtomicCopier performs a two operation: copies source path to an intermediate location, |
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.
To be more precise, it's not any intermediate location. It's the same destination path, but with temporary name. Can we make it clearer?
pkg/util/atomic_copier.go
Outdated
intermediatePath string | ||
} | ||
|
||
func (c *AtomicCopier) CopyToIntermediate() error { |
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.
Should we allow optional cpArgs override here?
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.
The default copy technique and args need to be documented.
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.
Good idea, but I don't think we need to this right now. Previous cp
implementation wasn't touched for over a year until now. I'll move the file to backup related package so it doesn't need to be generic :D
pkg/util/atomic_copier.go
Outdated
c.intermediatePath = fmt.Sprintf("%s.tmp", c.Destination) | ||
if exists, err := PathExists(c.intermediatePath); err != nil { | ||
return err | ||
} else if exists { | ||
if err := os.RemoveAll(c.intermediatePath); err != nil { | ||
klog.Errorf("Failed to remove intermediate path %q which already existed: %v", c.intermediatePath, err) | ||
return fmt.Errorf("failed to remove %q: %w", c.intermediatePath, err) | ||
} | ||
} |
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'm not living in peace with this approach of adding .tmp
suffix. It seems to be too common for the generic util
code.
Can we do something like mktemp
and return a fatal error if the destination exists? I'm a bit wary of deleting files while copying them.
pkg/util/atomic_copier.go
Outdated
} | ||
return copyErr | ||
} | ||
klog.InfoS("Made an intermediate copy", "cmd", cmd) |
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.
Do you mean this?
klog.InfoS("Made an intermediate copy", "cmd", cmd) | |
klog.InfoS("Completed an atomic file copy operation", "cmd", cmd) |
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.
Not really, not yet at least. The "atomic file copy operation" will be complete after rename, it's just a first part.
pkg/util/atomic_copier.go
Outdated
} | ||
return copyErr | ||
} | ||
klog.InfoS("Made an intermediate copy", "cmd", cmd) |
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.
Do you mean this?
klog.InfoS("Made an intermediate copy", "cmd", cmd) | |
klog.InfoS("Completed an atomic file copy operation", "cmd", cmd) |
pkg/util/atomic_copier.go
Outdated
|
||
// Delete the destination if it's a non-empty directory. | ||
// This is a limitation of the POSIX's rename. | ||
if err := removeDirIfExists(dest); err != nil { |
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 think this should be a fatal error. We should not delete leftover paths as a byproduct of copy operation.
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.
This is not leftover path - this is final path. And without this mv /var/lib/microshift.tmp /var/lib/microshift
doesn't work because of Rename()
limitations in POSIX and UNIX.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html
If new names an existing directory, it shall be required to be an empty directory.
$ mkdir 1 2; touch 1/a 2/b
$ mv 1 2
$ ls
2/
$ ls 2
1/ b
From mv
man (same thing in the cp
as they use the same library underneath):
-T, --no-target-directory
treat DEST as a normal file
$ mkdir 1 2; touch 1/a 2/b
$ mv -T 1 2
mv: cannot move '1' to '2': File exists
pkg/util/atomic_copier.go
Outdated
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.
Nit: what are we copying here? Is it atomic_dir_copy.go
, or more generic atomic_file_copy.go
?
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 think it should be capable of handling both, but it's used for copying dirs, specifically data and backup dirs, so I'll rename it. Thx
tmpDest := fmt.Sprintf("%s.tmp", dest) | ||
if exists, err := pathExists(tmpDest); err != nil { | ||
copier := util.AtomicCopier{Source: src, Destination: dest} | ||
if err := copier.CopyToIntermediate(); err != nil { |
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.
What's the reason for exposing the intermediate / final implementation of the object?
Should we just have a public Copy
function and hide the implementation specifics?
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.
Do you mean the "ToIntermediate" part of the name?
0da4ef8
to
e08cafb
Compare
e08cafb
to
4a5f7dc
Compare
4a5f7dc
to
283fad8
Compare
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pmtk, raz126 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
0b8430d
to
71016e9
Compare
@pmtk: all tests passed! Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Adds two new options to
microshift restore
command:--auto-recovery
to run the procedure of restoring the most recent backup from provided directory--save-failed
to additionally make a copy of current MicroShift data to "failed" subdirectory