Skip to content

feat: add compressed_size column to chunks table for CDC compression tracking#860

Merged
kalbasit merged 1 commit intomainfrom
02-11-feat_add_compressed_size_column_to_chunks_table_for_cdc_compression_tracking
Feb 12, 2026
Merged

feat: add compressed_size column to chunks table for CDC compression tracking#860
kalbasit merged 1 commit intomainfrom
02-11-feat_add_compressed_size_column_to_chunks_table_for_cdc_compression_tracking

Conversation

@kalbasit
Copy link
Owner

The chunks table now includes a compressed_size column to track the
actual size of chunks after compression. This is necessary for accurate
space management and decompression planning when using
Content-Addressable Storage (CAS) with Content-Defined Chunking (CDC).

  • Modified existing migrations for MySQL, PostgreSQL, and SQLite to
    include the compressed_size column in the chunks table.
  • Updated database schemas for all backends to reflect the new column.
  • Regenerated Go database code using gen-db-wrappers, which introduced
    specific row structs for GetChunksByNarFileID and
    GetOrphanedChunks queries to handle the updated schema correctly.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 12, 2026
@dosubot
Copy link

dosubot bot commented Feb 12, 2026

Related Documentation

Checked 7 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@gemini-code-assist
Copy link
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 enhances the chunks table by introducing a compressed_size column, which is crucial for managing space and planning decompression within Content-Addressable Storage (CAS) and Content-Defined Chunking (CDC systems. The changes propagate through database migrations, schema definitions, and the automatically generated Go database access code, ensuring full compatibility and functionality with the new data point.

Highlights

  • Database Schema Update: Added a new compressed_size column to the chunks table across MySQL, PostgreSQL, and SQLite database migrations and schemas to track the actual size of chunks after compression.
  • Go Database Code Regeneration: Regenerated Go database wrappers (gen-db-wrappers) to reflect the new compressed_size column in the Chunk struct and introduced specific row structs (GetChunkByNarFileIDAndIndexRow, GetChunksByNarFileIDRow, GetOrphanedChunksRow) for certain queries to handle the updated schema.
  • Query Updates: Modified various database queries and their corresponding Go wrapper functions to include the new compressed_size column in SELECT statements and to correctly map results to the updated Chunk struct or the newly generated row structs.
Changelog
  • db/migrations/mysql/20260131021850_add_chunks.sql
    • Added compressed_size column with a default value of 0 to the chunks table.
  • db/migrations/postgres/20260131021850_add_chunks.sql
    • Added compressed_size column with a default value of 0 and a check constraint to the chunks table.
  • db/migrations/sqlite/20260131021850_add_chunks.sql
    • Added compressed_size column with a default value of 0 and a check constraint to the chunks table.
  • db/schema/mysql.sql
    • Updated the chunks table definition to include the compressed_size column.
  • db/schema/postgres.sql
    • Updated the chunks table definition to include the compressed_size column and its check constraint.
  • db/schema/sqlite.sql
    • Updated the chunks table definition to include the compressed_size column and its check constraint.
  • pkg/database/generated_models.go
    • Added CompressedSize field to the Chunk struct.
    • Introduced GetChunkByNarFileIDAndIndexRow struct.
    • Introduced GetChunksByNarFileIDRow struct.
    • Introduced GetOrphanedChunksRow struct.
  • pkg/database/generated_querier.go
    • Updated CreateChunk query to return compressed_size.
    • Updated GetChunkByHash query to return compressed_size.
    • Updated GetChunkByID query to return compressed_size.
    • Modified GetChunkByNarFileIDAndIndex return type to GetChunkByNarFileIDAndIndexRow.
    • Modified GetChunksByNarFileID return type to []GetChunksByNarFileIDRow.
    • Modified GetOrphanedChunks return type to []GetOrphanedChunksRow.
  • pkg/database/generated_wrapper_mysql.go
    • Mapped CompressedSize in GetChunkByHash and GetChunkByID results.
    • Updated GetChunkByNarFileIDAndIndex function signature and return type.
    • Updated GetChunksByNarFileID function signature and return type.
    • Updated GetOrphanedChunks function signature and return type.
  • pkg/database/generated_wrapper_postgres.go
    • Mapped CompressedSize in CreateChunk, GetChunkByHash, and GetChunkByID results.
    • Updated GetChunkByNarFileIDAndIndex function signature and return type.
    • Updated GetChunksByNarFileID function signature and return type.
    • Updated GetOrphanedChunks function signature and return type.
  • pkg/database/generated_wrapper_sqlite.go
    • Mapped CompressedSize in CreateChunk, GetChunkByHash, and GetChunkByID results.
    • Updated GetChunkByNarFileIDAndIndex function signature and return type.
    • Updated GetChunksByNarFileID function signature and return type.
    • Updated GetOrphanedChunks function signature and return type.
  • pkg/database/mysqldb/models.go
    • Added CompressedSize field to the Chunk struct.
  • pkg/database/mysqldb/querier.go
    • Updated GetChunkByHash query to select compressed_size.
    • Updated GetChunkByID query to select compressed_size.
    • Modified GetChunkByNarFileIDAndIndex return type to GetChunkByNarFileIDAndIndexRow.
    • Modified GetChunksByNarFileID return type to []GetChunksByNarFileIDRow.
    • Modified GetOrphanedChunks return type to []GetOrphanedChunksRow.
  • pkg/database/mysqldb/query.mysql.sql.go
    • Updated GetChunkByHash SQL query and scan logic to include compressed_size.
    • Updated GetChunkByID SQL query and scan logic to include compressed_size.
    • Introduced GetChunkByNarFileIDAndIndexRow struct and updated GetChunkByNarFileIDAndIndex function signature and scan logic.
    • Introduced GetChunksByNarFileIDRow struct and updated GetChunksByNarFileID function signature and scan logic.
    • Introduced GetOrphanedChunksRow struct and updated GetOrphanedChunks function signature and scan logic.
  • pkg/database/postgresdb/models.go
    • Added CompressedSize field to the Chunk struct.
  • pkg/database/postgresdb/querier.go
    • Updated CreateChunk query to return compressed_size.
    • Updated GetChunkByHash query to select compressed_size.
    • Updated GetChunkByID query to select compressed_size.
    • Modified GetChunkByNarFileIDAndIndex return type to GetChunkByNarFileIDAndIndexRow.
    • Modified GetChunksByNarFileID return type to []GetChunksByNarFileIDRow.
    • Modified GetOrphanedChunks return type to []GetOrphanedChunksRow.
  • pkg/database/postgresdb/query.postgres.sql.go
    • Updated CreateChunk SQL query and scan logic to include compressed_size.
    • Updated GetChunkByHash SQL query and scan logic to include compressed_size.
    • Updated GetChunkByID SQL query and scan logic to include compressed_size.
    • Introduced GetChunkByNarFileIDAndIndexRow struct and updated GetChunkByNarFileIDAndIndex function signature and scan logic.
    • Introduced GetChunksByNarFileIDRow struct and updated GetChunksByNarFileID function signature and scan logic.
    • Introduced GetOrphanedChunksRow struct and updated GetOrphanedChunks function signature and scan logic.
  • pkg/database/sqlitedb/models.go
    • Added CompressedSize field to the Chunk struct.
  • pkg/database/sqlitedb/querier.go
    • Updated CreateChunk query to return compressed_size.
    • Updated GetChunkByHash query to select compressed_size.
    • Updated GetChunkByID query to select compressed_size.
    • Modified GetChunkByNarFileIDAndIndex return type to GetChunkByNarFileIDAndIndexRow.
    • Modified GetChunksByNarFileID return type to []GetChunksByNarFileIDRow.
    • Modified GetOrphanedChunks return type to []GetOrphanedChunksRow.
  • pkg/database/sqlitedb/query.sqlite.sql.go
    • Updated CreateChunk SQL query and scan logic to include compressed_size.
    • Updated GetChunkByHash SQL query and scan logic to include compressed_size.
    • Updated GetChunkByID SQL query and scan logic to include compressed_size.
    • Introduced GetChunkByNarFileIDAndIndexRow struct and updated GetChunkByNarFileIDAndIndex function signature and scan logic.
    • Introduced GetChunksByNarFileIDRow struct and updated GetChunksByNarFileID function signature and scan logic.
    • Introduced GetOrphanedChunksRow struct and updated GetOrphanedChunks function signature and scan logic.
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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 compressed_size column to the chunks table across all supported databases (MySQL, PostgreSQL, SQLite) to track the size of compressed data. The changes include database migrations, schema updates, and regeneration of the Go database access layer code. The implementation is mostly correct, but there is a type inconsistency in the generated Go code for the new compressed_size column. It's defined as int32 in the unified model, while different database backends generate uint32 (MySQL) or int64 (SQLite). This leads to type casting in the wrapper code that could cause data overflow. I've suggested a fix in sqlc.yml to unify the type as uint32, consistent with the existing size column.

@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

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

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #860   +/-   ##
=====================================
  Coverage   3.96%   3.96%           
=====================================
  Files          6       6           
  Lines        429     429           
=====================================
  Hits          17      17           
  Misses       409     409           
  Partials       3       3           

☔ 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.

…tracking

The `chunks` table now includes a `compressed_size` column to track the
actual size of chunks after compression. This is necessary for accurate
space management and decompression planning when using
Content-Addressable Storage (CAS) with Content-Defined Chunking (CDC).

- Modified existing migrations for MySQL, PostgreSQL, and SQLite to
  include the `compressed_size` column in the `chunks` table.
- Updated database schemas for all backends to reflect the new column.
- Regenerated Go database code using `gen-db-wrappers`, which introduced
  specific row structs for `GetChunksByNarFileID` and
  `GetOrphanedChunks` queries to handle the updated schema correctly.
@kalbasit kalbasit force-pushed the 02-11-feat_add_compressed_size_column_to_chunks_table_for_cdc_compression_tracking branch from a3da67f to a0ba5be Compare February 12, 2026 05:32
@kalbasit kalbasit enabled auto-merge (squash) February 12, 2026 06:12
@kalbasit kalbasit merged commit 012dba9 into main Feb 12, 2026
20 of 23 checks passed
@kalbasit kalbasit deleted the 02-11-feat_add_compressed_size_column_to_chunks_table_for_cdc_compression_tracking branch February 12, 2026 06:12
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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants