Skip to content

Commit

Permalink
fix(root): introduce --schema-seed
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Kropachev committed Jul 7, 2023
1 parent b6beb50 commit 46ef027
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions cmd/gemini/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var (
outFileArg string
concurrency uint64
seed uint64
schemaSeed uint64
dropSchema bool
verbose bool
mode string
Expand Down Expand Up @@ -110,7 +111,7 @@ func interactive() bool {
return !nonInteractive
}

func readSchema(confFile string, schemaConfig typedef.SchemaConfig) (*typedef.Schema, error) {
func readSchema(confFile string) (*typedef.Schema, error) {
byteValue, err := os.ReadFile(confFile)
if err != nil {
return nil, err
Expand All @@ -124,7 +125,7 @@ func readSchema(confFile string, schemaConfig typedef.SchemaConfig) (*typedef.Sc
}

schemaBuilder := builders.NewSchemaBuilder()
schemaBuilder.Keyspace(shm.Keyspace).Config(schemaConfig)
schemaBuilder.Keyspace(shm.Keyspace)
for t, tbl := range shm.Tables {
shm.Tables[t].LinkIndexAndColumns()
schemaBuilder.Table(tbl)
Expand All @@ -145,6 +146,8 @@ func run(_ *cobra.Command, _ []string) error {
globalStatus := status.NewGlobalStatus(1000)
defer utils.IgnoreError(logger.Sync)

rand.Seed(seed)

cons, err := gocql.ParseConsistencyWrapper(consistency)
if err != nil {
logger.Error("Unable parse consistency, error=%s. Falling back on Quorum", zap.Error(err))
Expand Down Expand Up @@ -193,12 +196,12 @@ func run(_ *cobra.Command, _ []string) error {
}
var schema *typedef.Schema
if len(schemaFile) > 0 {
schema, err = readSchema(schemaFile, schemaConfig)
schema, err = readSchema(schemaFile)
if err != nil {
return errors.Wrap(err, "cannot create schema")
}
} else {
schema = generators.GenSchema(schemaConfig, seed)
schema = generators.GenSchema(schemaConfig, schemaSeed)
}

jsonSchema, _ := json.MarshalIndent(schema, "", " ")
Expand Down Expand Up @@ -279,9 +282,8 @@ func run(_ *cobra.Command, _ []string) error {

if warmup > 0 && !stopFlag.IsHardOrSoft() {
jobsList := jobs.ListFromMode(jobs.WarmupMode, warmup, concurrency)
if err = jobsList.Run(ctx, schema, schemaConfig, st, pump, gens, globalStatus, logger, seed, stop.NewFlag("warmup"), failFast, verbose); err != nil {
if err = jobsList.Run(ctx, schema, schemaConfig, st, pump, gens, globalStatus, logger, seed, stopFlag.CreateChild("warmup"), failFast, verbose); err != nil {
logger.Error("warmup encountered an error", zap.Error(err))
stopFlag.SetHard(true)
}
}

Expand Down Expand Up @@ -380,8 +382,8 @@ func createClusters(
return testCluster, nil
}
oracleCluster := gocql.NewCluster(oracleClusterHost...)
oracleCluster.Timeout = requestTimeout
oracleCluster.ConnectTimeout = connectTimeout
testCluster.Timeout = requestTimeout
testCluster.ConnectTimeout = connectTimeout
oracleCluster.RetryPolicy = retryPolicy
oracleCluster.Consistency = consistency
oracleCluster.PoolConfig.HostSelectionPolicy = oracleHostSelectionPolicy
Expand Down Expand Up @@ -467,7 +469,8 @@ func init() {
rootCmd.Flags().StringVarP(&schemaFile, "schema", "", "", "Schema JSON config file")
rootCmd.Flags().StringVarP(&mode, "mode", "m", jobs.MixedMode, "Query operation mode. Mode options: write, read, mixed (default)")
rootCmd.Flags().Uint64VarP(&concurrency, "concurrency", "c", 10, "Number of threads per table to run concurrently")
rootCmd.Flags().Uint64VarP(&seed, "seed", "s", 1, "PRNG seed value")
rootCmd.Flags().Uint64VarP(&seed, "seed", "s", 1, "Statement seed value")
rootCmd.Flags().Uint64VarP(&schemaSeed, "schema-seed", "", 1, "Schema seed value")
rootCmd.Flags().BoolVarP(&dropSchema, "drop-schema", "d", false, "Drop schema before starting tests run")
rootCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output during test run")
rootCmd.Flags().BoolVarP(&failFast, "fail-fast", "f", false, "Stop on the first failure")
Expand Down Expand Up @@ -534,8 +537,8 @@ func init() {
func printSetup() error {
tw := new(tabwriter.Writer)
tw.Init(os.Stdout, 0, 8, 2, '\t', tabwriter.AlignRight)
rand.Seed(seed)
fmt.Fprintf(tw, "Seed:\t%d\n", seed)
fmt.Fprintf(tw, "Schema seed:\t%d\n", schemaSeed)
fmt.Fprintf(tw, "Maximum duration:\t%s\n", duration)
fmt.Fprintf(tw, "Warmup duration:\t%s\n", warmup)
fmt.Fprintf(tw, "Concurrency:\t%d\n", concurrency)
Expand Down

0 comments on commit 46ef027

Please sign in to comment.