Skip to content

Migrate math/rand to math/rand/v2#1810

Open
antonio-mello-ai wants to merge 1 commit into
ClickHouse:mainfrom
antonio-mello-ai:fix/rand-v2-migration
Open

Migrate math/rand to math/rand/v2#1810
antonio-mello-ai wants to merge 1 commit into
ClickHouse:mainfrom
antonio-mello-ai:fix/rand-v2-migration

Conversation

@antonio-mello-ai
Copy link
Copy Markdown

Summary

Migrates the entire codebase from math/rand to math/rand/v2, fixing the Go 1.25 rand.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 to math/rand/v2 #1653 where duplicate addresses could be picked while others were skipped.

Codebase-wide migration (20 files):

  • All rand.Seed() and rand.NewSource() calls removed — math/rand/v2 is auto-seeded and concurrency-safe
  • rand.Intn(n)rand.IntN(n), rand.Int63()rand.Int64()
  • Removed now-unnecessary ResetRandSeed() helpers and randSeed variables
  • Re-enabled three tests that were skipped due to Go 1.25 math/random changes

Checklist

  • Unit and integration tests covering the common scenarios were added

Generative AI disclosure: This PR was co-authored with Claude (Anthropic).

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) <[email protected]>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 29, 2026

CLA assistant check
All committers have signed the CLA.

@antonio-mello-ai
Copy link
Copy Markdown
Author

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.

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.

Upgrade to math/rand/v2

2 participants