Skip to content

feat: add core content-defined chunking (CDC) infrastructure - #667

Merged
kalbasit merged 5 commits into
mainfrom
01-30-feat_add_core_content-defined_chunking_cdc_infrastructure
Jan 31, 2026
Merged

kalbasit merged 5 commits into
mainfrom
01-30-feat_add_core_content-defined_chunking_cdc_infrastructure

Conversation

@kalbasit

@kalbasit kalbasit commented Jan 31, 2026 •

Copy link
Copy Markdown
Owner

This commit adds the foundation for content-defined chunking and deduplication:

  • Implemented pkg/chunker using the FastCDC algorithm for efficient streaming deduplication.
  • Added database migrations for 'chunks' and 'nar_file_chunks' tables.
  • Implemented a local file-based chunk store with a two-level directory structure.
  • Includes unit tests for chunking logic and local storage.
  • Added github.com/kalbasit/fastcdc dependency.

Part of #322

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request go Pull requests that update go code labels Jan 31, 2026

kalbasit commented Jan 31, 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 establishes the core infrastructure for content-defined chunking and data deduplication. It provides a robust mechanism to break down data streams into variable-sized chunks based on their content, rather than fixed boundaries. This foundation is crucial for optimizing storage and network transfer by identifying and storing unique data segments only once, thereby reducing redundancy across various data objects.

Highlights

  • Content-Defined Chunking (CDC) Implementation: Introduced pkg/chunker utilizing the FastCDC algorithm for efficient streaming deduplication, dynamically splitting data into variable-sized chunks based on content.
  • Database Schema Additions: New migration files for MySQL, PostgreSQL, and SQLite were added to create chunks and nar_file_chunks tables, supporting chunk metadata and their association with NAR files.
  • Local Chunk Storage: Implemented a local file-based chunk store (pkg/storage/chunk/local.go) with a two-level directory structure for content-addressable storage, ensuring atomic writes.
  • Comprehensive Unit Testing: Added unit tests for both the chunking logic (pkg/chunker/chunker_test.go) and the local storage implementation (pkg/storage/chunk/local_test.go) to ensure correctness and reliability.
  • Dependency Management: Included github.com/jotfs/fastcdc-go as a new dependency to provide the FastCDC algorithm implementation.
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 introduces the foundational infrastructure for content-defined chunking (CDC). It adds a chunker package using the FastCDC algorithm, a local file-based storage for chunks, and the necessary database migrations. The implementation is solid, introducing a streaming chunking mechanism and atomic file writes for the chunk store. My review includes suggestions to improve schema efficiency in the database migrations by removing redundant indexes and using more precise column types, and to enhance the robustness of the local chunk store's file writing logic.

Comment thread pkg/storage/chunk/local.go Resolved
Comment thread pkg/storage/chunk/local.go Resolved
@kalbasit

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 introduces the core infrastructure for content-defined chunking (CDC), which is a great step towards deduplication. The implementation of the FastCDC algorithm in pkg/chunker is solid and the use of channels for streaming is well-done. The database migrations and local file store are also included, making this a comprehensive feature foundation. I've found a few areas for improvement, mainly concerning database schema correctness to prevent potential data truncation and a fragile file-writing pattern in the local chunk store that could be made more robust.

Comment thread pkg/storage/chunk/local.go Resolved
Comment thread pkg/storage/chunk/local.go Resolved
@kalbasit

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 introduces a solid foundation for content-defined chunking (CDC) and deduplication. The implementation includes the FastCDC algorithm via pkg/chunker, corresponding database migrations and schema updates for chunks and nar_file_chunks tables, and a local file-based chunk store. The code is well-structured and includes relevant unit tests. I've identified a few areas for improvement regarding database schema consistency, potential integer overflow on 32-bit systems, and resource management in the local storage implementation. Overall, this is a great addition.

Comment thread db/schema/mysql.sql Resolved
Comment thread db/schema/postgres.sql Resolved
Comment thread pkg/chunker/chunker.go Resolved
Comment thread pkg/storage/chunk/local.go Resolved
@kalbasit
kalbasit force-pushed the 01-30-feat_add_core_content-defined_chunking_cdc_infrastructure branch from 844b061 to 8b0a778 Compare January 31, 2026 06:03
@kalbasit

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 PR introduces a solid foundation for content-defined chunking. The use of the FastCDC algorithm via an external library is appropriate, and the streaming implementation using channels is well-designed. The local file storage implementation correctly uses atomic writes for data integrity. I've identified a few areas for improvement: there's a data type inconsistency for the chunk size across the different database schemas (MySQL vs. Postgres/SQLite), and the ref_count column in MySQL could be UNSIGNED. Overall, great work on adding this significant feature.

@kalbasit

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 introduces the foundational infrastructure for content-defined chunking (CDC) using the FastCDC algorithm. It adds new database tables chunks and nar_file_chunks with corresponding migrations for MySQL, PostgreSQL, and SQLite. A local file-based chunk store is also implemented, along with unit tests for the new chunking logic and storage.

My review focuses on ensuring data integrity in the database schemas and improving code clarity. I've found a few inconsistencies in the generated schema dump files compared to the migrations, which should be addressed. I've also suggested adding CHECK constraints to prevent invalid data in PostgreSQL and SQLite, noting that such schema changes should be applied consistently across all supported backends. Additionally, I've suggested a small refactoring in the local chunk store implementation for better readability.

Comment thread db/schema/postgres.sql Resolved
Comment thread db/schema/sqlite.sql Resolved
Comment thread pkg/storage/chunk/local.go Resolved
This commit adds the foundation for content-defined chunking and deduplication:
- Implemented pkg/chunker using the FastCDC algorithm for efficient streaming deduplication.
- Added database migrations for 'chunks' and 'nar_file_chunks' tables.
- Implemented a local file-based chunk store with a two-level directory structure.
- Includes unit tests for chunking logic and local storage.
- Added github.com/kalbasit/fastcdc dependency.
@kalbasit
kalbasit force-pushed the 01-30-feat_add_core_content-defined_chunking_cdc_infrastructure branch from 7a370b5 to a033c74 Compare January 31, 2026 20:23
@kalbasit

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 introduces a solid foundation for content-defined chunking and deduplication. The changes are well-structured, including the new pkg/chunker for the FastCDC algorithm, database migrations for the new chunks and nar_file_chunks tables, and a local file-based chunk store. The unit tests for the chunking logic and local storage are also a great addition. I've identified a potential race condition in the local chunk store implementation that could affect data integrity (though its immediate impact might be mitigated in single-process environments if documented as technical debt) and a minor improvement for directory cleanup. Overall, this is a great step forward for the project.

Comment thread pkg/storage/chunk/local.go Resolved
Comment thread pkg/storage/chunk/local.go Resolved
@codecov

codecov Bot commented Jan 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.51%. Comparing base (3839a24) to head (bc4fc85).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #667   +/-   ##
=======================================
  Coverage   69.51%   69.51%           
=======================================
  Files           2        2           
  Lines         479      479           
=======================================
  Hits          333      333           
  Misses        129      129           
  Partials       17       17           

☔ 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

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 lays a solid foundation for content-defined chunking. It introduces a chunker package using the FastCDC algorithm, a local file-based chunk store, and corresponding database migrations for MySQL, PostgreSQL, and SQLite. The new functionality is accompanied by a good set of unit tests. My main feedback is focused on improving the channel-based concurrency pattern in the chunker to make it more robust and prevent potential race conditions. Overall, this is a great addition.

Comment thread pkg/chunker/chunker.go Resolved
Comment thread pkg/chunker/chunker_test.go Resolved
@kalbasit

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 introduces a solid foundation for content-defined chunking. The new chunker package provides an efficient, streaming implementation of FastCDC, and it's well-tested for correctness and concurrency. The storage/chunk package offers a clean interface for chunk storage, with a robust local file system implementation that correctly handles atomic writes and cleanup. The database migrations are consistent across all supported database engines. The code is of high quality. I have one minor suggestion to improve API clarity.

Comment thread pkg/storage/chunk/store.go Resolved
@kalbasit
kalbasit enabled auto-merge (squash) January 31, 2026 23:39
@kalbasit
kalbasit disabled auto-merge January 31, 2026 23:42
@kalbasit
kalbasit enabled auto-merge (squash) January 31, 2026 23:42
@kalbasit
kalbasit merged commit c9d95f9 into main Jan 31, 2026
@kalbasit
kalbasit deleted the 01-30-feat_add_core_content-defined_chunking_cdc_infrastructure branch January 31, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant