Skip to content

Commit 9e5880b

Browse files
author
Henrik Johansson
authored
Merge pull request #152 from scylladb/new_partitioning_scheme_patch
gemini: ensure partitioon key buffers don't block
2 parents d289502 + ddb2900 commit 9e5880b

File tree

4 files changed

+61
-18
lines changed

4 files changed

+61
-18
lines changed

Diff for: cmd/gemini/root.go

+24-4
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,12 @@ func runJob(f testJob, schema *gemini.Schema, schemaConfig *gemini.SchemaConfig,
364364
var gs []*gemini.Generators
365365
for _, table := range schema.Tables {
366366
gCfg := &gemini.GeneratorsConfig{
367-
Table: table,
368-
Partitions: &partitionRangeConfig,
369-
Size: concurrency,
370-
Seed: seed,
367+
Table: table,
368+
Partitions: &partitionRangeConfig,
369+
Size: concurrency,
370+
Seed: seed,
371+
PkBufferSize: 10000,
372+
PkUsedBufferSize: 100000,
371373
}
372374
g := gemini.NewGenerator(gCfg)
373375
gs = append(gs, g)
@@ -429,6 +431,12 @@ func ddlJob(ctx context.Context, schema *gemini.Schema, sc *gemini.SchemaConfig,
429431
testStatus.WriteErrors++
430432
return
431433
}
434+
if ddlStmts == nil {
435+
if w := logger.Check(zap.DebugLevel, "no statement generated"); w != nil {
436+
w.Write(zap.String("job", "ddl"))
437+
}
438+
return
439+
}
432440
defer postStmtHook()
433441
defer func() {
434442
if verbose {
@@ -462,6 +470,12 @@ func mutationJob(ctx context.Context, schema *gemini.Schema, _ *gemini.SchemaCon
462470
testStatus.WriteErrors++
463471
return
464472
}
473+
if mutateStmt == nil {
474+
if w := logger.Check(zap.DebugLevel, "no statement generated"); w != nil {
475+
w.Write(zap.String("job", "mutation"))
476+
}
477+
return
478+
}
465479
mutateQuery := mutateStmt.Query
466480
mutateValues := mutateStmt.Values()
467481
if w := logger.Check(zap.DebugLevel, "validation statement"); w != nil {
@@ -482,6 +496,12 @@ func mutationJob(ctx context.Context, schema *gemini.Schema, _ *gemini.SchemaCon
482496

483497
func validationJob(ctx context.Context, schema *gemini.Schema, _ *gemini.SchemaConfig, table *gemini.Table, s store.Store, r *rand.Rand, p gemini.PartitionRangeConfig, partitionValues <-chan gemini.Value, testStatus *Status, logger *zap.Logger) {
484498
checkStmt := schema.GenCheckStmt(table, partitionValues, r, p)
499+
if checkStmt == nil {
500+
if w := logger.Check(zap.DebugLevel, "no statement generated"); w != nil {
501+
w.Write(zap.String("job", "validation"))
502+
}
503+
return
504+
}
485505
checkQuery := checkStmt.Query
486506
checkValues := checkStmt.Values()
487507
if w := logger.Check(zap.DebugLevel, "validation statement"); w != nil {

Diff for: generator.go

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package gemini
22

33
import (
4+
"fmt"
5+
46
"github.com/scylladb/gemini/murmur"
57
"golang.org/x/exp/rand"
68
)
@@ -22,18 +24,20 @@ type Generators struct {
2224
}
2325

2426
type GeneratorsConfig struct {
25-
Table *Table
26-
Partitions *PartitionRangeConfig
27-
Size uint64
28-
Seed uint64
27+
Table *Table
28+
Partitions *PartitionRangeConfig
29+
Size uint64
30+
Seed uint64
31+
PkBufferSize uint64
32+
PkUsedBufferSize uint64
2933
}
3034

3135
func NewGenerator(config *GeneratorsConfig) *Generators {
3236
generators := make([]*source, config.Size)
3337
for i := uint64(0); i < config.Size; i++ {
3438
generators[i] = &source{
35-
newValues: make(chan Value, 10000),
36-
oldValues: make(chan Value, 20000),
39+
newValues: make(chan Value, config.PkBufferSize),
40+
oldValues: make(chan Value, config.PkUsedBufferSize),
3741
}
3842
}
3943
gs := &Generators{
@@ -80,3 +84,20 @@ func (gs *Generators) start() {
8084
}
8185
}()
8286
}
87+
88+
func sendIfPossible(values chan Value, value Value) {
89+
select {
90+
case values <- value:
91+
default:
92+
fmt.Println("Skipped returning an partition key")
93+
}
94+
}
95+
96+
func recvIfPossible(values <-chan Value) (Value, bool) {
97+
select {
98+
case values, ok := <-values:
99+
return values, ok
100+
default:
101+
return nil, false
102+
}
103+
}

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
go.uber.org/zap v1.10.0
2424
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522
2525
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
26+
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac
2627
gopkg.in/inf.v0 v0.9.1
2728
honnef.co/go/tools v0.0.0-2019.2.1 // indirect
2829
)

Diff for: schema.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ func (s *Schema) GenInsertStmt(t *Table, newPartitionValues <-chan Value, oldPar
501501
values := make([]interface{}, len(vals))
502502
copy(values, vals)
503503
defer func() {
504-
oldPartitionValues <- vals
504+
sendIfPossible(oldPartitionValues, vals)
505505
}()
506506
for _, ck := range t.ClusteringKeys {
507507
builder = builder.Columns(ck.Name)
@@ -531,7 +531,7 @@ func (s *Schema) GenInsertJsonStmt(t *Table, newPartitionValues <-chan Value, ol
531531
t.mu.RLock()
532532
defer t.mu.RUnlock()
533533

534-
vals, ok := <-newPartitionValues
534+
vals, ok := recvIfPossible(newPartitionValues)
535535
if !ok {
536536
return nil, nil
537537
}
@@ -605,7 +605,7 @@ func (s *Schema) GenDeleteRows(t *Table, newPartitionValues <-chan Value, oldPar
605605
values := make([]interface{}, len(vals))
606606
copy(values, vals)
607607
defer func() {
608-
oldPartitionValues <- vals
608+
sendIfPossible(oldPartitionValues, vals)
609609
}()
610610
if len(t.ClusteringKeys) > 0 {
611611
ck := t.ClusteringKeys[0]
@@ -698,7 +698,7 @@ func (s *Schema) genSinglePartitionQuery(t *Table, partitionValues <-chan Value,
698698
builder = builder.Where(qb.Eq(pk.Name))
699699
typs = append(typs, pk.Type)
700700
}
701-
values, ok := <-partitionValues
701+
values, ok := recvIfPossible(partitionValues)
702702
if !ok {
703703
return nil
704704
}
@@ -737,7 +737,7 @@ func (s *Schema) genMultiplePartitionQuery(t *Table, partitionValues <-chan Valu
737737
for i, pk := range partitionKeys {
738738
builder = builder.Where(qb.InTuple(pk.Name, pkNum))
739739
for j := 0; j < pkNum; j++ {
740-
vs, ok := <-partitionValues
740+
vs, ok := recvIfPossible(partitionValues)
741741
if !ok {
742742
return nil
743743
}
@@ -773,8 +773,9 @@ func (s *Schema) genClusteringRangeQuery(t *Table, partitionValues <-chan Value,
773773
clusteringKeys = t.MaterializedViews[view].ClusteringKeys
774774
}*/
775775
builder := qb.Select(s.Keyspace.Name + "." + tableName)
776-
values, ok := <-partitionValues
776+
values, ok := recvIfPossible(partitionValues)
777777
if !ok {
778+
// Done or no values available...
778779
return nil
779780
}
780781
for _, pk := range partitionKeys {
@@ -830,7 +831,7 @@ func (s *Schema) genMultiplePartitionClusteringRangeQuery(t *Table, partitionVal
830831
for i, pk := range partitionKeys {
831832
builder = builder.Where(qb.InTuple(pk.Name, pkNum))
832833
for j := 0; j < pkNum; j++ {
833-
vs, ok := <-partitionValues
834+
vs, ok := recvIfPossible(partitionValues)
834835
if !ok {
835836
return nil
836837
}
@@ -878,7 +879,7 @@ func (s *Schema) genSingleIndexQuery(t *Table, partitionValues <-chan Value, r *
878879
pkNum = 1
879880
}
880881
*/
881-
values, ok := <-partitionValues
882+
values, ok := recvIfPossible(partitionValues)
882883
if !ok {
883884
return nil
884885
}

0 commit comments

Comments
 (0)