Skip to content

refactor: consolidate chunker constructors into NewChunker with ChunkerConfig#705

Merged
morgo merged 1 commit into
block:mainfrom
morgo:chunker-config-refactor
Apr 28, 2026
Merged

refactor: consolidate chunker constructors into NewChunker with ChunkerConfig#705
morgo merged 1 commit into
block:mainfrom
morgo:chunker-config-refactor

Conversation

@morgo
Copy link
Copy Markdown
Collaborator

@morgo morgo commented Apr 28, 2026

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:

func NewChunker(t *TableInfo, config ChunkerConfig) (Chunker, error)

ChunkerConfig is a struct with optional fields that all have sensible defaults:

  • NewTable — destination table (defaults to source table for move operations)
  • 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

Changes

  • pkg/table/chunker.go — Introduce ChunkerConfig struct and collapse four constructors into one. When Key is set, the composite chunker is always selected regardless of whether the table has a single-column auto-increment PK.
  • pkg/table/chunker_composite.go — Extract resolveKey() from SetKey() so that key resolution can be deferred to open() when key/where are provided via config at construction time. SetKey() still works as before for direct callers.
  • All callers updatedpkg/migration/runner.go, pkg/move/runner.go, and all test files in pkg/table, pkg/copier, pkg/checksum, and pkg/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).

…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
@morgo morgo marked this pull request as ready for review April 28, 2026 15:28
@morgo morgo enabled auto-merge April 28, 2026 15:38
@morgo morgo merged commit 6d24f82 into block:main Apr 28, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants