refactor: consolidate chunker constructors into NewChunker with ChunkerConfig#705
Merged
Merged
Conversation
…erConfig Replace the four chunker constructor functions (newChunker, NewChunker, NewCompositeChunker, newCompositeChunkerWithDestination) with a single NewChunker(t *TableInfo, config ChunkerConfig) function. ChunkerConfig is a struct with optional fields: - NewTable: destination table (defaults to source table) - TargetChunkTime: target duration per chunk (defaults to ChunkerDefaultTarget) - Logger: structured logger (defaults to slog.Default()) - Key/Where: force composite chunker on a specific secondary index When Key is set, the composite chunker is always selected regardless of whether the table has a single-column auto-increment PK. Key resolution (DescIndex + PK column merging) is deferred to open() instead of happening at construction time, which is consistent with how the chunker already defers other initialization. This is a pure refactor with no behavior change — it prepares the constructor for upcoming features (ColumnMapping, MappedChunker interface) that need to pass additional configuration at chunker creation time. Part of block#701
aparajon
approved these changes
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Pull Request should be associated with an Issue.
Related: #701 (pre-requisite refactor)
Summary
Replaces the four chunker constructor functions (
newChunker,NewChunker,NewCompositeChunker,newCompositeChunkerWithDestination) with a single unified constructor:ChunkerConfigis a struct with optional fields that all have sensible defaults:ChunkerDefaultTarget)slog.Default())Changes
pkg/table/chunker.go— IntroduceChunkerConfigstruct and collapse four constructors into one. WhenKeyis set, the composite chunker is always selected regardless of whether the table has a single-column auto-increment PK.pkg/table/chunker_composite.go— ExtractresolveKey()fromSetKey()so that key resolution can be deferred toopen()when key/where are provided via config at construction time.SetKey()still works as before for direct callers.pkg/migration/runner.go,pkg/move/runner.go, and all test files inpkg/table,pkg/copier,pkg/checksum, andpkg/repl.Why
This is a pure refactor with no behavior change. It prepares the constructor for upcoming features (ColumnMapping, MappedChunker interface) that need to pass additional configuration at chunker creation time, as part of the work to support column rename operations (#701).