Skip to content

fix: check for CDC chunks when verifying NAR existence in GetNarInfo - #747

Merged
kalbasit merged 2 commits into
mainfrom
02-05-fix_use_int64_for_the_chunk_index_split
Feb 5, 2026
Merged

kalbasit merged 2 commits into
mainfrom
02-05-fix_use_int64_for_the_chunk_index_split

Conversation

@kalbasit

@kalbasit kalbasit commented Feb 5, 2026 •

Copy link
Copy Markdown
Owner

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.

Part of #322

Co-Authored-By: Claude Sonnet 4.5 [email protected]

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working go Pull requests that update go code labels Feb 5, 2026

kalbasit commented Feb 5, 2026 •

Copy link
Copy Markdown
Owner Author

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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

  • Fix for CDC Chunk Verification: The GetNarInfo function in pkg/cache/cache.go has been updated to correctly check for NARs stored as Content-Defined Chunks (CDC) in addition to whole files. Previously, it only checked for whole files, leading to incorrect cache purges and unnecessary re-downloads when CDC was enabled.
  • Improved Cache Efficiency: This fix resolves issues such as 'narinfo found in database but no nar in storage' errors, frequent re-downloads, and a significantly slower Time To First Byte (TTFB) for CDC-stored NARs, effectively restoring cache functionality for these items.
  • New Regression Test: A new regression test, testCDCGetNarInfo, has been added to pkg/cache/cdc_test.go. This test verifies that GetNarInfo correctly identifies and retrieves CDC-chunked NARs without triggering false purges, ensuring the fix works as intended.
Changelog
  • pkg/cache/cache.go
    • Modified getNarInfoFromDatabase to check for NAR existence using both narStore.HasNar() (for whole files) and c.HasNarInChunks() (for CDC chunks) before initiating a purge.
    • Updated comments to clarify the dual-check mechanism for NAR storage.
  • pkg/cache/cdc_test.go
    • Added testCDCGetNarInfo to the runCDCTestSuite to specifically test GetNarInfo's behavior with CDC-chunked NARs.
    • Implemented testCDCGetNarInfo to simulate storing a NAR with CDC enabled and then verifying that GetNarInfo successfully retrieves it without purging its metadata or chunks.
Activity
  • The pull request was co-authored by Claude Sonnet 4.5, indicating AI assistance in its creation.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot 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.

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.

Comment thread pkg/cache/cdc_test.go Resolved
Comment thread pkg/cache/cache.go Resolved
Base automatically changed from 02-05-fix_use_int64_for_the_chunk_index to main February 5, 2026 11:00
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Feb 5, 2026
kalbasit and others added 2 commits February 5, 2026 03:00
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]>
@kalbasit
kalbasit force-pushed the 02-05-fix_use_int64_for_the_chunk_index_split branch from 1f8d16d to 7ff8967 Compare February 5, 2026 11:12
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 5, 2026
@kalbasit

kalbasit commented Feb 5, 2026

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

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.

@kalbasit
kalbasit enabled auto-merge (squash) February 5, 2026 11:15
@codecov

codecov Bot commented Feb 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.41%. Comparing base (f7d6d82) to head (7ff8967).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalbasit
kalbasit merged commit 4cfeaa0 into main Feb 5, 2026
16 checks passed
@kalbasit
kalbasit deleted the 02-05-fix_use_int64_for_the_chunk_index_split branch February 5, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant