Skip to content
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

overlord/snapstate/backend: some copydata improvements #3611

Merged
merged 2 commits into from Jul 26, 2017

Conversation

chipaca
Copy link
Contributor

@chipaca chipaca commented Jul 20, 2017

The state machinery needs that every handler either succeeds or fails
entirely. Currently copy-snap-data has a few half-failure modes; this
addresses that.

In particular, copying data has multiple steps that can fail
independently. This makes it so that when one of them fails, the
previous ones are cleaned up (undone), and anything that had been
trashed in the same operation is brought back from the trash.

This is easy to check, currently: simply

snap refresh <some snap> --revision=<the current revision it's on>

and you'll see the operation fail, but also you'll notice that if the
snap had data dirs they're gone, moved to .old. This PR also enables
this operation to succeed, by explicitly checking for it in both
directions.

The state machinery needs that every handler either succeeds or fails
entirely. Currently copy-snap-data has a few half-failure modes; this
addresses that.

In particular, copying data has multiple steps that can fail
independently. This makes it so that when one of them fails, the
previous ones are cleaned up (undone), and anything that had been
trashed in the same operation is brought back from the trash.

This is easy to check, currently: simply

    snap refresh <some snap> --revision=<the current revision it's on>

and you'll see the operation fail, but also you'll notice that if the
snap had data dirs they're gone, moved to .old. This PR also enables
this operation to succeed, by explicitly checking for it in both
directions.
@codecov-io
Copy link

codecov-io commented Jul 20, 2017

Codecov Report

Merging #3611 into master will increase coverage by 0.08%.
The diff coverage is 54.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3611      +/-   ##
==========================================
+ Coverage    74.9%   74.99%   +0.08%     
==========================================
  Files         380      383       +3     
  Lines       32952    33237     +285     
==========================================
+ Hits        24682    24925     +243     
- Misses       6477     6504      +27     
- Partials     1793     1808      +15
Impacted Files Coverage Δ
overlord/snapstate/backend/copydata.go 60.41% <100%> (+6.75%) ⬆️
overlord/snapstate/backend/snapdata.go 55.63% <41.66%> (-3.54%) ⬇️
release/uname_linux.go 75% <0%> (-10%) ⬇️
cmd/cmd.go 83.87% <0%> (-8.99%) ⬇️
cmd/snap/cmd_aliases.go 93.33% <0%> (-1.67%) ⬇️
daemon/snap.go 80.19% <0%> (-1.39%) ⬇️
overlord/snapstate/check_snap.go 80.71% <0%> (-1.01%) ⬇️
wrappers/services.go 76.7% <0%> (-0.65%) ⬇️
interfaces/builtin/openvswitch_support.go 100% <0%> (ø) ⬆️
snap/types.go 80.43% <0%> (ø) ⬆️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a462005...2fa102a. Read the comment docs.

Copy link
Collaborator

@zyga zyga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, nice, one suggestion for a TODO comment

if err := os.RemoveAll(newDir); err != nil {
logger.Noticef("while undoing creation of new data directory %q: %v", newDir, err)
}
if err := untrash(newDir); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️, nice

// try to fix that; hope for the best
if e := untrash(newPath); e != nil {
// oh noes
msg += fmt.Sprintf("; and when trying to restore the old data directory: %v", e)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO: issue a warning to the user that data was lost

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question but otherwise lgtm

@@ -40,13 +40,20 @@ func (b Backend) CopySnapData(newSnap, oldSnap *snap.Info, meter progress.Meter)

if oldSnap == nil {
return os.MkdirAll(newSnap.DataDir(), 0755)
} else if oldSnap.Revision == newSnap.Revision {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we turn this into a NOP much higher ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but that doesn't make this wrong?

@chipaca chipaca merged commit 825ca27 into snapcore:master Jul 26, 2017
@chipaca chipaca deleted the some-copydata-improvements branch July 27, 2017 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants