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

snapshot: add Close() #1728

Merged
merged 1 commit into from Nov 14, 2017
Merged

Conversation

AkihiroSuda
Copy link
Member

@@ -296,6 +296,9 @@ type Snapshotter interface {
// Walk all snapshots in the snapshotter. For each snapshot in the
// snapshotter, the function will be called.
Walk(ctx context.Context, fn func(context.Context, Info) error) error

// Close closes the snapshotter.
Close(ctx context.Context) error
Copy link
Member Author

Choose a reason for hiding this comment

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

ctx would not be used in most cases, but I kept this ctx for potential support for cancellation

@AkihiroSuda AkihiroSuda force-pushed the snapshot-closable branch 2 times, most recently from 0bf8865 to 041dc33 Compare November 7, 2017 09:41
@stevvooe
Copy link
Member

stevvooe commented Nov 7, 2017

What does a snapshotter do on close? What is the contract?

@tonistiigi
Copy link
Member

@stevvooe My impression is that it releases the internal resources and makes it so that a new snapshotter instance can be created using the same state directory.

@dmcgowan
Copy link
Member

dmcgowan commented Nov 7, 2017

I agree with having a Close on snapshot, I am not about the justification for deviating from the io.Closer interface though. Cancellation implies that work is done on close, however we want to ensure our implementations are not relying on complex shutdown routines that might require this. @tonistiigi mentions a good use case and should only require freeing resources.

@stevvooe
Copy link
Member

stevvooe commented Nov 8, 2017

@tonistiigi @dmcgowan Agreed, but let's put that down in writing. Notice that most snapshot methods document their contract.

For example, should it always be required to call close? What if close is called twice?

@AkihiroSuda
Copy link
Member Author

removed ctx and added godoc

@codecov-io
Copy link

codecov-io commented Nov 8, 2017

Codecov Report

Merging #1728 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1728      +/-   ##
==========================================
+ Coverage   48.58%   48.68%   +0.09%     
==========================================
  Files          28       28              
  Lines        4250     4258       +8     
==========================================
+ Hits         2065     2073       +8     
  Misses       1750     1750              
  Partials      435      435
Impacted Files Coverage Δ
snapshot/overlay/overlay.go 47.79% <100%> (+0.38%) ⬆️
snapshot/naive/naive.go 46.6% <100%> (+0.48%) ⬆️
metadata/snapshot.go 49.25% <100%> (+0.18%) ⬆️
snapshot/btrfs/btrfs.go 50.99% <100%> (+0.39%) ⬆️

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 f9933e9...4feb6f2. Read the comment docs.

@@ -296,6 +296,15 @@ type Snapshotter interface {
// Walk all snapshots in the snapshotter. For each snapshot in the
// snapshotter, the function will be called.
Walk(ctx context.Context, fn func(context.Context, Info) error) error

// Close releases the internal resources and makes it so that a new
// snapshotter instance can be created using the same state directory.
Copy link
Member

Choose a reason for hiding this comment

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

This seems like an implementation detail. Can't multiple snapshotter instance be made from a single state directory?

// Close releases the internal resources and makes it so that a new
// snapshotter instance can be created using the same state directory.
//
// The most expected usecase of this function is unit testing.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should be the primary use case of a close function. Should this not be the lifecycle endpoint of the snapshotter?

@AkihiroSuda AkihiroSuda changed the title snapshot: add Close(), mainly for ease of UT snapshot: add Close() Nov 13, 2017
@AkihiroSuda
Copy link
Member Author

@stevvooe updated

// Close is expected to be called on the end of the lifecycle of the snapshotter,
// but not mandatory.
//
// Without calling Close, a new snapshotter instance may not be
Copy link
Member

Choose a reason for hiding this comment

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

Again, this is an implementation detail and doesn't belong here. Snapshotters do not know about state directories and other details about how they're implemented.

// Without calling Close, a new snapshotter instance may not be
// created using the same state directory, depending on the implementation.
//
// The behavior of Close after the first call is undefined. (see io.Closer godoc)
Copy link
Member

Choose a reason for hiding this comment

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

Let's make it safe to call this multiple times.

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
@AkihiroSuda
Copy link
Member Author

@stevvooe
Updated PR.
Also, added "CloseTwice" snapshotter test

@stevvooe
Copy link
Member

LGTM

@stevvooe stevvooe merged commit c78c156 into containerd:master Nov 14, 2017
AkihiroSuda added a commit to AkihiroSuda/zfs that referenced this pull request Nov 29, 2017
For containerd/containerd#1728

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
AkihiroSuda added a commit to AkihiroSuda/aufs that referenced this pull request Nov 29, 2017
For containerd/containerd#1728

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
crosbymichael pushed a commit to containerd/aufs that referenced this pull request Nov 29, 2017
For containerd/containerd#1728

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants