Repository navigation
feat: implement progressive chunk streaming for CDC concurrent downloads - #743
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 introduces a significant enhancement to the Content-Defined Chunking (CDC) download process by enabling progressive streaming. Previously, concurrent requests for a NAR file undergoing CDC chunking could result in partial data being served due to a race condition. The core of this change involves a database schema modification to track the chunking status more precisely and a refactoring of the NAR retrieval logic to support both immediate and progressive streaming. This ensures that multiple clients can reliably access NAR files, even when they are still being processed, thereby improving the robustness and concurrency of the caching system. 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 is an excellent pull request that addresses a tricky race condition in concurrent downloads with a robust and well-designed solution. The introduction of the total_chunks field to manage the state of CDC operations is a great approach. The new progressive streaming logic in getNarFromChunks is well-implemented, with thoughtful handling of polling, timeouts, and fast/slow paths. It's particularly impressive that this is backed by a re-enabled distributed test that now passes, which gives high confidence in the fix. The database migrations and query updates are clean and consistent across all supported engines. I have a couple of minor suggestions for code cleanup, but overall, this is a high-quality contribution.
e9b9e0b to
8b1ce64
Compare
8b1ce64 to
e423cb3
Compare
efed176 to
56ab810
Compare
ba1e37b to
3581de3
Compare
3581de3 to
ca05c7e
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a total_chunks column to the nar_files table across all database types to enable progressive streaming of NAR files during content-defined chunking (CDC). Database schemas, migrations, and generated query code were updated to support this new column and associated operations, including GetChunkByNarFileIDAndIndex and UpdateNarFileTotalChunks. The application logic was refactored to initialize total_chunks to 0 when a NAR file record is created and update it upon chunking completion. A new HasNarFileRecord function was added to check for a NAR file's existence regardless of chunking status, allowing concurrent requests to start streaming progressively via streamProgressiveChunks while another instance is still chunking. The HasNarInChunks function was updated to specifically indicate chunking completion. Tests were added and modified to verify this progressive streaming behavior and the new HasNarFileRecord functionality. Review comments suggest optimizing the HasNarFileRecord function by removing unnecessary transaction management for read-only queries and removing an unused narURL parameter from the streamProgressiveChunks function signature and its call site.
This change fixes a race condition where multiple cache instances requesting the same NAR file during CDC chunking would receive partial data because HasNarInChunks() returned true as soon as any chunk existed. The solution adds a total_chunks field to the nar_files table to track CDC operation status (NULL=legacy data, 0=in-progress, >0=complete). The HasNarInChunks function now only returns true when total_chunks > 0, preventing premature reads. The getNarFromChunks function has been rewritten to support two streaming paths: - Fast path: Loads all chunk hashes at once when chunking is complete - Progressive path: Polls and streams chunks one-by-one as they appear during in-progress chunking operations (200ms polling interval, 30s per-chunk timeout) This enables multiple instances to successfully stream chunks while another instance is still performing CDC chunking, eliminating the partial data issue. The CDC distributed test has been re-enabled and now passes with all 3 instances successfully retrieving the complete 12MB NAR file. Database migrations have been added for all three engines (SQLite, PostgreSQL, MySQL) to add the total_chunks column, and new SQL queries support chunk-by-index retrieval and completion status updates. Part of #322
ca05c7e to
104111f
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a robust solution for a race condition in concurrent CDC chunk downloads by adding a total_chunks field to track chunking status. The implementation of progressive chunk streaming is a significant improvement, allowing clients to stream NARs while they are still being chunked. The database migrations and new SQL queries are well-integrated, and the addition of comprehensive distributed tests validates the fix effectively. My review includes a couple of suggestions for performance optimization and code clarity, including documenting an accepted risk related to integer overflow as per repository guidelines.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #743 +/- ##
=======================================
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:
|

This change fixes a race condition where multiple cache instances requesting
the same NAR file during CDC chunking would receive partial data because
HasNarInChunks() returned true as soon as any chunk existed.
The solution adds a total_chunks field to the nar_files table to track CDC
operation status (NULL=legacy data, 0=in-progress, >0=complete). The
HasNarInChunks function now only returns true when total_chunks > 0,
preventing premature reads.
The getNarFromChunks function has been rewritten to support two streaming
paths:
during in-progress chunking operations (200ms polling interval, 30s
per-chunk timeout)
This enables multiple instances to successfully stream chunks while another
instance is still performing CDC chunking, eliminating the partial data
issue. The CDC distributed test has been re-enabled and now passes with all
3 instances successfully retrieving the complete 12MB NAR file.
Database migrations have been added for all three engines (SQLite,
PostgreSQL, MySQL) to add the total_chunks column, and new SQL queries
support chunk-by-index retrieval and completion status updates.
Part of #322