fix: guard delete detection against non-integer/large primary keys (#42) - #51
Merged
Conversation
The first-poll branch built `[*1...current_ids.max]` from primary-key values, which raised "bad value for range" for non-integer keys (e.g. UUIDs) and, for large/sparse integer ids, allocated a huge array and emitted phantom delete events for ids that never existed. Extract the logic into `detect_deleted_ids`: the first poll only establishes a baseline (reports nothing deleted), and subsequent polls diff against the previous snapshot. Behavior is otherwise unchanged, including not mass-deleting on an empty result set. Add regression tests covering string keys, sparse ids, a normal delete, and an emptied result set. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 16, 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.
Summary
Fixes the
mysql_replicator: failed to execute query / bad value for rangeerror reported in #42.Root cause
On the first poll (no previous snapshot yet), delete detection ran:
This builds an integer
Rangefrom the primary-key values, which:bad value for rangewhen theprimary_keyis non-integer (e.g. a UUID or string id) — exactly mysql_replicator: failed to execute query.error #42;[*1...10_000_000]);1andmax).Fix
Extract the logic into
detect_deleted_ids(previous_ids, current_ids):The first poll now only establishes a baseline (reports nothing deleted); deletions are detected on subsequent polls by diffing against the previous snapshot. All other behavior is unchanged.
Tests
Added unit regression tests (no DB needed) covering:
bad value for range;Verified locally on Ruby 3.4 (
6 tests, 11 assertions, 0 failures).Closes #42
🤖 Generated with Claude Code