address partition overflow bug#4550
Merged
Merged
Conversation
jgao54
commented
Jul 8, 2026
Comment on lines
+96
to
+137
| t.Run("int range spanning full int64 domain does not overflow", func(t *testing.T) { | ||
| helper := NewPartitionHelper(logger) | ||
| require.NoError(t, helper.AddPartitionsWithRange(int64(math.MinInt64), int64(math.MaxInt64), 7)) | ||
|
|
||
| partitions := helper.GetPartitions() | ||
| require.Len(t, partitions, 7) | ||
| require.Equal(t, int64(math.MinInt64), intRangeOf(t, partitions[0]).Start) | ||
| require.Equal(t, int64(math.MaxInt64), intRangeOf(t, partitions[len(partitions)-1]).End) | ||
| for i, partition := range partitions { | ||
| r := intRangeOf(t, partition) | ||
| require.LessOrEqual(t, r.Start, r.End) | ||
| if i > 0 { | ||
| require.Equal(t, intRangeOf(t, partitions[i-1]).End+1, r.Start) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| t.Run("uint range spanning full uint64 domain does not overflow", func(t *testing.T) { | ||
| helper := NewPartitionHelper(logger) | ||
| require.NoError(t, helper.AddPartitionsWithRange(uint64(0), uint64(math.MaxUint64), 7)) | ||
|
|
||
| partitions := helper.GetPartitions() | ||
| require.Len(t, partitions, 7) | ||
| require.Equal(t, uint64(0), uintRangeOf(t, partitions[0]).Start) | ||
| require.Equal(t, uint64(math.MaxUint64), uintRangeOf(t, partitions[len(partitions)-1]).End) | ||
| for i, partition := range partitions { | ||
| r := uintRangeOf(t, partition) | ||
| require.LessOrEqual(t, r.Start, r.End) | ||
| if i > 0 { | ||
| require.Equal(t, uintRangeOf(t, partitions[i-1]).End+1, r.Start) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| t.Run("span smaller than partition count yields fewer partitions", func(t *testing.T) { | ||
| helper := NewPartitionHelper(logger) | ||
| require.NoError(t, helper.AddPartitionsWithRange(int64(0), int64(5), 10)) | ||
|
|
||
| partitions := helper.GetPartitions() | ||
| require.Len(t, partitions, 5) | ||
| require.Equal(t, int64(5), intRangeOf(t, partitions[len(partitions)-1]).End) | ||
| }) |
Contributor
Author
There was a problem hiding this comment.
these tests were all failing before the fix
❌ 2 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Contributor
🔄 Flaky Test DetectedAnalysis: Test_MySQL_BinlogIncident failed with a transient MySQL handshake connection error ("readInitialHandshake EOF: connection was bad") while connecting to a freshly-started one-off MySQL testcontainer, a startup race/infra flake rather than a code bug. ✅ Automatically retrying the workflow |
ilidemi
approved these changes
Jul 9, 2026
Comment on lines
+96
to
+137
| t.Run("int range spanning full int64 domain does not overflow", func(t *testing.T) { | ||
| helper := NewPartitionHelper(logger) | ||
| require.NoError(t, helper.AddPartitionsWithRange(int64(math.MinInt64), int64(math.MaxInt64), 7)) | ||
|
|
||
| partitions := helper.GetPartitions() | ||
| require.Len(t, partitions, 7) | ||
| require.Equal(t, int64(math.MinInt64), intRangeOf(t, partitions[0]).Start) | ||
| require.Equal(t, int64(math.MaxInt64), intRangeOf(t, partitions[len(partitions)-1]).End) | ||
| for i, partition := range partitions { | ||
| r := intRangeOf(t, partition) | ||
| require.LessOrEqual(t, r.Start, r.End) | ||
| if i > 0 { | ||
| require.Equal(t, intRangeOf(t, partitions[i-1]).End+1, r.Start) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| t.Run("uint range spanning full uint64 domain does not overflow", func(t *testing.T) { | ||
| helper := NewPartitionHelper(logger) | ||
| require.NoError(t, helper.AddPartitionsWithRange(uint64(0), uint64(math.MaxUint64), 7)) | ||
|
|
||
| partitions := helper.GetPartitions() | ||
| require.Len(t, partitions, 7) | ||
| require.Equal(t, uint64(0), uintRangeOf(t, partitions[0]).Start) | ||
| require.Equal(t, uint64(math.MaxUint64), uintRangeOf(t, partitions[len(partitions)-1]).End) | ||
| for i, partition := range partitions { | ||
| r := uintRangeOf(t, partition) | ||
| require.LessOrEqual(t, r.Start, r.End) | ||
| if i > 0 { | ||
| require.Equal(t, uintRangeOf(t, partitions[i-1]).End+1, r.Start) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| t.Run("span smaller than partition count yields fewer partitions", func(t *testing.T) { | ||
| helper := NewPartitionHelper(logger) | ||
| require.NoError(t, helper.AddPartitionsWithRange(int64(0), int64(5), 10)) | ||
|
|
||
| partitions := helper.GetPartitions() | ||
| require.Len(t, partitions, 5) | ||
| require.Equal(t, int64(5), intRangeOf(t, partitions[len(partitions)-1]).End) | ||
| }) |
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.
This PR addresses the overflow bugs by moving the
computeNumericRangesmethod into a shared generic function that applies for both int64 and uint64. Int64 can overflow if min value is negative. Also, both int64 and uint64 can overflow withr.IntRange.Start+size*(i+1)/r.UintRange.Start+size*(i+1)on the last partition.Another bug fix is when span is smaller than partition count, previous logic would blindly honors
numPartitionsand generate invalid partitions (where start exceeds end). This PR fixes this so it will stop as soon as max value is reached.Fixes: DBI-822