Skip to content

Commit

Permalink
*some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-li committed Jun 11, 2023
1 parent 7257481 commit 80db162
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 140 deletions.
90 changes: 1 addition & 89 deletions pkg/jobs/gen_check_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package jobs

import (
"math"

"github.com/scylladb/gocqlx/v2/qb"
"golang.org/x/exp/rand"

Expand Down Expand Up @@ -62,7 +60,7 @@ var GenCheckStmtRatios = testschema.CasesRatios{
GenSingleIndexQueryID: 1,
}

func GenCheckStmtNew(s *testschema.Schema, table *testschema.Table, g generators.GeneratorInterface, rnd *rand.Rand, p *typedef.PartitionRangeConfig) *typedef.Stmt {
func GenCheckStmt(s *testschema.Schema, table *testschema.Table, g generators.GeneratorInterface, rnd *rand.Rand, p *typedef.PartitionRangeConfig) *typedef.Stmt {
switch table.AvailableFuncs.Check.RandomCase(rnd) {
case GenSinglePartitionID:
return genSinglePartitionQuery(s, table, g)
Expand Down Expand Up @@ -100,92 +98,6 @@ func GenCheckStmtNew(s *testschema.Schema, table *testschema.Table, g generators
return nil
}

func GenCheckStmt(
s *testschema.Schema,
table *testschema.Table,
g generators.GeneratorInterface,
rnd *rand.Rand,
p *typedef.PartitionRangeConfig,
) *typedef.Stmt {
n := 0
mvNum := -1
maxClusteringRels := 0
numQueryPKs := 0
if len(table.MaterializedViews) > 0 && rnd.Int()%2 == 0 {
mvNum = utils.RandInt2(rnd, 0, len(table.MaterializedViews))
}

switch mvNum {
case -1:
if len(table.Indexes) > 0 {
n = rnd.Intn(5)
} else {
n = rnd.Intn(4)
}
switch n {
case 0:
return genSinglePartitionQuery(s, table, g)
case 1:
numQueryPKs = utils.RandInt2(rnd, 1, table.PartitionKeys.Len())
multiplier := int(math.Pow(float64(numQueryPKs), float64(table.PartitionKeys.Len())))
if multiplier > 100 {
numQueryPKs = 1
}
return genMultiplePartitionQuery(s, table, g, numQueryPKs)
case 2:
maxClusteringRels = utils.RandInt2(rnd, 0, table.ClusteringKeys.Len())
return genClusteringRangeQuery(s, table, g, rnd, p, maxClusteringRels)
case 3:
numQueryPKs = utils.RandInt2(rnd, 1, table.PartitionKeys.Len())
multiplier := int(math.Pow(float64(numQueryPKs), float64(table.PartitionKeys.Len())))
if multiplier > 100 {
numQueryPKs = 1
}
maxClusteringRels = utils.RandInt2(rnd, 0, table.ClusteringKeys.Len())
return genMultiplePartitionClusteringRangeQuery(s, table, g, rnd, p, numQueryPKs, maxClusteringRels)
case 4:
// Reducing the probability to hit these since they often take a long time to run
switch rnd.Intn(5) {
case 0:
idxCount := utils.RandInt2(rnd, 1, len(table.Indexes))
return genSingleIndexQuery(s, table, g, rnd, p, idxCount)
default:
return genSinglePartitionQuery(s, table, g)
}
}
default:
n = rnd.Intn(4)
switch n {
case 0:
return genSinglePartitionQueryMv(s, table, g, rnd, p, mvNum)
case 1:
lenPartitionKeys := table.MaterializedViews[mvNum].PartitionKeys.Len()
numQueryPKs = utils.RandInt2(rnd, 1, lenPartitionKeys)
multiplier := int(math.Pow(float64(numQueryPKs), float64(lenPartitionKeys)))
if multiplier > 100 {
numQueryPKs = 1
}
return genMultiplePartitionQueryMv(s, table, g, rnd, p, mvNum, numQueryPKs)
case 2:
lenClusteringKeys := table.MaterializedViews[mvNum].ClusteringKeys.Len()
maxClusteringRels = utils.RandInt2(rnd, 0, lenClusteringKeys)
return genClusteringRangeQueryMv(s, table, g, rnd, p, mvNum, maxClusteringRels)
case 3:
lenPartitionKeys := table.MaterializedViews[mvNum].PartitionKeys.Len()
numQueryPKs = utils.RandInt2(rnd, 1, lenPartitionKeys)
multiplier := int(math.Pow(float64(numQueryPKs), float64(lenPartitionKeys)))
if multiplier > 100 {
numQueryPKs = 1
}
lenClusteringKeys := table.MaterializedViews[mvNum].ClusteringKeys.Len()
maxClusteringRels = utils.RandInt2(rnd, 0, lenClusteringKeys)
return genMultiplePartitionClusteringRangeQueryMv(s, table, g, rnd, p, mvNum, numQueryPKs, maxClusteringRels)
}
}

return nil
}

func genSinglePartitionQuery(
s *testschema.Schema,
t *testschema.Table,
Expand Down
19 changes: 1 addition & 18 deletions pkg/jobs/gen_ddl_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var GenDdlStmtRatios = testschema.CasesRatios{
GenDropColumnStmtID: 1,
}

func GenDDLStmtNew(s *testschema.Schema, t *testschema.Table, r *rand.Rand, _ *typedef.PartitionRangeConfig, sc *typedef.SchemaConfig) (*typedef.Stmts, error) {
func GenDDLStmt(s *testschema.Schema, t *testschema.Table, r *rand.Rand, _ *typedef.PartitionRangeConfig, sc *typedef.SchemaConfig) (*typedef.Stmts, error) {
switch t.AvailableFuncs.DDL.RandomCase(r) {
case GenDropColumnStmtID:
colNum := r.Intn(len(t.Columns))
Expand All @@ -55,23 +55,6 @@ func GenDDLStmtNew(s *testschema.Schema, t *testschema.Table, r *rand.Rand, _ *t
return nil, nil
}

func GenDDLStmt(s *testschema.Schema, t *testschema.Table, r *rand.Rand, _ *typedef.PartitionRangeConfig, sc *typedef.SchemaConfig) (*typedef.Stmts, error) {
maxVariant := 1
if len(t.Columns) > 0 {
maxVariant = 2
}
switch n := r.Intn(maxVariant + 2); n {
// case 0: // Alter column not supported in Cassandra from 3.0.11
// return t.alterColumn(s.Keyspace.Name)
case 2:
colNum := r.Intn(len(t.Columns))
return genDropColumnStmt(t, s.Keyspace.Name, colNum)
default:
column := testschema.ColumnDef{Name: generators.GenColumnName("col", len(t.Columns)+1), Type: generators.GenColumnType(len(t.Columns)+1, sc)}
return genAddColumnStmt(t, s.Keyspace.Name, &column)
}
}

func appendValue(columnType typedef.Type, r *rand.Rand, p *typedef.PartitionRangeConfig, values []interface{}) []interface{} {
return append(values, columnType.GenValue(r, p)...)
}
Expand Down
34 changes: 1 addition & 33 deletions pkg/jobs/gen_mutate_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var GenMutateStmtRatios = testschema.CasesRatios{
GenDeleteRowsID: 1,
}

func GenMutateStmtNew(
func GenMutateStmt(
s *testschema.Schema,
t *testschema.Table,
g generators.GeneratorInterface,
Expand Down Expand Up @@ -92,38 +92,6 @@ func GenMutateStmtNew(
return nil, nil
}

func GenMutateStmt(s *testschema.Schema, t *testschema.Table, g generators.GeneratorInterface, r *rand.Rand, p *typedef.PartitionRangeConfig, deletes bool) (*typedef.Stmt, error) {
t.RLock()
defer t.RUnlock()

valuesWithToken := g.Get()
if valuesWithToken == nil {
return nil, nil
}
useLWT := false
if p.UseLWT && r.Uint32()%10 == 0 {
useLWT = true
}

if !deletes {
return genInsertOrUpdateStmt(s, t, valuesWithToken, r, p, useLWT)
}
switch n := rand.Intn(1000); n {
case 10, 100:
return genDeleteRows(s, t, valuesWithToken, r, p)
default:
switch rand.Intn(2) {
case 0:
if t.KnownIssues[typedef.KnownIssuesJSONWithTuples] {
return genInsertOrUpdateStmt(s, t, valuesWithToken, r, p, useLWT)
}
return genInsertJSONStmt(s, t, valuesWithToken, r, p)
default:
return genInsertOrUpdateStmt(s, t, valuesWithToken, r, p, useLWT)
}
}
}

func genInsertOrUpdateStmt(
s *testschema.Schema,
t *testschema.Table,
Expand Down

0 comments on commit 80db162

Please sign in to comment.