@@ -25,6 +25,14 @@ import (
2525 "github.com/scylladb/scylla-bench/random"
2626)
2727
28+ type (
29+ Session interface {
30+ Query (string , ... interface {}) * gocql.Query
31+ }
32+ )
33+
34+ type ModeFunc func (session * gocql.Session , testResult * results.TestThreadResult , workload WorkloadGenerator , rateLimiter RateLimiter , validateData bool )
35+
2836type DistributionValue struct {
2937 Dist * random.Distribution
3038}
@@ -111,14 +119,14 @@ var (
111119 truncateTable bool
112120)
113121
114- func Query (session * gocql. Session , request string ) {
122+ func Query (session Session , request string ) {
115123 err := session .Query (request ).Exec ()
116124 if err != nil {
117- log .Fatal (err )
125+ log .Panic (err )
118126 }
119127}
120128
121- func PrepareDatabase (session * gocql. Session , replicationFactor int ) {
129+ func PrepareDatabase (session Session , replicationFactor int ) {
122130 //nolint:lll
123131 Query (session , fmt .Sprintf ("CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'replication_factor' : %d }" , keyspaceName , replicationFactor ))
124132
@@ -166,7 +174,7 @@ func GetWorkload(name string, threadID int, partitionOffset int64, mode string,
166174 case "write" :
167175 return NewTimeSeriesWriter (threadID , concurrency , partitionCount , partitionOffset , clusteringRowCount , startTime , int64 (maximumRate / concurrency ))
168176 default :
169- log .Fatal ("time series workload supports only write and read modes" )
177+ log .Panic ("time series workload supports only write and read modes" )
170178 }
171179 case "scan" :
172180 rangesPerThread := rangeCount / concurrency
@@ -179,12 +187,12 @@ func GetWorkload(name string, threadID int, partitionOffset int64, mode string,
179187 }
180188 return NewRangeScan (rangeCount , thisOffset , thisCount )
181189 default :
182- log .Fatal ("unknown workload: " , name , ". Available workloads: sequential, uniform, timeseries, scan" )
190+ log .Panic ("unknown workload: " , name , ". Available workloads: sequential, uniform, timeseries, scan" )
183191 }
184192 panic ("unreachable" )
185193}
186194
187- func GetMode (name string ) func ( session * gocql. Session , testResult * results. TestThreadResult , workload WorkloadGenerator , rateLimiter RateLimiter , validateData bool ) {
195+ func GetMode (name string ) ModeFunc {
188196 switch name {
189197 case "write" :
190198 if rowsPerRequest == 1 {
@@ -200,7 +208,7 @@ func GetMode(name string) func(session *gocql.Session, testResult *results.TestT
200208 case "scan" :
201209 return DoScanTable
202210 default :
203- log .Fatal ("unknown mode: " , name , " . Available modes: write, counter_update, read, counter_read, scan" )
211+ log .Panicf ("unknown mode: %s . Available modes: write, counter_update, read, counter_read, scan" , name )
204212 }
205213 panic ("unreachable" )
206214}
@@ -221,7 +229,7 @@ func getRetryPolicy() *gocql.ExponentialBackoffRetryPolicy {
221229 values := strings .Split (retryInterval , "," )
222230 lenValues := len (values )
223231 if (lenValues == 0 ) || (lenValues > 2 ) {
224- log .Fatal ("Wrong value for retry interval: '" , retryInterval ,
232+ log .Panic ("Wrong value for retry interval: '" , retryInterval ,
225233 "'. Only 1 or 2 values are expected." )
226234 }
227235 for i := range values {
@@ -233,14 +241,14 @@ func getRetryPolicy() *gocql.ExponentialBackoffRetryPolicy {
233241 }
234242 retryMinIntervalMillisecond , err = strconv .Atoi (values [0 ])
235243 if err != nil {
236- log .Fatal ("Wrong value for retry minimum interval: '" , values [0 ], "'" )
244+ log .Panic ("Wrong value for retry minimum interval: '" , values [0 ], "'" )
237245 }
238246 retryMaxIntervalMillisecond , err = strconv .Atoi (values [lenValues - 1 ])
239247 if err != nil {
240- log .Fatal ("Wrong value for retry maximum interval: '" , values [lenValues - 1 ], "'" )
248+ log .Panic ("Wrong value for retry maximum interval: '" , values [lenValues - 1 ], "'" )
241249 }
242250 if retryMinIntervalMillisecond > retryMaxIntervalMillisecond {
243- log .Fatal ("Wrong retry interval values provided: 'min' (" ,
251+ log .Panic ("Wrong retry interval values provided: 'min' (" ,
244252 values [0 ], "ms) interval is bigger than 'max' (" +
245253 values [lenValues - 1 ]+ "ms)" )
246254 }
@@ -392,32 +400,32 @@ func main() {
392400 }
393401
394402 if mode == "" {
395- log .Fatal ("test mode needs to be specified" )
403+ log .Panic ("test mode needs to be specified" )
396404 }
397405
398406 if mode == "scan" {
399407 if workload != "" {
400- log .Fatal ("workload type cannot be scpecified for scan mode" )
408+ log .Panic ("workload type cannot be scpecified for scan mode" )
401409 }
402410 workload = "scan"
403411 if concurrency > rangeCount {
404412 concurrency = rangeCount
405413 log .Printf ("adjusting concurrency to the highest useful value of %v" , concurrency )
406414 }
407415 } else if workload == "" {
408- log .Fatal ("workload type needs to be specified" )
416+ log .Panic ("workload type needs to be specified" )
409417 }
410418
411419 if workload == "uniform" && testDuration == 0 {
412- log .Fatal ("uniform workload requires limited test duration" )
420+ log .Panic ("uniform workload requires limited test duration" )
413421 }
414422
415423 if iterations > 1 && workload != "sequential" && workload != "scan" {
416- log .Fatal ("iterations only supported for the sequential and scan workload" )
424+ log .Panic ("iterations only supported for the sequential and scan workload" )
417425 }
418426
419427 if partitionOffset != 0 && workload == "scan" {
420- log .Fatal ("partition-offset is not supported by the 'scan' workload" )
428+ log .Panic ("partition-offset is not supported by the 'scan' workload" )
421429 }
422430
423431 if selectOrderBy == "" {
@@ -433,34 +441,34 @@ func main() {
433441 case "desc" :
434442 selectOrderByParsed = append (selectOrderByParsed , "ORDER BY ck DESC" )
435443 default :
436- log .Fatal ( fmt . Sprintf ( "value in -select-order-by[%d] is neither of none,asc,desc" , idx ) )
444+ log .Panicf ( "value in -select-order-by[%d] is neither of none,asc,desc" , idx )
437445 }
438446 }
439447
440448 readModeTweaks := toInt (inRestriction ) + toInt (provideUpperBound ) + toInt (noLowerBound )
441449 if mode != "read" && mode != "counter_read" {
442450 if readModeTweaks != 0 {
443- log .Fatal ("in-restriction, no-lower-bound and provide-uppder-bound flags make sense only in read mode" )
451+ log .Panic ("in-restriction, no-lower-bound and provide-uppder-bound flags make sense only in read mode" )
444452 }
445453 } else if readModeTweaks > 1 {
446- log .Fatal ("in-restriction, no-lower-bound and provide-uppder-bound flags are mutually exclusive" )
454+ log .Panic ("in-restriction, no-lower-bound and provide-uppder-bound flags are mutually exclusive" )
447455 }
448456
449457 if workload == "timeseries" && mode == "read" && writeRate == 0 {
450- log .Fatal ("write rate must be provided for time series reads loads" )
458+ log .Panic ("write rate must be provided for time series reads loads" )
451459 }
452460 if workload == "timeseries" && mode == "read" && startTimestamp == 0 {
453- log .Fatal ("start timestamp must be provided for time series reads loads" )
461+ log .Panic ("start timestamp must be provided for time series reads loads" )
454462 }
455463 if workload == "timeseries" && mode == "write" && int64 (concurrency ) > partitionCount {
456- log .Fatal ("time series writes require concurrency less than or equal partition count" )
464+ log .Panic ("time series writes require concurrency less than or equal partition count" )
457465 }
458466 if workload == "timeseries" && mode == "write" && maximumRate == 0 {
459- log .Fatal ("max-rate must be provided for time series write loads" )
467+ log .Panic ("max-rate must be provided for time series write loads" )
460468 }
461469
462470 if 0 >= hdrLatencySigFig || hdrLatencySigFig > 5 {
463- log .Fatal ("hdr-latency-sig should be int from 1 to 5" )
471+ log .Panicf ("hdr-latency-sig should be int from 1 to 5, got %d" , hdrLatencySigFig )
464472 }
465473
466474 if timeout != 0 {
@@ -470,7 +478,7 @@ func main() {
470478 }
471479
472480 if err := results .ValidateGlobalLatencyType (latencyType ); err != nil {
473- log .Fatal (errors .Wrap (err , "Bad value for latency-type" ))
481+ log .Panic (errors .Wrap (err , "Bad value for latency-type" ))
474482 }
475483 var cluster * gocql.ClusterConfig
476484 var err error
@@ -480,17 +488,17 @@ func main() {
480488 } else if ! tlsEncryption && username == "" && password == "" {
481489 cluster , err = scyllacloud .NewCloudCluster (cloudConfigPath )
482490 if err != nil {
483- log .Fatal (err )
491+ log .Panic (err )
484492 }
485493 } else {
486- log .Fatal ("can't use -tls/-username/-password and -cloud-config-path at the same time" )
494+ log .Panic ("can't use -tls/-username/-password and -cloud-config-path at the same time" )
487495 }
488496
489497 retryPolicy = getRetryPolicy ()
490498 if retryHandler == "gocql" {
491499 cluster .RetryPolicy = retryPolicy
492500 } else if retryHandler != "sb" {
493- log .Fatal ("'-retry-handler' option accepts only 'sb' and 'gocql' values." )
501+ log .Panic ("'-retry-handler' option accepts only 'sb' and 'gocql' values." )
494502 }
495503 cluster .DefaultIdempotence = true
496504 cluster .NumConns = connectionCount
@@ -499,7 +507,7 @@ func main() {
499507
500508 policy , err := newHostSelectionPolicy (hostSelectionPolicy , strings .Split (nodes , "," ), datacenter , rack )
501509 if err != nil {
502- log .Fatal (err )
510+ log .Panic (err )
503511 }
504512 cluster .PoolConfig .HostSelectionPolicy = policy
505513
@@ -525,6 +533,7 @@ func main() {
525533 default :
526534 log .Fatal ("unknown consistency level: " , consistencyLevel )
527535 }
536+
528537 if clientCompression {
529538 cluster .Compressor = & gocql.SnappyCompressor {}
530539 }
@@ -543,38 +552,38 @@ func main() {
543552
544553 if caCertFile != "" {
545554 if _ , err := os .Stat (caCertFile ); err != nil {
546- log .Fatal (err )
555+ log .Panic (err )
547556 }
548557 sslOpts .CaPath = caCertFile
549558 }
550559
551560 if clientKeyFile != "" {
552561 if _ , err := os .Stat (clientKeyFile ); err != nil {
553- log .Fatal (err )
562+ log .Panic (err )
554563 }
555564 sslOpts .KeyPath = clientKeyFile
556565 }
557566
558567 if clientCertFile != "" {
559568 if _ , err := os .Stat (clientCertFile ); err != nil {
560- log .Fatal (err )
569+ log .Panic (err )
561570 }
562571 sslOpts .CertPath = clientCertFile
563572 }
564573
565574 if clientKeyFile != "" && clientCertFile == "" {
566- log .Fatal ("tls-client-cert-file is required when tls-client-key-file is provided" )
575+ log .Panic ("tls-client-cert-file is required when tls-client-key-file is provided" )
567576 }
568577 if clientCertFile != "" && clientKeyFile == "" {
569- log .Fatal ("tls-client-key-file is required when tls-client-cert-file is provided" )
578+ log .Panic ("tls-client-key-file is required when tls-client-cert-file is provided" )
570579 }
571580
572581 cluster .SslOpts = sslOpts
573582 }
574583
575584 session , err := cluster .CreateSession ()
576585 if err != nil {
577- log .Fatal (err )
586+ log .Panic (err )
578587 }
579588 defer session .Close ()
580589
0 commit comments