Skip to content

Commit

Permalink
cache manager: fix cache manager failure in none daemon mode
Browse files Browse the repository at this point in the history
Previously, both AddSnapshot and DelSnapshot will not be executed in
the none daemon mode. The fundamental reason is that the incoming
parameter is the imageID obtained from the daemon. Now we adjust the
function call path to bypass the daemon and get the imageID directly
from snapshot labels.

For AddSnapshot, we separate it from prepareRemoteSnapshot, run it
separately, and parse the imageID directly from the snapshot label.

For DelSnapshot, we advance it from Cleanup to Remove.

Signed-off-by: zhaoshang <[email protected]>
  • Loading branch information
power-more committed Aug 4, 2022
1 parent 92d4e57 commit 60cc64f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
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 {
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

0 comments on commit 60cc64f

Please sign in to comment.