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

cache manager: fix cache manager failure in none daemon mode #124

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions pkg/filesystem/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,19 @@ func (fs *Filesystem) WaitUntilReady(ctx context.Context, snapshotID string) err
return d.WaitUntilReady()
}

func (fs *Filesystem) DelSnapshot(imageID string) error {
if fs.cacheMgr == nil {
return nil
}

if err := fs.cacheMgr.DelSnapshot(imageID); err != nil {
return errors.Wrap(err, "del snapshot err")
}
log.L.Debugf("remove snapshot %s\n", imageID)
fs.cacheMgr.SchedGC()
return nil
}

func (fs *Filesystem) Umount(ctx context.Context, mountPoint string) error {
if !fs.hasDaemon() {
return nil
Expand All @@ -544,14 +557,6 @@ func (fs *Filesystem) Umount(ctx context.Context, mountPoint string) error {
return errors.Wrap(err, "destroy daemon err")
}

if fs.cacheMgr != nil {
if err := fs.cacheMgr.DelSnapshot(daemon.ImageID); err != nil {
return errors.Wrap(err, "del snapshot err")
}
log.L.Debugf("remove snapshot %s\n", daemon.ImageID)
fs.cacheMgr.SchedGC()
}

return nil
}

Expand Down Expand Up @@ -619,15 +624,16 @@ func (fs *Filesystem) mount(d *daemon.Daemon, labels map[string]string) error {
} else if err := fs.manager.StartDaemon(d); err != nil {
return errors.Wrapf(err, "start daemon err")
}
return fs.addSnapshot(d.ImageID, labels)
return nil
}

func (fs *Filesystem) addSnapshot(imageID string, labels map[string]string) error {
func (fs *Filesystem) AddSnapshot(labels map[string]string) error {
// Do nothing if there's no cacheMgr
if fs.cacheMgr == nil {
return nil
}

imageID, _ := registry.ParseLabels(labels)
blobs, err := fs.getBlobIDs(labels)
if err != nil {
return err
Expand Down
15 changes: 15 additions & 0 deletions snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ func (o *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...s
}

logCtx.Infof("found nydus meta layer id %s, parpare remote snapshot", id)

if err := o.fs.AddSnapshot(info.Labels); 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.

Why only do AddSnapshot when the container running? If the user deletes the image before any container run, can nydus blobs be GC-ed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay I miss it, blob cache is generated at only container running.

return nil, errors.Wrap(err, "cache manager failed to add snapshot")
}

if o.manager.IsPrefetchDaemon() {
// Prepare prefetch mount in background, so we could return Mounts
// info to containerd as soon as possible.
Expand Down Expand Up @@ -398,6 +403,16 @@ func (o *snapshotter) Remove(ctx context.Context, key string) error {
return errors.Wrap(err, "failed to get snapshot")
}

if snap.Labels != nil {
if imageID, ok := snap.Labels[label.CRIImageRef]; ok {
if err := o.fs.DelSnapshot(imageID); err != nil {
return errors.Wrap(err, "failed to delete snapshot in cache manager")
}
} else {
return fmt.Errorf("failed to get image ref from snapshot label %#v", snap.Labels)
}
}

_, _, err = storage.Remove(ctx, key)
if err != nil {
return errors.Wrap(err, "failed to remove")
Expand Down