Skip to content

Commit 38eff35

Browse files
authored
Merge pull request #328 from scylladb/dk/implement_stmt_cache
feat(generators): impelemt statement cache
2 parents e771939 + 361fa69 commit 38eff35

File tree

21 files changed

+490
-126
lines changed

21 files changed

+490
-126
lines changed

pkg/builders/builders.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package builders
1616

1717
import (
18+
"github.com/scylladb/gemini/pkg/querycache"
1819
"github.com/scylladb/gemini/pkg/testschema"
1920
"github.com/scylladb/gemini/pkg/typedef"
2021
)
@@ -49,7 +50,11 @@ func (s *schemaBuilder) Table(table *testschema.Table) SchemaBuilder {
4950
}
5051

5152
func (s *schemaBuilder) Build() *testschema.Schema {
52-
return &testschema.Schema{Keyspace: s.keyspace, Tables: s.tables}
53+
out := &testschema.Schema{Keyspace: s.keyspace, Tables: s.tables}
54+
for id := range s.tables {
55+
s.tables[id].Init(out, querycache.New(out))
56+
}
57+
return out
5358
}
5459

5560
func NewSchemaBuilder() SchemaBuilder {

pkg/coltypes/bag.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func (ct *BagType) GenValue(r *rand.Rand, p *typedef.PartitionRangeConfig) []int
8686
return []interface{}{out}
8787
}
8888

89+
func (ct *BagType) LenValue() int {
90+
return 1
91+
}
92+
8993
func (ct *BagType) Indexable() bool {
9094
return false
9195
}

pkg/coltypes/simple_type.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (st SimpleType) CQLHolder() string {
6363
return "?"
6464
}
6565

66+
func (st SimpleType) LenValue() int {
67+
return 1
68+
}
69+
6670
func (st SimpleType) CQLPretty(query string, value []interface{}) (string, int) {
6771
if len(value) == 0 {
6872
return query, 0

pkg/coltypes/tuple.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,11 @@ func (t *TupleType) GenValue(r *rand.Rand, p *typedef.PartitionRangeConfig) []in
8383
}
8484
return out
8585
}
86+
87+
func (t *TupleType) LenValue() int {
88+
out := 0
89+
for _, tp := range t.Types {
90+
out += tp.LenValue()
91+
}
92+
return out
93+
}

pkg/coltypes/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"golang.org/x/exp/rand"
2525

2626
"github.com/scylladb/gemini/pkg/typedef"
27+
"github.com/scylladb/gemini/pkg/utils"
2728
)
2829

2930
const (
@@ -144,6 +145,10 @@ func (mt *MapType) GenValue(r *rand.Rand, p *typedef.PartitionRangeConfig) []int
144145
return []interface{}{vals}
145146
}
146147

148+
func (mt *MapType) LenValue() int {
149+
return 1
150+
}
151+
147152
func (mt *MapType) CQLDef() string {
148153
if mt.Frozen {
149154
return "frozen<map<" + mt.KeyType.CQLDef() + "," + mt.ValueType.CQLDef() + ">>"
@@ -176,9 +181,16 @@ func (ct *CounterType) CQLPretty(query string, value []interface{}) (string, int
176181
}
177182

178183
func (ct *CounterType) GenValue(r *rand.Rand, p *typedef.PartitionRangeConfig) []interface{} {
184+
if utils.UnderTest {
185+
return []interface{}{r.Int63()}
186+
}
179187
return []interface{}{atomic.AddInt64(&ct.Value, 1)}
180188
}
181189

190+
func (ct *CounterType) LenValue() int {
191+
return 1
192+
}
193+
182194
func (ct *CounterType) CQLDef() string {
183195
return "counter"
184196
}

pkg/coltypes/udt.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,7 @@ func (t *UDTType) GenValue(r *rand.Rand, p *typedef.PartitionRangeConfig) []inte
8282
}
8383
return []interface{}{vals}
8484
}
85+
86+
func (t *UDTType) LenValue() int {
87+
return 1
88+
}

pkg/generators/schema_mutation_stmt_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ package generators
1616

1717
import (
1818
"testing"
19+
20+
"github.com/scylladb/gemini/pkg/utils"
1921
)
2022

2123
var (
@@ -51,6 +53,8 @@ var (
5153
)
5254

5355
func TestGenInsertStmt(t *testing.T) {
56+
utils.SetUnderTest()
57+
t.Parallel()
5458
expected := initExpected(t, "insert.json", genInsertStmtCases, *updateExpected)
5559
if *updateExpected {
5660
defer expected.updateExpected(t)
@@ -59,7 +63,7 @@ func TestGenInsertStmt(t *testing.T) {
5963
caseName := genInsertStmtCases[idx]
6064
t.Run(caseName,
6165
func(subT *testing.T) {
62-
schema, prc, gen, rnd, useLWT, _ := getAllForTestStmt(subT, genInsertStmtCases[idx])
66+
schema, prc, gen, rnd, useLWT, _ := getAllForTestStmt(subT, caseName)
6367
stmt, err := genInsertStmt(schema, schema.Tables[0], gen.Get(), rnd, prc, useLWT)
6468
validateStmt(subT, stmt, err)
6569
expected.CompareOrStore(subT, caseName, stmt)
@@ -68,6 +72,8 @@ func TestGenInsertStmt(t *testing.T) {
6872
}
6973

7074
func TestGenUpdateStmt(t *testing.T) {
75+
utils.SetUnderTest()
76+
t.Parallel()
7177
expected := initExpected(t, "update.json", genUpdateStmtCases, *updateExpected)
7278
if *updateExpected {
7379
defer expected.updateExpected(t)
@@ -76,7 +82,7 @@ func TestGenUpdateStmt(t *testing.T) {
7682
caseName := genUpdateStmtCases[idx]
7783
t.Run(caseName,
7884
func(subT *testing.T) {
79-
schema, prc, gen, rnd, _, _ := getAllForTestStmt(subT, genUpdateStmtCases[idx])
85+
schema, prc, gen, rnd, _, _ := getAllForTestStmt(subT, caseName)
8086
stmt, err := genUpdateStmt(schema, schema.Tables[0], gen.Get(), rnd, prc)
8187
validateStmt(subT, stmt, err)
8288
expected.CompareOrStore(subT, caseName, stmt)
@@ -85,6 +91,8 @@ func TestGenUpdateStmt(t *testing.T) {
8591
}
8692

8793
func TestGenDeleteRows(t *testing.T) {
94+
utils.SetUnderTest()
95+
t.Parallel()
8896
expected := initExpected(t, "delete.json", genDeleteStmtCases, *updateExpected)
8997
if *updateExpected {
9098
defer expected.updateExpected(t)
@@ -93,7 +101,7 @@ func TestGenDeleteRows(t *testing.T) {
93101
caseName := genDeleteStmtCases[idx]
94102
t.Run(caseName,
95103
func(subT *testing.T) {
96-
schema, prc, gen, rnd, _, _ := getAllForTestStmt(subT, genDeleteStmtCases[idx])
104+
schema, prc, gen, rnd, _, _ := getAllForTestStmt(subT, caseName)
97105
stmt, err := genDeleteRows(schema, schema.Tables[0], gen.Get(), rnd, prc)
98106
validateStmt(subT, stmt, err)
99107
expected.CompareOrStore(subT, caseName, stmt)
@@ -102,6 +110,7 @@ func TestGenDeleteRows(t *testing.T) {
102110
}
103111

104112
func BenchmarkGenInsertStmt(t *testing.B) {
113+
utils.SetUnderTest()
105114
for idx := range genInsertStmtCases {
106115
caseName := genInsertStmtCases[idx]
107116
t.Run(caseName,
@@ -116,6 +125,7 @@ func BenchmarkGenInsertStmt(t *testing.B) {
116125
}
117126

118127
func BenchmarkGenUpdateStmt(t *testing.B) {
128+
utils.SetUnderTest()
119129
for idx := range genUpdateStmtCases {
120130
caseName := genUpdateStmtCases[idx]
121131
t.Run(caseName,
@@ -130,6 +140,7 @@ func BenchmarkGenUpdateStmt(t *testing.B) {
130140
}
131141

132142
func BenchmarkGenDeleteRows(t *testing.B) {
143+
utils.SetUnderTest()
133144
for idx := range genDeleteStmtCases {
134145
caseName := genDeleteStmtCases[idx]
135146
t.Run(caseName,

0 commit comments

Comments
 (0)