-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathtpcc.go
1626 lines (1499 loc) · 55.2 KB
/
tpcc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2018 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package tests
import (
"context"
gosql "database/sql"
"fmt"
"math"
"math/rand"
"os"
"path/filepath"
"strings"
"time"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
"github.com/cockroachdb/cockroach/pkg/roachprod/install"
"github.com/cockroachdb/cockroach/pkg/roachprod/logger"
"github.com/cockroachdb/cockroach/pkg/roachprod/prometheus"
"github.com/cockroachdb/cockroach/pkg/roachprod/vm"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/testutils/release"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/cockroach/pkg/util/search"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/cockroach/pkg/util/version"
"github.com/cockroachdb/cockroach/pkg/workload/histogram"
"github.com/cockroachdb/cockroach/pkg/workload/tpcc"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/ttycolor"
"github.com/lib/pq"
promapi "github.com/prometheus/client_golang/api"
promv1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/stretchr/testify/require"
)
type tpccSetupType int
const (
usingImport tpccSetupType = iota
usingInit
usingExistingData // skips import
)
// rampDuration returns the default durations passed to the `ramp`
// option when running a tpcc workload in these tests.
func rampDuration(isLocal bool) time.Duration {
if isLocal {
return 30 * time.Second
}
return 5 * time.Minute
}
type tpccOptions struct {
Warehouses int
ExtraRunArgs string
ExtraSetupArgs string
Chaos func() Chaos // for late binding of stopper
During func(context.Context) error // for running a function during the test
Duration time.Duration // if zero, TPCC is not invoked
SetupType tpccSetupType
EstimatedSetupTime time.Duration
// PrometheusConfig, if set, overwrites the default prometheus config settings.
PrometheusConfig *prometheus.Config
// DisablePrometheus will force prometheus to not start up.
DisablePrometheus bool
// WorkloadInstances contains a list of instances for
// workloads to run against.
// If unset, it will run one workload which talks to
// all cluster nodes.
WorkloadInstances []workloadInstance
// tpccChaosEventProcessor processes chaos events if specified.
ChaosEventsProcessor func(
prometheusNode option.NodeListOption,
workloadInstances []workloadInstance,
) (tpccChaosEventProcessor, error)
// If specified, called to stage+start cockroach. If not
// specified, defaults to uploading the default binary to
// all nodes, and starting it on all but the last node.
//
// TODO(tbg): for better coverage at scale of the migration process, we should
// also be doing a rolling-restart into the new binary while the cluster
// is running, but that feels like jamming too much into the tpcc setup.
Start func(context.Context, test.Test, cluster.Cluster)
// SkipPostRunCheck, if set, skips post TPC-C run checks.
SkipPostRunCheck bool
DisableDefaultScheduledBackup bool
}
type workloadInstance struct {
// nodes dictates the nodes workload should run against.
nodes option.NodeListOption
// prometheusPort is the port on the workload which runs
// prometheus.
prometheusPort int
// extraRunArgs dictates unique arguments to use for the workload.
extraRunArgs string
}
const workloadPProfStartPort = 33333
// tpccImportCmd generates the command string to load tpcc data for the
// specified warehouse count into a cluster.
//
// The command uses `cockroach workload` instead of `workload` so the tpcc
// workload-versions match on release branches. Similarly, the command does not
// specify pgurl to ensure that it is run on a node with a running cockroach
// instance to ensure that the workload version matches the gateway version in a
// mixed version cluster.
func tpccImportCmd(warehouses int, extraArgs ...string) string {
return tpccImportCmdWithCockroachBinary("./cockroach", warehouses, extraArgs...)
}
func tpccImportCmdWithCockroachBinary(
crdbBinary string, warehouses int, extraArgs ...string,
) string {
return fmt.Sprintf("./%s workload fixtures import tpcc --warehouses=%d %s",
crdbBinary, warehouses, strings.Join(extraArgs, " "))
}
func setupTPCC(
ctx context.Context, t test.Test, c cluster.Cluster, opts tpccOptions,
) (crdbNodes, workloadNode option.NodeListOption) {
// Randomize starting with encryption-at-rest enabled.
crdbNodes = c.Range(1, c.Spec().NodeCount-1)
workloadNode = c.Node(c.Spec().NodeCount)
if c.IsLocal() {
opts.Warehouses = 1
}
if opts.Start == nil {
opts.Start = func(ctx context.Context, t test.Test, c cluster.Cluster) {
// NB: workloadNode also needs ./cockroach because
// of `./cockroach workload` for usingImport.
c.Put(ctx, t.Cockroach(), "./cockroach", c.All())
settings := install.MakeClusterSettings()
if c.IsLocal() {
settings.Env = append(settings.Env, "COCKROACH_SCAN_INTERVAL=200ms")
settings.Env = append(settings.Env, "COCKROACH_SCAN_MAX_IDLE_TIME=5ms")
}
startOpts := option.DefaultStartOpts()
startOpts.RoachprodOpts.ScheduleBackups = !opts.DisableDefaultScheduledBackup
c.Start(ctx, t.L(), startOpts, settings, crdbNodes)
}
}
func() {
opts.Start(ctx, t, c)
db := c.Conn(ctx, t.L(), 1)
defer db.Close()
if t.SkipInit() {
return
}
require.NoError(t, WaitFor3XReplication(ctx, t, c.Conn(ctx, t.L(), crdbNodes[0])))
estimatedSetupTimeStr := ""
if opts.EstimatedSetupTime != 0 {
estimatedSetupTimeStr = fmt.Sprintf(" (<%s)", opts.EstimatedSetupTime)
}
switch opts.SetupType {
case usingExistingData:
// Do nothing.
case usingImport:
t.Status("loading fixture" + estimatedSetupTimeStr)
c.Run(ctx, crdbNodes[:1], tpccImportCmd(opts.Warehouses, opts.ExtraSetupArgs))
case usingInit:
t.Status("initializing tables" + estimatedSetupTimeStr)
extraArgs := opts.ExtraSetupArgs
if !t.BuildVersion().AtLeast(version.MustParse("v20.2.0")) {
extraArgs += " --deprecated-fk-indexes"
}
cmd := fmt.Sprintf(
"./cockroach workload init tpcc --warehouses=%d %s {pgurl:1}",
opts.Warehouses, extraArgs,
)
c.Run(ctx, workloadNode, cmd)
default:
t.Fatal("unknown tpcc setup type")
}
t.Status("finished tpc-c setup")
}()
return crdbNodes, workloadNode
}
func runTPCC(ctx context.Context, t test.Test, c cluster.Cluster, opts tpccOptions) {
workloadInstances := opts.WorkloadInstances
if len(workloadInstances) == 0 {
workloadInstances = append(
workloadInstances,
workloadInstance{
nodes: c.Range(1, c.Spec().NodeCount-1),
prometheusPort: 2112,
},
)
}
var pgURLs []string
for _, workloadInstance := range workloadInstances {
pgURLs = append(pgURLs, fmt.Sprintf("{pgurl%s}", workloadInstance.nodes.String()))
}
var ep *tpccChaosEventProcessor
var promCfg *prometheus.Config
if !opts.DisablePrometheus && !t.SkipInit() {
// TODO(irfansharif): Move this after the import step. The statistics
// during import itself is uninteresting and pollutes actual workload
// data.
var cleanupFunc func()
promCfg, cleanupFunc = setupPrometheusForRoachtest(ctx, t, c, opts.PrometheusConfig, workloadInstances)
defer cleanupFunc()
}
if opts.ChaosEventsProcessor != nil {
if promCfg == nil {
t.Skip("skipping test as prometheus is needed, but prometheus does not yet work locally")
return
}
cep, err := opts.ChaosEventsProcessor(
c.Nodes(int(promCfg.PrometheusNode[0])),
workloadInstances,
)
if err != nil {
t.Fatal(err)
}
cep.listen(ctx, t.L())
ep = &cep
}
if c.IsLocal() {
opts.Warehouses = 1
if opts.Duration > time.Minute {
opts.Duration = time.Minute
}
}
crdbNodes, workloadNode := setupTPCC(ctx, t, c, opts)
m := c.NewMonitor(ctx, crdbNodes)
rampDur := rampDuration(c.IsLocal())
for i := range workloadInstances {
// Make a copy of i for the goroutine.
i := i
m.Go(func(ctx context.Context) error {
// Only prefix stats.json with workload_i_ if we have multiple workloads,
// in case other processes relied on previous behavior.
var statsPrefix string
if len(workloadInstances) > 1 {
statsPrefix = fmt.Sprintf("workload_%d.", i)
}
t.WorkerStatus(fmt.Sprintf("running tpcc worker=%d warehouses=%d ramp=%s duration=%s on %s (<%s)",
i, opts.Warehouses, rampDur, opts.Duration, pgURLs[i], time.Minute))
cmd := fmt.Sprintf(
"./cockroach workload run tpcc --warehouses=%d --histograms="+t.PerfArtifactsDir()+"/%sstats.json "+
opts.ExtraRunArgs+" --ramp=%s --duration=%s --prometheus-port=%d --pprofport=%d %s %s",
opts.Warehouses,
statsPrefix,
rampDur,
opts.Duration,
workloadInstances[i].prometheusPort,
workloadPProfStartPort+i,
workloadInstances[i].extraRunArgs,
pgURLs[i],
)
return c.RunE(ctx, workloadNode, cmd)
})
}
if opts.Chaos != nil {
chaos := opts.Chaos()
m.Go(chaos.Runner(c, t, m))
}
if opts.During != nil {
m.Go(opts.During)
}
m.Wait()
if !opts.SkipPostRunCheck {
c.Run(ctx, workloadNode, fmt.Sprintf(
"./cockroach workload check tpcc --warehouses=%d {pgurl:1}", opts.Warehouses))
}
// Check no errors from metrics.
if ep != nil {
if err := ep.err(); err != nil {
t.Fatal(errors.Wrap(err, "error detected during DRT"))
}
}
}
// tpccSupportedWarehouses returns our claim for the maximum number of tpcc
// warehouses we support for a given hardware configuration.
//
// These should be added to periodically. Ideally when tpccbench finds major
// performance movement, but at the least for every major release.
var tpccSupportedWarehouses = []struct {
hardware string
v *version.Version
warehouses int
}{
// We append "-0" to the version so that we capture all prereleases of the
// specified version. Otherwise, "v2.1.0" would compare greater than
// "v2.1.0-alpha.x".
{hardware: "gce-n4cpu16", v: version.MustParse(`v2.1.0-0`), warehouses: 1300},
{hardware: "gce-n4cpu16", v: version.MustParse(`v19.1.0-0`), warehouses: 1250},
{hardware: "aws-n4cpu16", v: version.MustParse(`v19.1.0-0`), warehouses: 2100},
// TODO(tbg): this number is copied from gce-n4cpu16. The real number should be a
// little higher, find out what it is.
{hardware: "gce-n5cpu16", v: version.MustParse(`v19.1.0-0`), warehouses: 1300},
{hardware: "aws-n5cpu16", v: version.MustParse(`v19.1.0-0`), warehouses: 2100},
// Ditto.
{hardware: "gce-n5cpu16", v: version.MustParse(`v2.1.0-0`), warehouses: 1300},
}
// tpccMaxRate calculates the max rate of the workload given a number of warehouses.
func tpccMaxRate(warehouses int) int {
const txnsPerWarehousePerSecond = 12.8 * (23.0 / 10.0) * (1.0 / 60.0) // max_tpmC/warehouse * all_txns/new_order_txns * minutes/seconds
rateAtExpected := txnsPerWarehousePerSecond * float64(warehouses)
maxRate := int(rateAtExpected / 2)
return maxRate
}
func maxSupportedTPCCWarehouses(
buildVersion version.Version, cloud string, nodes spec.ClusterSpec,
) int {
var v *version.Version
var warehouses int
hardware := fmt.Sprintf(`%s-%s`, cloud, &nodes)
for _, x := range tpccSupportedWarehouses {
if x.hardware != hardware {
continue
}
if buildVersion.AtLeast(x.v) && (v == nil || buildVersion.AtLeast(v)) {
v = x.v
warehouses = x.warehouses
}
}
if v == nil {
panic(fmt.Sprintf(`could not find max tpcc warehouses for %s`, hardware))
}
return warehouses
}
type backgroundFn func(ctx context.Context, u *versionUpgradeTest) error
// A backgroundStepper is a tool to run long-lived commands while a cluster is
// going through a sequence of version upgrade operations.
// It exposes a `launch` step that launches the method carrying out long-running
// work (in the background) and a `stop` step collecting any errors.
type backgroundStepper struct {
// This is the operation that will be launched in the background. When the
// context gets canceled, it should shut down and return without an error.
// The way to typically get this is:
//
// err := doSomething(ctx)
// ctx.Err() != nil {
// return nil
// }
// return err
run backgroundFn
// When not nil, called with the error within `.stop()`. The interceptor
// gets a chance to ignore the error or produce a different one (via t.Fatal).
onStop func(context.Context, test.Test, *versionUpgradeTest, error)
nodes option.NodeListOption // nodes to monitor, defaults to c.All()
// Internal.
m cluster.Monitor
}
// launch spawns the function the background step was initialized with.
func (s *backgroundStepper) launch(ctx context.Context, t test.Test, u *versionUpgradeTest) {
nodes := s.nodes
if nodes == nil {
nodes = u.c.All()
}
s.m = u.c.NewMonitor(ctx, nodes)
s.m.Go(func(ctx context.Context) error {
return s.run(ctx, u)
})
}
func (s *backgroundStepper) wait(ctx context.Context, t test.Test, u *versionUpgradeTest) {
// We don't care about the workload failing since we only use it to produce a
// few `RESTORE` jobs. And indeed workload will fail because it does not
// tolerate pausing of its jobs.
err := s.m.WaitE()
if s.onStop != nil {
s.onStop(ctx, t, u, err)
} else if err != nil {
t.Fatal(err)
}
}
// runTPCCMixedHeadroom runs a mixed-version test that imports a large
// `bank` dataset, and runs one or multiple database upgrades while a
// TPCC workload is running. The number of database upgrades is
// controlled by the `versionsToUpgrade` parameter.
func runTPCCMixedHeadroom(
ctx context.Context, t test.Test, c cluster.Cluster, cloud string, versionsToUpgrade int,
) {
crdbNodes := c.Range(1, c.Spec().NodeCount-1)
workloadNode := c.Node(c.Spec().NodeCount)
maxWarehouses := maxSupportedTPCCWarehouses(*t.BuildVersion(), cloud, c.Spec())
headroomWarehouses := int(float64(maxWarehouses) * 0.7)
if c.IsLocal() {
headroomWarehouses = 10
}
// We'll need this below.
tpccBackgroundStepper := func(duration time.Duration) backgroundStepper {
return backgroundStepper{
nodes: crdbNodes,
run: func(ctx context.Context, u *versionUpgradeTest) error {
t.L().Printf("running background TPCC workload for %s", duration)
runTPCC(ctx, t, c, tpccOptions{
Warehouses: headroomWarehouses,
Duration: duration,
SetupType: usingExistingData,
Start: func(ctx context.Context, t test.Test, c cluster.Cluster) {
// Noop - we don't let tpcc upload or start binaries in this test.
},
})
return nil
}}
}
randomCRDBNode := func() int { return crdbNodes.RandNode()[0] }
const mainBinary = ""
// NB: this results in ~100GB of (actual) disk usage per node once things
// have settled down, and ~7.5k ranges. The import takes ~40 minutes.
// The full 6.5m import ran into out of disk errors (on 250gb machines),
// hence division by two.
bankRows := 65104166 / 2
if c.IsLocal() {
bankRows = 1000
}
rng, seed := randutil.NewLockedPseudoRand()
t.L().Printf("using random seed %d", seed)
history, err := release.RandomPredecessorHistory(rng, t.BuildVersion(), versionsToUpgrade)
if err != nil {
t.Fatal(err)
}
sep := " -> "
t.L().Printf("testing upgrade: %s%scurrent", strings.Join(history, sep), sep)
history = append(history, mainBinary)
waitForWorkloadToRampUp := sleepStep(rampDuration(c.IsLocal()))
logStep := func(format string, args ...interface{}) versionStep {
return func(ctx context.Context, t test.Test, u *versionUpgradeTest) {
t.L().Printf(format, args...)
}
}
oldestVersion := history[0]
setupSteps := []versionStep{
logStep("starting from fixture at version %s", oldestVersion),
uploadAndStartFromCheckpointFixture(crdbNodes, oldestVersion),
waitForUpgradeStep(crdbNodes), // let oldest version settle (gossip etc)
uploadVersionStep(workloadNode, mainBinary), // for tpccBackgroundStepper's workload
// Load TPCC dataset, don't run TPCC yet. We do this while in the
// version we are starting with to load some data and hopefully
// create some state that will need work by long-running
// migrations.
importTPCCStep(oldestVersion, headroomWarehouses, crdbNodes),
// Add a lot of cold data to this cluster. This further stresses the version
// upgrade machinery, in which a) all ranges are touched and b) work proportional
// to the amount data may be carried out.
importLargeBankStep(oldestVersion, bankRows, crdbNodes),
}
// upgradeToVersionSteps returns the list of steps to be performed
// when upgrading to the given version.
upgradeToVersionSteps := func(crdbVersion string) []versionStep {
duration := 10 * time.Minute
versionString := crdbVersion
if crdbVersion == mainBinary {
duration = 100 * time.Minute
versionString = "current"
}
tpccWorkload := tpccBackgroundStepper(duration)
return []versionStep{
logStep("upgrading to version %q", versionString),
preventAutoUpgradeStep(randomCRDBNode()),
// Upload and restart cluster into the new
// binary (stays at previous cluster version).
binaryUpgradeStep(crdbNodes, crdbVersion),
// Now start running TPCC in the background.
tpccWorkload.launch,
// Wait for the workload to ramp up before attemping to
// upgrade the cluster version. If we start the migrations
// immediately after launching the tpcc workload above, they
// could finish "too quickly", before the workload had a
// chance to pick up the pace (starting all the workers, range
// merge/splits, compactions, etc). By waiting here, we
// increase the concurrency exposed to the upgrade migrations,
// and increase the chances of exposing bugs (such as #83079).
waitForWorkloadToRampUp,
// While tpcc is running in the background, bump the cluster
// version manually. We do this over allowing automatic upgrades
// to get a better idea of what errors come back here, if any.
// This will block until the long-running migrations have run.
allowAutoUpgradeStep(randomCRDBNode()),
waitForUpgradeStep(crdbNodes),
// Wait until TPCC background run terminates
// and fail if it reports an error.
tpccWorkload.wait,
}
}
// Test steps consist of the setup steps + the upgrade steps for
// each upgrade being carried out here.
testSteps := append([]versionStep{}, setupSteps...)
for _, nextVersion := range history[1:] {
testSteps = append(testSteps, upgradeToVersionSteps(nextVersion)...)
}
newVersionUpgradeTest(c, testSteps...).run(ctx, t)
}
func registerTPCC(r registry.Registry) {
cloud := r.MakeClusterSpec(1).Cloud
headroomSpec := r.MakeClusterSpec(4, spec.CPU(16), spec.RandomlyUseZfs())
r.Add(registry.TestSpec{
// w=headroom runs tpcc for a semi-extended period with some amount of
// headroom, more closely mirroring a real production deployment than
// running with the max supported warehouses.
Name: "tpcc/headroom/" + headroomSpec.String(),
Owner: registry.OwnerTestEng,
Tags: registry.Tags(`default`, `release_qualification`, `aws`),
Cluster: headroomSpec,
EncryptionSupport: registry.EncryptionMetamorphic,
Leases: registry.MetamorphicLeases,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
maxWarehouses := maxSupportedTPCCWarehouses(*t.BuildVersion(), cloud, t.Spec().(*registry.TestSpec).Cluster)
headroomWarehouses := int(float64(maxWarehouses) * 0.7)
t.L().Printf("computed headroom warehouses of %d\n", headroomWarehouses)
runTPCC(ctx, t, c, tpccOptions{
Warehouses: headroomWarehouses,
Duration: 120 * time.Minute,
SetupType: usingImport,
})
},
})
mixedHeadroomSpec := r.MakeClusterSpec(5, spec.CPU(16), spec.RandomlyUseZfs())
r.Add(registry.TestSpec{
// mixed-headroom is similar to w=headroom, but with an additional
// node and on a mixed version cluster which runs its long-running
// migrations while TPCC runs. It simulates a real production
// deployment in the middle of the migration into a new cluster version.
Name: "tpcc/mixed-headroom/" + mixedHeadroomSpec.String(),
Timeout: 5 * time.Hour,
Owner: registry.OwnerTestEng,
// TODO(tbg): add release_qualification tag once we know the test isn't
// buggy.
Tags: registry.Tags(`default`),
Cluster: mixedHeadroomSpec,
EncryptionSupport: registry.EncryptionMetamorphic,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runTPCCMixedHeadroom(ctx, t, c, cloud, 1)
},
})
// N.B. Multiple upgrades may require a released version < 22.2.x, which wasn't built for ARM64.
mixedHeadroomMultiUpgradesSpec := r.MakeClusterSpec(5, spec.CPU(16), spec.RandomlyUseZfs(), spec.Arch(vm.ArchAMD64))
r.Add(registry.TestSpec{
// run the same mixed-headroom test, but going back two versions
Name: "tpcc/mixed-headroom/multiple-upgrades/" + mixedHeadroomMultiUpgradesSpec.String(),
Timeout: 5 * time.Hour,
Owner: registry.OwnerTestEng,
Tags: registry.Tags(`default`),
Cluster: mixedHeadroomMultiUpgradesSpec,
EncryptionSupport: registry.EncryptionMetamorphic,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runTPCCMixedHeadroom(ctx, t, c, cloud, 2)
},
})
r.Add(registry.TestSpec{
Name: "tpcc-nowait/nodes=3/w=1",
Owner: registry.OwnerTestEng,
Cluster: r.MakeClusterSpec(4, spec.CPU(16)),
EncryptionSupport: registry.EncryptionMetamorphic,
Leases: registry.MetamorphicLeases,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runTPCC(ctx, t, c, tpccOptions{
Warehouses: 1,
Duration: 10 * time.Minute,
ExtraRunArgs: "--wait=false",
SetupType: usingImport,
})
},
})
r.Add(registry.TestSpec{
Name: "weekly/tpcc/headroom",
Owner: registry.OwnerTestEng,
Tags: registry.Tags(`weekly`),
Cluster: r.MakeClusterSpec(4, spec.CPU(16)),
// Give the test a generous extra 10 hours to load the dataset and
// slowly ramp up the load.
Timeout: 4*24*time.Hour + 10*time.Hour,
EncryptionSupport: registry.EncryptionMetamorphic,
Leases: registry.MetamorphicLeases,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
warehouses := 1000
runTPCC(ctx, t, c, tpccOptions{
Warehouses: warehouses,
Duration: 4 * 24 * time.Hour,
SetupType: usingImport,
})
},
})
// Setup multi-region tests.
{
mrSetup := []struct {
region string
zones string
}{
{region: "us-east1", zones: "us-east1-b"},
{region: "us-west1", zones: "us-west1-b"},
{region: "europe-west2", zones: "europe-west2-b"},
}
zs := []string{}
// NOTE: region is currently only used for number of regions.
regions := []string{}
for _, s := range mrSetup {
regions = append(regions, s.region)
zs = append(zs, s.zones)
}
const nodesPerRegion = 3
const warehousesPerRegion = 20
multiRegionTests := []struct {
desc string
name string
survivalGoal string
chaosTarget func(iter int) option.NodeListOption
workloadInstances []workloadInstance
}{
{
desc: "test zone survivability works when single nodes are down",
name: "tpcc/multiregion/survive=zone/chaos=true",
survivalGoal: "zone",
chaosTarget: func(iter int) option.NodeListOption {
return option.NodeListOption{(iter % (len(regions) * nodesPerRegion)) + 1}
},
workloadInstances: func() []workloadInstance {
const prometheusPortStart = 2110
ret := []workloadInstance{}
for i := 0; i < len(regions)*nodesPerRegion; i++ {
ret = append(
ret,
workloadInstance{
nodes: option.NodeListOption{i + 1}, // 1-indexed
prometheusPort: prometheusPortStart + i,
extraRunArgs: fmt.Sprintf("--partition-affinity=%d", i/nodesPerRegion), // 0-indexed
},
)
}
return ret
}(),
},
{
desc: "test region survivability works when regions going down",
name: "tpcc/multiregion/survive=region/chaos=true",
survivalGoal: "region",
chaosTarget: func(iter int) option.NodeListOption {
regionIdx := iter % len(regions)
return option.NewNodeListOptionRange(
(nodesPerRegion*regionIdx)+1,
(nodesPerRegion * (regionIdx + 1)),
)
},
workloadInstances: func() []workloadInstance {
// We run two sets of workloads:
// * for each region, have a workload that speaks SQL which only affects data
// that is partitioned in the same region.
// * for each region, have a workload that speaks SQL which affects data
// that is partitioned into a different region.
const prometheusLocalPortStart = 2110
const prometheusRemotePortStart = 2120
ret := []workloadInstance{}
for i := 0; i < len(regions); i++ {
// Data partitioned in the same region.
// e.g. nodes 1-3, partition-affinity=0, prometheus port 2111 means
// we talk to nodes 1-3, with nodes partitioned in nodes 1-3 (affinity 0).
ret = append(
ret,
workloadInstance{
nodes: option.NewNodeListOptionRange((i*nodesPerRegion)+1, ((i + 1) * nodesPerRegion)), // 1-indexed
prometheusPort: prometheusLocalPortStart + i,
extraRunArgs: fmt.Sprintf("--partition-affinity=%d", i), // 0-indexed
},
)
// Data partitioned in a different region.
// e.g. nodes 1-3, partition-affinity=1, prometheus port 2121 means
// we talk to nodes 1-3, with nodes partitioned in nodes 3-6 (affinity 1).
ret = append(
ret,
workloadInstance{
nodes: option.NewNodeListOptionRange((i*nodesPerRegion)+1, ((i + 1) * nodesPerRegion)), // 1-indexed
prometheusPort: prometheusRemotePortStart + i,
extraRunArgs: fmt.Sprintf("--partition-affinity=%d", (i+1)%len(regions)), // 0-indexed
},
)
}
return ret
}(),
},
}
for i := range multiRegionTests {
tc := multiRegionTests[i]
r.Add(registry.TestSpec{
Name: tc.name,
Owner: registry.OwnerSQLFoundations,
// Add an extra node which serves as the workload nodes.
Cluster: r.MakeClusterSpec(len(regions)*nodesPerRegion+1, spec.Geo(), spec.Zones(strings.Join(zs, ","))),
EncryptionSupport: registry.EncryptionMetamorphic,
Leases: registry.MetamorphicLeases,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
t.Status(tc.desc)
duration := 90 * time.Minute
partitionArgs := fmt.Sprintf(
`--survival-goal=%s --regions=%s --partitions=%d`,
tc.survivalGoal,
strings.Join(regions, ","),
len(regions),
)
iter := 0
chaosEventCh := make(chan ChaosEvent)
runTPCC(ctx, t, c, tpccOptions{
Warehouses: len(regions) * warehousesPerRegion,
Duration: duration,
ExtraSetupArgs: partitionArgs,
ExtraRunArgs: `--method=simple --wait=false --tolerate-errors ` + partitionArgs,
Chaos: func() Chaos {
return Chaos{
Timer: Periodic{
Period: 300 * time.Second,
DownTime: 300 * time.Second,
},
Target: func() option.NodeListOption {
ret := tc.chaosTarget(iter)
iter++
return ret
},
Stopper: time.After(duration),
DrainAndQuit: false,
ChaosEventCh: chaosEventCh,
}
},
ChaosEventsProcessor: func(
prometheusNode option.NodeListOption,
workloadInstances []workloadInstance,
) (tpccChaosEventProcessor, error) {
prometheusNodeIP, err := c.ExternalIP(ctx, t.L(), prometheusNode)
if err != nil {
return tpccChaosEventProcessor{}, err
}
client, err := promapi.NewClient(promapi.Config{
Address: fmt.Sprintf("http://%s:9090", prometheusNodeIP[0]),
})
if err != nil {
return tpccChaosEventProcessor{}, err
}
// We see a slow trickle of errors after a server has been force shutdown due
// to queries before the shutdown not fully completing. You can inspect this
// by looking at the workload logs and corresponding the errors with the
// prometheus graphs.
// The errors seen can be of the form:
// * ERROR: inbox communication error: rpc error: code = Canceled
// desc = context canceled (SQLSTATE 58C01)
// Setting this allows some errors to occur.
allowedErrorsMultiplier := 5
if tc.survivalGoal == "region" {
// REGION failures last a bit longer after a region has gone down.
allowedErrorsMultiplier *= 20
}
maxErrorsDuringUptime := warehousesPerRegion * tpcc.NumWorkersPerWarehouse * allowedErrorsMultiplier
return tpccChaosEventProcessor{
workloadInstances: workloadInstances,
workloadNodeIP: prometheusNodeIP[0],
ops: []string{
"newOrder",
"delivery",
"payment",
"orderStatus",
"stockLevel",
},
ch: chaosEventCh,
promClient: promv1.NewAPI(client),
maxErrorsDuringUptime: maxErrorsDuringUptime,
// "delivery" does not trigger often.
allowZeroSuccessDuringUptime: true,
}, nil
},
SetupType: usingInit,
WorkloadInstances: tc.workloadInstances,
})
},
})
}
}
r.Add(registry.TestSpec{
Name: "tpcc/w=100/nodes=3/chaos=true",
Owner: registry.OwnerTestEng,
Cluster: r.MakeClusterSpec(4),
EncryptionSupport: registry.EncryptionMetamorphic,
Leases: registry.MetamorphicLeases,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
duration := 30 * time.Minute
runTPCC(ctx, t, c, tpccOptions{
Warehouses: 100,
Duration: duration,
// For chaos tests, we don't want to use the default method because it
// involves preparing statements on all connections (see #51785).
ExtraRunArgs: "--method=simple --wait=false --tolerate-errors",
Chaos: func() Chaos {
return Chaos{
Timer: Periodic{
Period: 45 * time.Second,
DownTime: 10 * time.Second,
},
Target: func() option.NodeListOption { return c.Node(1 + rand.Intn(c.Spec().NodeCount-1)) },
Stopper: time.After(duration),
DrainAndQuit: false,
}
},
SetupType: usingImport,
})
},
})
// Run a few representative tpccbench specs in CI.
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 3,
CPUs: 4,
LoadWarehouses: 1000,
EstimatedMax: gceOrAws(cloud, 750, 900),
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 3,
CPUs: 4,
LoadWarehouses: 1000,
EstimatedMax: gceOrAws(cloud, 750, 900),
SharedProcessMT: true,
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 3,
CPUs: 4,
EnableDefaultScheduledBackup: true,
LoadWarehouses: 1000,
EstimatedMax: gceOrAws(cloud, 750, 900),
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 3,
CPUs: 16,
LoadWarehouses: gceOrAws(cloud, 3500, 3900),
EstimatedMax: gceOrAws(cloud, 2900, 3500),
Tags: registry.Tags(`aws`),
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 3,
CPUs: 16,
LoadWarehouses: gceOrAws(cloud, 3500, 3900),
EstimatedMax: gceOrAws(cloud, 2900, 3500),
Tags: registry.Tags(`aws`),
SharedProcessMT: true,
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 12,
CPUs: 16,
LoadWarehouses: gceOrAws(cloud, 11500, 11500),
EstimatedMax: gceOrAws(cloud, 10000, 10000),
Tags: registry.Tags(`weekly`),
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 6,
CPUs: 16,
Distribution: multiZone,
LoadWarehouses: 6500,
EstimatedMax: 5000,
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 9,
CPUs: 4,
HighMem: true, // can OOM otherwise: https://github.com/cockroachdb/cockroach/issues/73376
Distribution: multiRegion,
LoadConfig: multiLoadgen,
LoadWarehouses: 3000,
EstimatedMax: 2000,
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 9,
CPUs: 4,
Chaos: true,
LoadConfig: singlePartitionedLoadgen,
LoadWarehouses: 2000,
EstimatedMax: 900,
})
// Encryption-At-Rest benchmarks. These are duplicates of variants above,
// using encrypted stores.
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 3,
CPUs: 4,
LoadWarehouses: 1000,
EstimatedMax: gceOrAws(cloud, 750, 900),
EncryptionEnabled: true,
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 3,
CPUs: 16,
LoadWarehouses: gceOrAws(cloud, 3500, 3900),
EstimatedMax: gceOrAws(cloud, 2900, 3500),
EncryptionEnabled: true,
Tags: registry.Tags(`aws`),
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 12,
CPUs: 16,
LoadWarehouses: gceOrAws(cloud, 11500, 11500),
EstimatedMax: gceOrAws(cloud, 10000, 10000),
EncryptionEnabled: true,
Tags: registry.Tags(`weekly`),
})
// Expiration lease benchmarks. These are duplicates of variants above.
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 3,
CPUs: 4,
LoadWarehouses: 1000,
EstimatedMax: gceOrAws(cloud, 750, 900),
ExpirationLeases: true,
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 3,
CPUs: 16,
LoadWarehouses: gceOrAws(cloud, 3500, 3900),
EstimatedMax: gceOrAws(cloud, 2900, 3500),
ExpirationLeases: true,
Tags: registry.Tags(`aws`),
})
registerTPCCBenchSpec(r, tpccBenchSpec{
Nodes: 12,
CPUs: 16,
LoadWarehouses: gceOrAws(cloud, 11500, 11500),
EstimatedMax: gceOrAws(cloud, 10000, 10000),
ExpirationLeases: true,
Tags: registry.Tags(`weekly`),
})
}
func gceOrAws(cloud string, gce, aws int) int {
if cloud == "aws" {
return aws
}
return gce
}
// tpccBenchDistribution represents a distribution of nodes in a tpccbench