Repository navigation
fix: check for CDC chunks when verifying NAR existence in GetNarInfo - #747
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Summary of ChangesHello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical caching bug where the system failed to recognize NARs stored using Content-Defined Chunking (CDC). The previous implementation incorrectly assumed NARs were missing if not found as whole files, leading to performance degradation and cache invalidation. The updated logic now properly accounts for CDC-chunked storage, ensuring correct cache behavior and significantly improving retrieval times for such data. A dedicated test case has been introduced to prevent future regressions. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes a critical bug where NAR metadata was being purged incorrectly when Content-Defined Chunking (CDC) is enabled. The fix in pkg/cache/cache.go correctly checks for the existence of NARs stored as chunks before deciding to purge, which resolves the issue of unnecessary re-downloads and performance degradation.
I have one minor suggestion to improve the conciseness of the implementation.
However, the new regression test in pkg/cache/cdc_test.go appears to be flawed. It does not correctly simulate the scenario that triggers the bug, as it doesn't involve a GetNarInfo call on a database-resident narinfo. I've left a critical comment with details on how to correct the test to ensure it properly covers the bug fix.
When CDC (Content-Defined Chunking) is enabled, NARs are stored as chunks in the database rather than as whole files in storage. The GetNarInfo function was only checking for whole files using narStore.HasNar(), causing it to incorrectly purge metadata and re-download NARs that were already cached as chunks. This resulted in: - "narinfo found in database but no nar in storage" errors - Unnecessary re-downloads from upstream on every request - Cache effectively disabled for CDC-stored NARs - ~6-9 second TTFB instead of ~0.03-0.05 seconds (180x slower) Fix by following the established pattern used elsewhere in the codebase: check both narStore.HasNar() for whole files AND HasNarInChunks() for CDC chunks before determining if a NAR is missing. Add regression test that verifies GetNarInfo works correctly with CDC-chunked NARs and doesn't trigger false purges. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1f8d16d to
7ff8967
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a critical bug where NARs stored as CDC chunks were not being found, causing performance issues and unnecessary re-downloads. The fix consistently checks for both whole files and chunked NARs across multiple functions (GetNar, getNarInfoFromDatabase, checkAndFixNarInfo) and adds a solid regression test to prevent this issue from recurring. The logic is sound. I've added one low-severity suggestion to refactor a duplicated NAR existence check into a helper method for improved maintainability, noting that such duplication can sometimes be acceptable per repository guidelines.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #747 +/- ##
=======================================
Coverage 85.41% 85.41%
=======================================
Files 2 2
Lines 480 480
=======================================
Hits 410 410
Misses 65 65
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|

When CDC (Content-Defined Chunking) is enabled, NARs are stored as chunks
in the database rather than as whole files in storage. The GetNarInfo
function was only checking for whole files using narStore.HasNar(), causing
it to incorrectly purge metadata and re-download NARs that were already
cached as chunks.
This resulted in:
Fix by following the established pattern used elsewhere in the codebase:
check both narStore.HasNar() for whole files AND HasNarInChunks() for
CDC chunks before determining if a NAR is missing.
Add regression test that verifies GetNarInfo works correctly with
CDC-chunked NARs and doesn't trigger false purges.
Part of #322
Co-Authored-By: Claude Sonnet 4.5 [email protected]