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

Update storage management from root labels to leases #1176

Merged
merged 15 commits into from
Oct 18, 2019

Conversation

tonistiigi
Copy link
Member

@tonistiigi tonistiigi commented Sep 20, 2019

Update all buildkit storage management from using root labels for containerd snapshots and blobs to using leases instead.

Every reference in buildctl du is now backed by non-expiring lease. Snapshots and blobs are added to the lease during the lifetime of the cache record. A record can have only a snapshot, only a blob or both. Records with only one can pick up another later (eg. after differ runs). These leases are also used for additional metadata blobs like image configs and manifests.

Tracking of blob metadata is now moved directly into the cache package.

Using leases helps to avoid some races caused by the label management not being completely atomic. It also means that buildkit doesn't require full ownership of the containerd namespace anymore.

Another change is that because chainid-s are not used directly in pull, a chainid calculated by a differ can now be matched with the pulled blob.

This work depends on the flat-leases feature in containerd 1.3 . Without it metadata blobs can have back-references to layers, causing them to not get released. So containerd 1.2 and lower will not be supported after this PR.

TODO: migration from old storage metadata. Current PR only works from an empty state.

@tonistiigi tonistiigi force-pushed the cache-refs branch 9 times, most recently from 0816792 to 804f043 Compare September 24, 2019 22:48
@tonistiigi tonistiigi force-pushed the cache-refs branch 2 times, most recently from 0be18c3 to b314aa2 Compare October 1, 2019 22:20
@tonistiigi tonistiigi marked this pull request as ready for review October 1, 2019 22:43
@tonistiigi
Copy link
Member Author

Finished up the migration and this should be ready now.

@fuweid Can you check that the unpack on image export still works properly and leaves the correct labels for the images.

@tonistiigi tonistiigi requested a review from dmcgowan October 1, 2019 22:45
@tonistiigi tonistiigi assigned AkihiroSuda and unassigned AkihiroSuda Oct 1, 2019
@tonistiigi tonistiigi requested a review from AkihiroSuda October 1, 2019 22:45
return nil, errors.Wrapf(err, "failed to add snapshot %s to lease", id)
}

if err := cm.Snapshotter.Prepare(ctx, id, parentSnapshotID); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Is that newly created lease supposed to be used in this context?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the id is already part of the permanent lease from the AddResource

@@ -106,19 +89,31 @@ func NewWorkerOpt(root string, snFactory SnapshotterFactory, rootless bool, proc
for k, v := range labels {
xlabels[k] = v
}
snap := containerdsnapshot.NewSnapshotter(snFactory.Name, mdb.Snapshotter(snFactory.Name), "buildkit", idmap)
lm := leaseutil.WithNamespace(ctdmetadata.NewLeaseManager(mdb), "buildkit")
if err := cache.MigrateV2(context.TODO(), filepath.Join(root, "metadata.db"), filepath.Join(root, "metadata_v2.db"), c, snap, lm); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Is this context going to be passed in? The calling function signature looks like it could use some attention

Copy link
Member

@dmcgowan dmcgowan left a comment

Choose a reason for hiding this comment

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

Overall flow LGTM

@dmcgowan
Copy link
Member

Needs rebase

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.

3 participants