Skip to content
Merged
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
22 changes: 22 additions & 0 deletions layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,27 @@ func (r *layerStore) tspath(id string) string {
return filepath.Join(r.layerdir, id+tarSplitSuffix)
}

func (r *layerStore) deleteInDigestMap(id string) {
for digest, layers := range r.bycompressedsum {
for i, layerID := range layers {
if layerID == id {
layers = append(layers[:i], layers[i+1:]...)
r.bycompressedsum[digest] = layers
break
}
}
}
for digest, layers := range r.byuncompressedsum {
for i, layerID := range layers {
if layerID == id {
layers = append(layers[:i], layers[i+1:]...)
r.byuncompressedsum[digest] = layers
break
}
}
}
}

func (r *layerStore) Delete(id string) error {
if !r.IsReadWrite() {
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to delete layers at %q", r.layerspath())
Expand All @@ -857,6 +878,7 @@ func (r *layerStore) Delete(id string) error {
if layer.MountPoint != "" {
delete(r.bymount, layer.MountPoint)
}
r.deleteInDigestMap(id)
Copy link
Member

Choose a reason for hiding this comment

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

Probably outside of the scope of this PR, but is there any advantage to backport the deleteInternal() function from master where this particular function is called from there?

Copy link
Author

@fgiudici fgiudici Oct 12, 2020

Choose a reason for hiding this comment

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

Good point. Tried to look into it...
AFAICS the deleteInternal() just contains the core deletion operations once in Delete().
The main difference I can see in commit bcedb54d05 on master (which introduced the function) is that now the Load() function calls deleteInternal() in place of the full Delete() function.
This skips from the Load() the operations left in Delete(), which are:

  • the checks if the layers are mounted
  • the call to the Save() function

As bcedb54d05 commit message says, this was introduced to skip the mountpoints locking in the Save() function, as locking already happens in Load().
Looking at the code in the 1.11 branch, the locking management seems quite different. In particular the Save() function doesn't perform any lock.
So, my guess is that we wouldn't benefit from the deleteInternal() function here (moreover, backporting wouldn't be trivial).

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for taking a look @fgiudici. I was afraid that once you undid one string, too much would unravel with that.

toDeleteIndex := -1
for i, candidate := range r.layers {
if candidate.ID == id {
Expand Down