Skip to content

Commit

Permalink
Merge pull request #124 from power-more/zhaoshang/cachemanager
Browse files Browse the repository at this point in the history
cache manager: fix cache manager failure in none daemon mode
  • Loading branch information
changweige authored Aug 10, 2022
2 parents 4bb81a8 + 60cc64f commit cd6452d
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 cd6452d

Please sign in to comment.