Skip to content

address partition overflow bug#4550

Merged
jgao54 merged 1 commit into
mainfrom
fix-overflow
Jul 9, 2026
Merged

address partition overflow bug#4550
jgao54 merged 1 commit into
mainfrom
fix-overflow

Conversation

@jgao54

@jgao54 jgao54 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This PR addresses the overflow bugs by moving the computeNumericRanges method 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 with r.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 numPartitions and 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

@jgao54 jgao54 changed the title address overflow bug address partition overflow bug 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)
})

@jgao54 jgao54 Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

these tests were all failing before the fix

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.

😱

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
2952 2 2950 348
View the top 2 failed test(s) by shortest run time
github.com/PeerDB-io/peerdb/flow/e2e::TestPeerFlowE2ETestSuiteMySQL_CH
Stack Traces | 0.02s run time
=== RUN   TestPeerFlowE2ETestSuiteMySQL_CH
=== PAUSE TestPeerFlowE2ETestSuiteMySQL_CH
=== CONT  TestPeerFlowE2ETestSuiteMySQL_CH
--- FAIL: TestPeerFlowE2ETestSuiteMySQL_CH (0.02s)
2026/07/08 04:58:00 INFO Received AWS credentials from peer for connector: ci x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN}
2026/07/08 04:58:00 INFO Received AWS credentials from peer for connector: clickhouse x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN}
2026/07/08 04:58:00 INFO fetched schema x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN} table=e2e_test_mychcl_xocbsoit.test_myisam
github.com/PeerDB-io/peerdb/flow/e2e::TestPeerFlowE2ETestSuiteMySQL_CH/Test_MySQL_BinlogIncident
Stack Traces | 45.1s run time
=== RUN   TestPeerFlowE2ETestSuiteMySQL_CH/Test_MySQL_BinlogIncident
=== PAUSE TestPeerFlowE2ETestSuiteMySQL_CH/Test_MySQL_BinlogIncident
=== CONT  TestPeerFlowE2ETestSuiteMySQL_CH/Test_MySQL_BinlogIncident
2026/07/08 04:56:56 INFO Received AWS credentials from peer for connector: ci x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN}
2026/07/08 04:56:56 INFO Received AWS credentials from peer for connector: clickhouse x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN}
2026/07/08 04:56:56 INFO fetched schema x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN} table=e2e_test_mych_uktig3ra.test_nullengine
    clickhouse_mysql_test.go:2036: 
        	Error Trace:	.../flow/e2e/clickhouse_mysql_test.go:2036
        	Error:      	Received unexpected error:
        	            	MySQL execute error: readInitialHandshake: io.ReadFull(header) failed. err EOF: connection was bad
        	Test:       	TestPeerFlowE2ETestSuiteMySQL_CH/Test_MySQL_BinlogIncident
2026/07/08 04:57:11 INFO fetched schema x-peerdb-additional-metadata={Operation:FLOW_OPERATION_UNKNOWN} table=e2e_test_mychcl_kd1qsbhf.test_update_pkey_enabled
--- FAIL: TestPeerFlowE2ETestSuiteMySQL_CH/Test_MySQL_BinlogIncident (45.11s)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🔄 Flaky Test Detected

Analysis: 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.
Confidence: 0.9

✅ Automatically retrying the workflow

View workflow run

@jgao54 jgao54 marked this pull request as ready for review July 8, 2026 05:25
@jgao54 jgao54 requested a review from a team as a code owner July 8, 2026 05:25
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)
})

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.

😱

@jgao54 jgao54 merged commit cf2c6dc into main Jul 9, 2026
27 of 28 checks passed
@jgao54 jgao54 deleted the fix-overflow branch July 9, 2026 08:08
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