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 12, 2023
1 parent 541f842 commit 889544a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 98 deletions.
98 changes: 8 additions & 90 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 @@ -61,7 +59,13 @@ var GenCheckStmtRatios = typedef.CasesRatios{
GenSingleIndexQueryID: 1,
}

func GenCheckStmtNew(s *typedef.Schema, table *typedef.Table, g generators.GeneratorInterface, rnd *rand.Rand, p *typedef.PartitionRangeConfig) *typedef.Stmt {
func GenCheckStmt(
s *typedef.Schema,
table *typedef.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 @@ -99,92 +103,6 @@ func GenCheckStmtNew(s *typedef.Schema, table *typedef.Table, g generators.Gener
return nil
}

func GenCheckStmt(
s *typedef.Schema,
table *typedef.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 *typedef.Schema,
t *typedef.Table,
Expand Down Expand Up @@ -314,7 +232,7 @@ func genMultiplePartitionQueryMv(
return nil
}
if i == 0 {
values = appendValue(pk.Type, r, p, values)
values = append(values, pk.Type.GenValue(r, p)...)
typs = append(typs, pk.Type)
} else {
values = append(values, vs.Value[i-1])
Expand Down
4 changes: 0 additions & 4 deletions pkg/jobs/gen_ddl_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ func GenDDLStmt(s *typedef.Schema, t *typedef.Table, r *rand.Rand, _ *typedef.Pa
return nil, nil
}

func appendValue(columnType typedef.Type, r *rand.Rand, p *typedef.PartitionRangeConfig, values []interface{}) []interface{} {
return append(values, columnType.GenValue(r, p)...)
}

func genAddColumnStmt(t *typedef.Table, keyspace string, column *typedef.ColumnDef) (*typedef.Stmts, error) {
var stmts []*typedef.Stmt
if c, ok := column.Type.(*typedef.UDTType); ok {
Expand Down
8 changes: 4 additions & 4 deletions pkg/jobs/gen_mutate_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ func genUpdateStmt(_ *typedef.Schema, t *typedef.Table, valuesWithToken *typedef
nonCounters := t.Columns.NonCounters()
values := make(typedef.Values, 0, t.PartitionKeys.LenValues()+t.ClusteringKeys.LenValues()+nonCounters.LenValues())
for _, cdef := range nonCounters {
values = appendValue(cdef.Type, r, p, values)
values = append(values, cdef.Type.GenValue(r, p)...)
}
values = values.CopyFrom(valuesWithToken.Value)
for _, ck := range t.ClusteringKeys {
values = appendValue(ck.Type, r, p, values)
values = append(values, ck.Type.GenValue(r, p)...)
}
return &typedef.Stmt{
StmtCache: stmtCache,
Expand Down Expand Up @@ -218,8 +218,8 @@ func genDeleteRows(_ *typedef.Schema, t *typedef.Table, valuesWithToken *typedef
values := valuesWithToken.Value.Copy()
if len(t.ClusteringKeys) > 0 {
ck := t.ClusteringKeys[0]
values = appendValue(ck.Type, r, p, values)
values = appendValue(ck.Type, r, p, values)
values = append(values, ck.Type.GenValue(r, p)...)
values = append(values, ck.Type.GenValue(r, p)...)
}
return &typedef.Stmt{
StmtCache: stmtCache,
Expand Down

0 comments on commit 889544a

Please sign in to comment.