Skip to content

Commit

Permalink
changefeedccl: attempt to deflake distribution strategy unit tests
Browse files Browse the repository at this point in the history
This patch attempts to deflake the changefeed distribution strategy
unit tests by replacing all the manually constructed
`ALTER TABLE ... RELOCATE` statements with a single statement that
uses a select query.

Release note: None
  • Loading branch information
andyyang890 committed Aug 12, 2024
1 parent 99e44fb commit fbda8dc
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions pkg/ccl/changefeedccl/changefeed_dist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,20 +423,12 @@ func newRangeDistributionTester(
t.Logf("%s: spitting the table took %s", timeutil.Now().Format(time.DateTime), timeutil.Since(start))

// Distribute the leases exponentially across the first 5 nodes.
for i := 0; i < 64; i += 1 {
nodeID := 1
// Avoid log(0).
if i != 0 {
nodeID = int(math.Floor(math.Log2(float64(i)))) + 1
}
t.Logf("%s: relocating range for %d to store %d", timeutil.Now().Format(time.DateTime), i, nodeID)
cmd := fmt.Sprintf(`ALTER TABLE x EXPERIMENTAL_RELOCATE VALUES (ARRAY[%d], %d)`, nodeID, i)
// Relocate can fail with errors like `change replicas... descriptor changed` thus the SucceedsSoon.
start := timeutil.Now()
sqlDB.ExecSucceedsSoon(t, cmd)
t.Logf("%s: relocating range for %d to store %d took %s",
timeutil.Now().Format(time.DateTime), i, nodeID, timeutil.Since(start))
}
t.Logf("%s: relocating ranges in exponential distribution", timeutil.Now().Format(time.DateTime))
start = timeutil.Now()
// Relocate can fail with errors like `change replicas... descriptor changed` thus the SucceedsSoon.
sqlDB.ExecSucceedsSoon(t,
`ALTER TABLE x RELOCATE SELECT ARRAY[floor(log(greatest(1,id)::DECIMAL)/log(2::DECIMAL))::INT+1], id FROM x`)
t.Logf("%s: relocating ranges took %s", timeutil.Now().Format(time.DateTime), timeutil.Since(start))

return &rangeDistributionTester{
ctx: ctx,
Expand Down

0 comments on commit fbda8dc

Please sign in to comment.