Skip to content

metadata: image removal triggers GC#1960

Merged
stevvooe merged 2 commits intocontainerd:masterfrom
dmcgowan:images-removal-dirty
Jan 17, 2018
Merged

metadata: image removal triggers GC#1960
stevvooe merged 2 commits intocontainerd:masterfrom
dmcgowan:images-removal-dirty

Conversation

@dmcgowan
Copy link
Copy Markdown
Member

@dmcgowan dmcgowan commented Jan 3, 2018

Currently an image removal with the sync flag will not by itself cause a GC to run the same way removal of content or snapshots would. This fixes this by refactoring the image store to have access to the metadata store to mark the content dirty flag.

To do this...
The boltdb image store now manages its own transactions when one is not provided, but allows the caller to pass in a transaction through the context. This makes the image store more similar to the content and snapshot stores. Additionally, use the reference to the metadata database to mark the content store as dirty after an image has been deleted. The deletion of an image means a reference to a piece of content is gone and therefore garbage collection should be run to check if any resources can be cleaned up as a result.

The namespace empty check logic also needed to be updated since it was relying on using a transaction to initialize the container and image stores. Now the transaction is just directly used to check whether the buckets are empty, saving unnecessarily loading all the content into memory just to check whether or not a key exists under the buckets.

Credit to @tonistiigi for finding image removal not triggering gc without sync

@dmcgowan dmcgowan changed the title metadata: Images removal triggers GC metadata: images removal triggers GC Jan 3, 2018
@dmcgowan dmcgowan changed the title metadata: images removal triggers GC metadata: image removal triggers GC Jan 3, 2018
@dmcgowan dmcgowan force-pushed the images-removal-dirty branch from 62a473f to 4a8c983 Compare January 4, 2018 01:42
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jan 4, 2018

Codecov Report

Merging #1960 into master will increase coverage by 0.02%.
The diff coverage is 46.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1960      +/-   ##
==========================================
+ Coverage    45.7%   45.73%   +0.02%     
==========================================
  Files          94       94              
  Lines        9307     9341      +34     
==========================================
+ Hits         4254     4272      +18     
- Misses       4350     4364      +14     
- Partials      703      705       +2
Flag Coverage Δ
#linux 50.33% <48.71%> (-0.01%) ⬇️
#windows 40.55% <46.46%> (+0.05%) ⬆️
Impacted Files Coverage Δ
metadata/namespaces.go 0% <0%> (ø) ⬆️
metadata/buckets.go 56.16% <50%> (+0.16%) ⬆️
metadata/images.go 58.46% <63.76%> (+0.4%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 002c0e2...89fa154. Read the comment docs.

@crosbymichael
Copy link
Copy Markdown
Member

LGTM

Comment thread metadata/buckets.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This if is now unnecessary:

return createBucketIfNotExists(tx, imagesBucketPath(namespace)...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

quite unnecessary

Comment thread metadata/images.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is a delete, shouldn't this use getImageBukcet() and ignore any "ErrBucketNotFound" errors? (or maybe not ignore them, not sure if delete is supposed to be idempotent at this level).

I believe right now it would create the the bucket if it doesn't exist, which is a bit unexpected.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree, that is not correct behavior. The transaction ends up getting rolled back anyway but it is unnecessary to create.

Comment thread metadata/images.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: these three lines are identical in the container store so could be moved into a DB.markDirtyCSWithLock() or something like that

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am going to keep it like this for now, it is only the second use of this particular pattern and adding a function does not necessarily improve readability.

@dmcgowan dmcgowan force-pushed the images-removal-dirty branch from 4a8c983 to cee77c5 Compare January 5, 2018 21:29
Directly get and check whether a bucket is empty.
This prevents unnecessarily loading all records of
the buckets into memory just to check existence.
Also added checks for content and snapshots.

Signed-off-by: Derek McGowan <[email protected]>
The boltdb image store now manages its own transactions when
one is not provided, but allows the caller to pass in a
transaction through the context. This makes the image store
more similar to the content and snapshot stores. Additionally,
use the reference to the metadata database to mark the content
store as dirty after an image has been deleted. The deletion
of an image means a reference to a piece of content is gone
and therefore garbage collection should be run to check if
any resources can be cleaned up as a result.

Signed-off-by: Derek McGowan <[email protected]>
@dmcgowan dmcgowan force-pushed the images-removal-dirty branch from cee77c5 to 89fa154 Compare January 5, 2018 21:39
@stevvooe stevvooe added this to the 1.0.2 milestone Jan 10, 2018
@stevvooe
Copy link
Copy Markdown
Member

LGTM

Merging this now so we can test it for 1.0.2. Please backport since we've released 1.0.1.

@stevvooe stevvooe merged commit acc6011 into containerd:master Jan 17, 2018
@dmcgowan dmcgowan deleted the images-removal-dirty branch June 5, 2018 18:20
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.

5 participants