Skip to content

Add an atomic.Bool to singleflight prefetching#7963

Merged
thevilledev merged 1 commit into
coredns:masterfrom
rpb-ant:cache-prefetch-dedup
Mar 30, 2026
Merged

Add an atomic.Bool to singleflight prefetching#7963
thevilledev merged 1 commit into
coredns:masterfrom
rpb-ant:cache-prefetch-dedup

Conversation

@rpb-ant

@rpb-ant rpb-ant commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

1. Why is this pull request needed and what does it do?

Follow-up to #7944

This ended up being fairly simple to implement, and my experiments indicate that it eliminates a significant footgun with both prefetch and serve_stale

2. Which issues (if any) are related?

#7904

3. Which documentation changes (if any) need to be made?

We probably want to update the docs around prefetch and serve_stale just to clarify that the background fetches are single-flighted

4. Does this introduce a backward incompatible change or deprecation?

I don't believe so. Technically this is an observable change, but it should be a nearly strict improvement. I'd consider this more of an optimization than a breaking change.

@thevilledev thevilledev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the clean implementation @rpb-ant! I think compare-and-swap on the item is a more elegant approach than a separate sync.Map.

One small follow-up to consider: having a brief note in the plugin readme that concurrent background fetches for the same entry are deduplicated. Can be this PR or a separate one.

Comment thread plugin/cache/handler.go
@rpb-ant

rpb-ant commented Mar 28, 2026

Copy link
Copy Markdown
Contributor Author

I updated the plugin documentation, very open to feedback on phrasing.

@rpb-ant rpb-ant force-pushed the cache-prefetch-dedup branch 2 times, most recently from 3c9aa7d to 0805bf3 Compare March 30, 2026 19:34
@rpb-ant

rpb-ant commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

Apologies for the missing DCO, fixed that and squashed everything down

Also updated plugin to document single-flighting

Signed-off-by: Ryan Brewster <rpb@anthropic.com>
@rpb-ant rpb-ant force-pushed the cache-prefetch-dedup branch from 0805bf3 to 96d49c5 Compare March 30, 2026 19:41
@thevilledev

Copy link
Copy Markdown
Collaborator

Thanks @rpb-ant - merging 🥇

@thevilledev thevilledev merged commit 20626a7 into coredns:master Mar 30, 2026
12 checks passed
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.

3 participants