Skip to content

fix: use int64 for the chunk index - #746

Merged
kalbasit merged 1 commit into
mainfrom
02-05-fix_use_int64_for_the_chunk_index
Feb 5, 2026
Merged

kalbasit merged 1 commit into
mainfrom
02-05-fix_use_int64_for_the_chunk_index

Conversation

@kalbasit

@kalbasit kalbasit commented Feb 5, 2026

Copy link
Copy Markdown
Owner

While it's not a concern for one NAR to be chunked into more chunks than
an int32 can handle, the performance and storage gain is simply not
worth the special handling I had to do in order to support int32.
Convert to int64 to keep the code simpler and the database essentially
limitless in terms of number of chunks.

While it's not a concern for one NAR to be chunked into more chunks than
an int32 can handle, the performance and storage gain is simply not
worth the special handling I had to do in order to support int32.
Convert to int64 to keep the code simpler and the database essentially
limitless in terms of number of chunks.
@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
@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 standardizes the data types for chunk indexing and total chunk counts by migrating them from int32 to int64 throughout the system. This change simplifies the codebase by eliminating the need for special handling of int32's limitations, thereby enhancing the system's capacity to manage a significantly larger number of chunks per NAR file and improving overall scalability.

Highlights

  • Database Schema Updates: The chunk_index column in nar_file_chunks and the total_chunks column in nar_files have been updated from INT/INTEGER to BIGINT across MySQL, PostgreSQL, and SQLite database schemas and their respective migration files.
  • Go Type Refactoring: Corresponding Go types for chunkCount, totalChunks, and chunkIndex have been changed from int32 to int64 in pkg/cache/cache.go and various generated database model and query files (pkg/database/generated_models.go, pkg/database/mysqldb/models.go, pkg/database/mysqldb/query.mysql.sql.go, etc.).
  • SQLC Configuration Adjustment: Explicit go_type: int32 overrides for nar_file_chunks.chunk_index and nar_files.total_chunks have been removed from sqlc.yml, allowing sqlc to correctly infer int64 for the BIGINT database columns.
Changelog
  • db/migrations/mysql/20260131021850_add_chunks.sql
    • Changed chunk_index column type from INT to BIGINT.
  • db/migrations/mysql/20260205063659_add_total_chunks_to_nar_files.sql
    • Changed total_chunks column type from INTEGER to BIGINT(20).
  • db/migrations/postgres/20260131021850_add_chunks.sql
    • Changed chunk_index column type from INTEGER to BIGINT.
  • db/migrations/postgres/20260205063658_add_total_chunks_to_nar_files.sql
    • Changed total_chunks column type from INTEGER to BIGINT.
  • db/migrations/sqlite/20260205063651_add_total_chunks_to_nar_files.sql
    • Changed total_chunks column type from INTEGER to BIGINT.
  • db/schema/mysql.sql
    • Updated chunk_index and total_chunks column types to BIGINT(20).
  • db/schema/postgres.sql
    • Updated chunk_index and total_chunks column types to BIGINT.
  • db/schema/sqlite.sql
    • Updated total_chunks column type to BIGINT.
  • pkg/cache/cache.go
    • Updated chunkCount and totalChunks variables and function parameters from int32 to int64.
  • pkg/database/generated_models.go
    • Updated TotalChunks and ChunkIndex fields in various generated structs from int32 to int64.
  • pkg/database/mysqldb/models.go
    • Updated TotalChunks and ChunkIndex fields in NarFile and NarFileChunk structs from int32 to int64.
  • pkg/database/mysqldb/query.mysql.sql.go
    • Updated TotalChunks and ChunkIndex types in various query parameter and result structs from int32 to int64.
  • pkg/database/postgresdb/models.go
    • Updated TotalChunks and ChunkIndex fields in NarFile and NarFileChunk structs from int32 to int64.
  • pkg/database/postgresdb/query.postgres.sql.go
    • Updated TotalChunks and ChunkIndex types in various query parameter and result structs from int32 to int64.
  • pkg/database/sqlitedb/models.go
    • Updated TotalChunks and ChunkIndex fields in NarFile and NarFileChunk structs from int32 to int64.
  • pkg/database/sqlitedb/query.sqlite.sql.go
    • Updated TotalChunks and ChunkIndex types in various query parameter and result structs from int32 to int64.
  • sqlc.yml
    • Removed explicit go_type overrides for nar_file_chunks.chunk_index and nar_files.total_chunks.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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. ↩

kalbasit commented Feb 5, 2026 •

Copy link
Copy Markdown
Owner Author

@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 aims to simplify the codebase by changing the data type for chunk indices and total chunk counts from int32 to int64. The changes are applied across database migrations, schemas, and Go code for MySQL and PostgreSQL. This is a good simplification.

I've identified one critical issue that will cause a compilation failure and one minor style improvement. Additionally, it appears the database migration for chunk_index in SQLite was missed. While this may not cause a functional issue due to how SQLite and sqlc handle INTEGER types, it creates an inconsistency in the database schemas that should be rectified.

Comment thread pkg/cache/cache.go
// streamCompleteChunks streams all chunks for a NAR that has completed chunking.
// This is the fast path where all chunks are available immediately.
func (c *Cache) streamCompleteChunks(ctx context.Context, w io.Writer, narFileID int64, totalChunks int32) error {
func (c *Cache) streamCompleteChunks(ctx context.Context, w io.Writer, narFileID int64, totalChunks int64) error {

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.

critical

Changing totalChunks to int64 here introduces a compilation error on line 4188. The capacity argument for make must be of type int. Please cast totalChunks to int when creating the slice: // On line 4188 chunkHashes := make([]string, 0, int(totalChunks))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gemini-code-assist it's compiling fine...

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.

Hello @kalbasit,

Thanks for your feedback. While the change to the function signature on line 4186 itself might compile, the issue arises on line 4188 where totalChunks is used as the capacity argument for make.

The Go language specification requires the capacity argument for make to be of type int. When totalChunks is an int64 variable, the Go compiler will typically report a type mismatch error, such as cannot use totalChunks (type int64) as type int in argument to make.

It's possible your local environment or specific Go version might be more lenient in certain contexts, but to ensure strict adherence to the Go specification and avoid potential issues across different build environments, an explicit type conversion is necessary.

Please consider adding an explicit cast to int for totalChunks on line 4188:

chunkHashes := make([]string, 0, int(totalChunks))

This ensures type correctness and portability.

@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 (7ec4318) to head (3ce2a45).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #746   +/-   ##
=======================================
  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 f7d6d82 into main Feb 5, 2026
17 checks passed
@kalbasit
kalbasit deleted the 02-05-fix_use_int64_for_the_chunk_index branch February 5, 2026 11:00
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