Skip to content

Metadata garbage collection#1563

Merged
stevvooe merged 4 commits intocontainerd:masterfrom
dmcgowan:gc-alpha
Oct 11, 2017
Merged

Metadata garbage collection#1563
stevvooe merged 4 commits intocontainerd:masterfrom
dmcgowan:gc-alpha

Conversation

@dmcgowan
Copy link
Copy Markdown
Member

Add initial implementation of a mark and sweep garbage collection on the metadata store.

Currently the garbage collection is only trigger on image deletion, this temporary.

Follows reference and root definitions defined in #1398. Labels are used to keep these references. An alternate implementation is being considered which continues to use labels but stores backreferences to allow a fully consistent delete just on the metadata store.

@dmcgowan
Copy link
Copy Markdown
Member Author

Pushed snapshot cleanup, going to add content clean up next. I think we want add a few more trigger points for GC right now (container deletion?) then we can consider this for merge. Considering this makes no changes to the underlying data structures it is safe to merge this and add a reference tracking version later.

Comment thread gc/gc.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make sure to fill in the godoc for these core exports.

Comment thread metadata/gc.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: use a switch here.

Comment thread metadata/content.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a little odd. We shouldn't rely on this fixup on the database. Are we not able to construct the database with the correct content store?

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 was thinking that we would want to prevent overriding, however it doesn't really make sense for it to be called multiple times. I was trying to prevent changes to other parts of the code that handle this initialization, it is already somewhat complicated by the fact that the metadata db is passed around as a plugin and these functions are also initialized by plugins. The alternative to have the database object fully initialized at construction would require the metadata plugin to rely on content store and snapshot store and the services to only rely on the metadata store. That pattern may make more sense now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is important that we ensure our initialization is worked out correctly. Usually, ergonomics problems during instantiation reflect a problem with the object model. We might be missing a component.

Let's draw a dependency diagram and work it out from there.

Comment thread metadata/db.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use d for the name, short for "duration". I think we used "duration` in the past.

Comment thread metadata/db.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's document the locking semantics. The behavior of these is really important for implementing this safely.

Comment thread metadata/db.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this m for "modification"? Would wlock be better?

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.

Short for "mutation", modification works as well. wlock would probably be clearer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Alright, wlock sounds like fine. Just make sure to make it clear how these work together as a latch.

Comment thread metadata/db_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you can use sub tests to do this now.

@dmcgowan
Copy link
Copy Markdown
Member Author

dmcgowan commented Oct 2, 2017

Removing WIP tag. I added a trigger for containerd deletion as well as well as updated content and snapshot deletion to mark their stores as dirty so the next collection will know to clean up those datastores even if the metadata collection did not mark anything for deletion.

@dmcgowan dmcgowan changed the title [WIP] Metadata garbage collection Metadata garbage collection Oct 2, 2017
@dmcgowan
Copy link
Copy Markdown
Member Author

dmcgowan commented Oct 3, 2017

Added #1582 for metadata database changes

@dmcgowan
Copy link
Copy Markdown
Member Author

dmcgowan commented Oct 6, 2017

Rebased

Note that the garbage collection is relying on labels to determine the links between content. These labels are set during content creation. The first garbage collection after updating will remove content which was previously pulled. Is this an issue I should mitigate like I did with the database migration? It would still likely require some sort of repull to get the labels set on the client.

Note the labeling commit is separate, it is possible we could get this commit in first if we are in agreement on the garbage collection label approach.

Ensure all snapshots and content are referenced on commit and
protected from cleanup.

Signed-off-by: Derek McGowan <[email protected]>
Marks and sweeps unreferenced objects.
Add snapshot cleanup to metadata.
Add content garbage collection

Add dirty flags for snapshotters and content store which
are set on deletion and used during the next garbage collection.
Cleanup content store backend when content metadata is removed.

Signed-off-by: Derek McGowan <[email protected]>
Call garbage collection on container and image deletion.

Signed-off-by: Derek McGowan <[email protected]>
Prevent checkpoints from getting garbage collected by
adding root labels to unreferenced checkpoint objects.
Mark checkpoints as gc roots.

Signed-off-by: Derek McGowan <[email protected]>
@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #1563 into master will increase coverage by 2.49%.
The diff coverage is 65.16%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1563      +/-   ##
==========================================
+ Coverage   46.37%   48.87%   +2.49%     
==========================================
  Files          26       27       +1     
  Lines        3547     4074     +527     
==========================================
+ Hits         1645     1991     +346     
- Misses       1524     1668     +144     
- Partials      378      415      +37
Impacted Files Coverage Δ
metadata/content.go 31.04% <50%> (+3.64%) ⬆️
metadata/gc.go 61.25% <61.25%> (ø)
metadata/snapshot.go 50.28% <73.45%> (+6.17%) ⬆️
metadata/db.go 65.97% <74.77%> (+10.16%) ⬆️
metadata/bolt.go 75% <0%> (+18.75%) ⬆️

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 551579b...ffb03c4. Read the comment docs.

@crosbymichael
Copy link
Copy Markdown
Member

LGTM

1 similar comment
@stevvooe
Copy link
Copy Markdown
Member

LGTM

@stevvooe stevvooe merged commit 587f252 into containerd:master Oct 11, 2017
@dmcgowan dmcgowan deleted the gc-alpha 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.

4 participants