Skip to content

Defer layer download until unpack - #3870

Merged
estesp merged 1 commit into
containerd:masterfrom
dmcgowan:download-during-apply
Dec 19, 2019
Merged

estesp merged 1 commit into
containerd:masterfrom
dmcgowan:download-during-apply

Conversation

@dmcgowan

@dmcgowan dmcgowan commented Dec 4, 2019

Copy link
Copy Markdown
Member

Moves the content fetching into the unpack process and defers the download until the snapshot needs it and is ready to apply. As soon as a layer is reached which requires fetching, all remaining layers are fetched.

This should allow supporting the remote snapshotters through the already exists error. This could also support cross namespace snapshot sharing if the snapshotter allows it.

I am working on an update to ctr to use the updated code (since simultaneous unpack), I am going to keep that separate since it is not a trivial change. I needed that to manually test this though, it can also be tested through CRI.

@theopenlab-ci

theopenlab-ci Bot commented Dec 4, 2019

Copy link
Copy Markdown

Build succeeded.

Comment thread unpacker.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we stat from top layer to bot layer, and break once a snapshot is found?

That is an optimization, and make it possible to support squashed remote snapshots. :)

@dmcgowan dmcgowan Dec 4, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That did cross my mind, you make things so much harder

I'll look at that tomorrow

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Random-Liu would merging it like this today break any snapshot implementations? As we discussed yesterday, figuring out how to handle the parentage for squashing is kind of tricky. For example we would need to ensure that while referencing a chain id, we aren't enforcing the parent. We currently don't enforce this on the client but the metadata store is.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Random-Liu @dmcgowan Even without that optimization, we can support squashed remote snapshots using a digest of a manifest (discussed with CernVM-FS people in containerd/stargz-snapshotter#7 ). We will be able to pass these digests to remote snapshotters by PR #3846 (comment) .

@dmcgowan
dmcgowan force-pushed the download-during-apply branch from 45191f9 to b46e542 Compare December 4, 2019 01:14
@theopenlab-ci

theopenlab-ci Bot commented Dec 4, 2019

Copy link
Copy Markdown

Build succeeded.

@ktock ktock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you very much for opening it! Seems the alternative to #3846?

Comment thread unpacker.go Outdated
Comment on lines 116 to 118

@ktock ktock Dec 4, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we pass the image layer's basic information?

  • Reference name of the image which the layer belongs to
  • Digest(not ChainID, the one written in the OCI manifest) of the layer

CRFS needs them to get the layer URL.

https://github.com/ktock/remote-snapshotter/blob/master/filesystems/stargz/fs.go#L152

CVMFS also seems to use the digest to get the path on the filesystem.

https://github.com/ktock/remote-snapshotter/blob/bba94869bfde513a6e7f9d3a009b08f21102b263/filesystems/cvmfs/fs.go#L44

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think we can add an option to do it, it doesn't make sense to do by default as this is very particular to one possible backend implementation. Generally speaking this information does not identify the snapshot and for any given snapshot it could end up having multiple values. Either way, out of scope for this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So for some of these type of implementations, I would favor such a snapshot actually making use of the content store interface for accessing the data. We have already defined a label format there for referencing the source. Likewise referring to a piece of content from a snapshot is an acceptable pattern, although in this case the reference would need to be passed down to the backend.

@ktock ktock Dec 5, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dmcgowan Thank you for your idea!

So we seem to need another patch for storing data X(might be chainID string?) which is label by distribution source information(containerd.io/distribution.source) to the content store.

There's room for consideration about what should X be, but I think the X being chainID string(+some dedicated prefix) is good because snapshotter can easily refer it without any additional labels through Prepare.

@dmcgowan
dmcgowan force-pushed the download-during-apply branch from b46e542 to 65d875e Compare December 4, 2019 23:58
@theopenlab-ci

theopenlab-ci Bot commented Dec 5, 2019

Copy link
Copy Markdown

Build succeeded.

Comment thread unpacker.go Resolved
Comment thread unpacker.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OMG! You just committed a sin in Go I didn't even know was possible.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

lol, there was a goto in the first version but that just felt too wrong. I am not a huge fan of this pattern, but the refactored version was harder to follow.

@ktock

ktock commented Dec 9, 2019 •

Copy link
Copy Markdown
Member

@dmcgowan Recently I've attempted a hacky integration of this patch with remote snapshotter implementation and it seems to work well!(reproduction steps here)

Patches are still needed on client side for kind of pre-preparing remote snapshots. (Currently, for easier implementation, I've taken such approach instead of using the content store for image information propagation)

Moves the content fetching into the unpack process
and defers the download until the snapshot needs it
and is ready to apply. As soon as a layer is reached
which requires fetching, all remaining layers are
fetched.

Signed-off-by: Derek McGowan <[email protected]>
@dmcgowan
dmcgowan force-pushed the download-during-apply branch from 65d875e to 30d92ef Compare December 9, 2019 18:29
@theopenlab-ci

theopenlab-ci Bot commented Dec 9, 2019

Copy link
Copy Markdown

Build succeeded.

@codecov-io

codecov-io commented Dec 9, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #3870 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3870   +/-   ##
=======================================
  Coverage   42.34%   42.34%           
=======================================
  Files         130      130           
  Lines       14683    14683           
=======================================
  Hits         6217     6217           
  Misses       7540     7540           
  Partials      926      926
Flag Coverage Δ
#linux 45.76% <ø> (ø) ⬆️
#windows 37.82% <ø> (ø) ⬆️

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 e8948e1...30d92ef. Read the comment docs.

Comment thread unpacker.go
func uniquePart() string {
t := time.Now()
var b [3]byte
// Ignore read failures, just decreases uniqueness

@AkihiroSuda AkihiroSuda Dec 10, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If read fail, can we add t.Second() as well as t.Nanosecond()?

Comment thread unpacker.go
if states[i].downloaded {
continue

labelOpt := snapshots.WithLabels(map[string]string{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we merge with UnpackConfig.SnapshotOpts ? I think the label for parent snapshotter is still useful, not just for the snapshotter named by RootFS ID.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not limited for this PR. It is proposal and can be handled by following PR. :)

@AkihiroSuda AkihiroSuda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

nits can be worked out later. Let's move this forward.

@ktock ktock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM as mentioned in #3870 (comment) .
Thank you very much for opening this!

@estesp estesp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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.

8 participants