Add forward References to the GC collection context by dmcgowan · Pull Request #13634 · containerd/containerd · GitHub
Skip to content

Add forward References to the GC collection context - #13634

Merged
mxpv merged 1 commit into
containerd:mainfrom
dmcgowan:gc-forward-references
Jun 22, 2026
Merged

Add forward References to the GC collection context#13634
mxpv merged 1 commit into
containerd:mainfrom
dmcgowan:gc-forward-references

Conversation

@dmcgowan

Copy link
Copy Markdown
Member

Extend the garbage-collection framework so a collectible resource can emit forward references during graph traversal, in addition to the existing back-reference mechanism.

A CollectionContext may now implement the optional collectionWithReferences interface:

References(ctx context.Context, node gc.Node, fn func(gc.Node))

When the GC visits a node whose resource type was registered by an external collector, gcContext.references consults the per-type References implementation after the built-in core resource types are handled.

This is the forward-reference analogue of collectionWithBackRefs. Whereas ActiveWithBackRefs must enumerate every edge up front and the gcContext holds all of them in its backRefs map for the entire collection, References is invoked on demand for a single node. A collector whose resources fan out to many other nodes can therefore emit those edges without retaining them in memory for the gc context.

This commit is intentionally a no-op: no plugin registers a collector that uses collectionWithReferences yet. It is isolated here so that concurrent development efforts that depend on this interface can be proposed and reviewed upstream independently. This is useful for implementing chunked storage as a plugin, which will directly reference blobs in the content store. This is also useful for any plugin that might hold a reference to a core containerd type.

Copilot AI review requested due to automatic review settings June 19, 2026 19:35
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Jun 19, 2026

Copilot AI left a comment

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.

Pull request overview

Extends the core/metadata garbage-collection traversal logic to support lazy, forward reference emission from externally-registered collectible resource types, complementing the existing eager/back-reference mechanism.

Changes:

  • Introduces an optional collectionWithReferences interface for CollectionContext to emit forward references on demand.
  • Caches per-resource-type collectionWithReferences implementations in gcContext.refContexts during startGCContext.
  • Updates gcContext.references to invoke References(...) for matching external resource types after handling built-in core types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/metadata/gc.go
Comment thread core/metadata/gc.go
Extend the garbage-collection framework so a collectible resource can emit
forward references during graph traversal, in addition to the existing
back-reference mechanism.

A CollectionContext may now implement the optional collectionWithReferences
interface:

	References(ctx context.Context, node gc.Node, fn func(gc.Node))

When the GC visits a node whose resource type was registered by an external
collector, gcContext.references consults the per-type References
implementation after the built-in core resource types are handled.

This is the forward-reference analogue of collectionWithBackRefs.  Whereas
ActiveWithBackRefs must enumerate every edge up front and the gcContext
holds all of them in its backRefs map for the entire collection, References
is invoked on demand for a single node.  A collector whose resources fan
out to many other nodes can therefore emit those edges without retaining
them in memory for the gc context.

This commit is intentionally a no-op: no plugin registers a collector that
uses collectionWithReferences yet.  It is isolated here so that concurrent
development efforts that depend on this interface can be proposed and
reviewed upstream independently.

Signed-off-by: Derek McGowan <derek@mcg.dev>
@dmcgowan
dmcgowan force-pushed the gc-forward-references branch from ee2a4ca to 4be39f1 Compare June 19, 2026 19:49
@dmcgowan dmcgowan added this to the 2.4 milestone Jun 19, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jun 22, 2026
@mxpv
mxpv added this pull request to the merge queue Jun 22, 2026
Merged via the queue into containerd:main with commit 49480db Jun 22, 2026
50 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jun 22, 2026
@dmcgowan dmcgowan changed the title core/metadata: add forward References to the GC collection context Add forward References to the GC collection context Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants