Repository navigation
Migrate math/rand to math/rand/v2 - #1810
antonio-mello-ai wants to merge 5 commits into
Conversation
|
Hi @kavirajk — this is my first contribution here, so the CI workflow may need a maintainer to approve the run. The CLA is signed and all changes are covered by existing tests. Could you take a look when you get a chance? Happy to address any feedback. |
🤖 Claude reviewMigrates the code from What I examined:
Remaining item: one Blind spots:
Verdict: ✅ Approve Inline comments are attached to the relevant lines. This summary updates in place on re-review. |
must108
left a comment
There was a problem hiding this comment.
Hi @antonio-mello-ai, thanks for the contribution. Could you please address the comments made by github-bot and Claude? Thanks.
Go 1.25 broke rand.Seed() from math/rand v1, which caused several connection failover tests to be skipped. This migrates the entire codebase to math/rand/v2, which is auto-seeded and concurrency-safe. Key changes: - All rand.Seed() and rand.NewSource() calls removed (v2 auto-seeds) - rand.Intn(n) → rand.IntN(n), rand.Int63() → rand.Int64() - Connection failover: random offset now computed once before the loop instead of on every iteration, ensuring all hosts are tried exactly once in a random-start round-robin order - Three skipped tests re-enabled (conn_test, std/conn_test, main_test) Closes ClickHouse#1653 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
07aadac to
76c00be
Compare
45aa00e to
4446f59
Compare
|
Good day, @must108 ! Thanks! |
AI review gate — Human approval in place of AI reviewApproved on the head commit by chernser, must108 (write access, not the author), standing in for the AI review:
What to do:
Evaluated at |
Summary
Migrates the entire codebase from
math/randtomath/rand/v2, fixing the Go 1.25rand.Seed()breakage and re-enabling three skipped tests.Closes #1653
Changes
Core (connection failover fix):
clickhouse.go,clickhouse_std.go— Random host offset is now computed once before the loop instead of on every iteration. This ensures all hosts are tried exactly once in a random-start round-robin order, fixing the issue described in Upgrade tomath/rand/v2#1653 where duplicate addresses could be picked while others were skipped.Codebase-wide migration (20 files):
rand.Seed()andrand.NewSource()calls removed —math/rand/v2is auto-seeded and concurrency-saferand.Intn(n)→rand.IntN(n),rand.Int63()→rand.Int64()ResetRandSeed()helpers andrandSeedvariablesChecklist
Generative AI disclosure: This PR was co-authored with Claude (Anthropic).
Note
Medium Risk
Changes core connection dial/failover behavior for random strategy; behavior is intentional and tested but affects how clients pick hosts on failure.
Overview
Replaces
math/randwithmath/rand/v2across the driver, std wrapper, examples, and tests: drops manualSeed/NewSource/ResetRandSeed, and updates call sites toIntN/Int64.For
ConnOpenRandom, random host selection now picks a single starting offset before the retry loop (native and std paths) so failover walks each address exactly once in a rotated order—fixing duplicate/skipped hosts (#1653). Skipped random multi-host and failover tests are re-enabled, with new coverage inissue_1653_test.go.Reviewed by Cursor Bugbot for commit 4446f59. Bugbot is set up for automated code reviews on this repo. Configure here.