Skip to content

Commit 3ea732c

Browse files
craig[bot]srosenberg
andcommitted
Merge #152595
152595: workload: fix divide by zero in `csvServerPaths` r=stevendanna,williamchoe3 a=srosenberg Previously, `getNodeCount` could return zero without an error. This internal helper is used in `csvServerPaths` to determine `rowStep`. Not having any SQL nodes "available" is plausibly a valid system state. However, in the context of loading data, that indicates an error. This PR ensures `getNodeCount` returns a non-zero result or an error. As a precaution, we also clamp down the divisor. Epic: none Fixes: #152092 Release note: None Co-authored-by: Stan Rosenberg <[email protected]>
2 parents 579ec24 + bd4a105 commit 3ea732c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/ccl/workloadccl/fixture.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func csvServerPaths(
167167
// so our "integer multiple" is picked to be 1 to minimize this effect. Too
168168
// bad about the progress tracking granularity.
169169
numFiles := numNodes
170-
rowStep := table.InitialRows.NumBatches / numFiles
170+
rowStep := table.InitialRows.NumBatches / max(numFiles, 1)
171171
if rowStep == 0 {
172172
rowStep = 1
173173
}
@@ -329,11 +329,16 @@ func (l ImportDataLoader) InitialDataLoad(
329329
// the database we're connected to does not exist.
330330
const numNodesQuery = `SELECT count(1) FROM system.sql_instances WHERE addr IS NOT NULL`
331331

332+
// getNodeCount returns the number of nodes in the cluster by querying a system table.
333+
// Ensures err != nil => res > 0.
332334
func getNodeCount(ctx context.Context, sqlDB *gosql.DB) (int, error) {
333335
var numNodes int
334-
if err := sqlDB.QueryRow(numNodesQuery).Scan(&numNodes); err != nil {
336+
if err := sqlDB.QueryRowContext(ctx, numNodesQuery).Scan(&numNodes); err != nil {
335337
return 0, err
336338
}
339+
if numNodes == 0 {
340+
return 0, errors.New("no SQL nodes available")
341+
}
337342
return numNodes, nil
338343
}
339344

0 commit comments

Comments
 (0)