From c9f0043bed80524ec55ef077358f22db7b0c29c1 Mon Sep 17 00:00:00 2001 From: Lucy Zhang Date: Thu, 19 Nov 2020 21:51:42 -0500 Subject: [PATCH] workload/tpcc: fix race condition in scattering tables When iterating over the names of tables to scatter, we were sharing the loop variable between the goroutines, which is racy and caused a test failure due to reading a garbage string value for the table name. In general, this function may not scatter each table exactly once. This PR fixes the bug by moving the read out of the goroutine. Release note (bug fix): Fixed a race condition in the `tpcc` workload with the `--scatter` flag where tables could be scattered multiple times or not at all. --- pkg/workload/tpcc/ddls.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/workload/tpcc/ddls.go b/pkg/workload/tpcc/ddls.go index 01874030fbdd..0817bf1e387b 100644 --- a/pkg/workload/tpcc/ddls.go +++ b/pkg/workload/tpcc/ddls.go @@ -208,8 +208,8 @@ func scatterRanges(db *gosql.DB) error { var g errgroup.Group for _, table := range tables { + sql := fmt.Sprintf(`ALTER TABLE %s SCATTER`, table) g.Go(func() error { - sql := fmt.Sprintf(`ALTER TABLE %s SCATTER`, table) if _, err := db.Exec(sql); err != nil { return errors.Wrapf(err, "Couldn't exec %q", sql) }