From fbda8dc20049a98b0bd85c237b484e6142d5a709 Mon Sep 17 00:00:00 2001 From: Andy Yang Date: Mon, 12 Aug 2024 16:44:04 -0400 Subject: [PATCH] changefeedccl: attempt to deflake distribution strategy unit tests 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 --- pkg/ccl/changefeedccl/changefeed_dist_test.go | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pkg/ccl/changefeedccl/changefeed_dist_test.go b/pkg/ccl/changefeedccl/changefeed_dist_test.go index 842078f7b9bf..dbb1112d9422 100644 --- a/pkg/ccl/changefeedccl/changefeed_dist_test.go +++ b/pkg/ccl/changefeedccl/changefeed_dist_test.go @@ -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,