Skip to content

Commit d3f704f

Browse files
craig[bot]nvb
andcommitted
Merge #36778
36778: workload/tpcc: reallow scattering during `workload run` r=nvanbenschoten a=nvanbenschoten Fixes #36776. This was broken by #33242. I'd rather not allow this, but doing so breaks compatibility with a lot of our guides. Release note: None Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
2 parents ee451b4 + beb9370 commit d3f704f

File tree

1 file changed

+44
-50
lines changed

1 file changed

+44
-50
lines changed

pkg/workload/tpcc/tpcc.go

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -284,31 +284,7 @@ func (w *tpcc) Hooks() workload.Hooks {
284284
}
285285
}
286286

287-
if w.partitions > 1 {
288-
if !w.split {
289-
return errors.Errorf("multiple partitions requires --split")
290-
}
291-
292-
// Repartitioning can take upwards of 10 minutes, so determine if
293-
// the dataset is already partitioned before launching the operation
294-
// again.
295-
if parts, err := partitionCount(db); err != nil {
296-
return errors.Wrapf(err, "could not determine if tables are partitioned")
297-
} else if parts > 0 {
298-
log.Infof(context.Background(), "tables already partitioned")
299-
} else {
300-
if err := partitionTables(db, w.wPart, w.zones); err != nil {
301-
return errors.Wrapf(err, "could not partition tables")
302-
}
303-
}
304-
}
305-
306-
if w.scatter {
307-
if err := scatterRanges(db); err != nil {
308-
return errors.Wrapf(err, "could not scatter ranges")
309-
}
310-
}
311-
return nil
287+
return w.partitionAndScatterWithDB(db)
312288
},
313289
PostRun: func(startElapsed time.Duration) error {
314290
w.auditor.runChecks()
@@ -512,6 +488,14 @@ func (w *tpcc) Tables() []workload.Table {
512488

513489
// Ops implements the Opser interface.
514490
func (w *tpcc) Ops(urls []string, reg *histogram.Registry) (workload.QueryLoad, error) {
491+
// It would be nice to remove the need for this and to require that
492+
// partitioning and scattering occurs only when the PostLoad hook is
493+
// run, but to maintain backward compatibility, it's easiest to allow
494+
// partitioning and scattering during `workload run`.
495+
if err := w.partitionAndScatter(urls); err != nil {
496+
return workload.QueryLoad{}, err
497+
}
498+
515499
sqlDatabase, err := workload.SanitizeUrls(w, w.dbOverride, urls)
516500
if err != nil {
517501
return workload.QueryLoad{}, err
@@ -547,31 +531,6 @@ func (w *tpcc) Ops(urls []string, reg *histogram.Registry) (workload.QueryLoad,
547531
return workload.QueryLoad{}, err
548532
}
549533

550-
// Verify that the dataset is correctly partitioned into the desired number
551-
// of partitions.
552-
if w.partitions > 1 {
553-
db, err := gosql.Open(`cockroach`, strings.Join(urls, ` `))
554-
if err != nil {
555-
return workload.QueryLoad{}, err
556-
}
557-
558-
if parts, err := partitionCount(db); err != nil {
559-
return workload.QueryLoad{},
560-
errors.Wrapf(err, "could not determine if tables are partitioned")
561-
} else if parts == 0 {
562-
// It would be nice to disallow this case and require that
563-
// partitioning occurs only when the PostLoad hook is run,
564-
// but to maintain backward compatibility, it's easiest to
565-
// allow partitioning during `workload run`.
566-
if err := partitionTables(db, w.wPart, w.zones); err != nil {
567-
return workload.QueryLoad{}, errors.Wrapf(err, "could not partition tables")
568-
}
569-
} else if parts != w.partitions {
570-
return workload.QueryLoad{}, errors.Errorf("tables are not partitioned %d way(s). "+
571-
"Pass the --partitions flag to 'workload init' or 'workload fixtures'.", w.partitions)
572-
}
573-
}
574-
575534
// Assign each DB connection pool to a local partition. This assumes that
576535
// dbs[i] is a machine that holds partition "i % *partitions". If we have an
577536
// affinity partition, all connections will be for the same partition.
@@ -625,3 +584,38 @@ func (w *tpcc) Ops(urls []string, reg *histogram.Registry) (workload.QueryLoad,
625584
}
626585
return ql, nil
627586
}
587+
588+
func (w *tpcc) partitionAndScatter(urls []string) error {
589+
db, err := gosql.Open(`cockroach`, strings.Join(urls, ` `))
590+
if err != nil {
591+
return err
592+
}
593+
defer db.Close()
594+
return w.partitionAndScatterWithDB(db)
595+
}
596+
597+
func (w *tpcc) partitionAndScatterWithDB(db *gosql.DB) error {
598+
if w.partitions > 1 {
599+
// Repartitioning can take upwards of 10 minutes, so determine if
600+
// the dataset is already partitioned before launching the operation
601+
// again.
602+
if parts, err := partitionCount(db); err != nil {
603+
return errors.Wrapf(err, "could not determine if tables are partitioned")
604+
} else if parts == 0 {
605+
if err := partitionTables(db, w.wPart, w.zones); err != nil {
606+
return errors.Wrapf(err, "could not partition tables")
607+
}
608+
} else if parts != w.partitions {
609+
return errors.Errorf("tables are not partitioned %d way(s). "+
610+
"Pass the --partitions flag to 'workload init' or 'workload fixtures'.", w.partitions)
611+
}
612+
}
613+
614+
if w.scatter {
615+
if err := scatterRanges(db); err != nil {
616+
return errors.Wrapf(err, "could not scatter ranges")
617+
}
618+
}
619+
620+
return nil
621+
}

0 commit comments

Comments
 (0)