Skip to content

Commit

Permalink
gemini: explicit return of values after mutations
Browse files Browse the repository at this point in the history
The mutation routines now return the used values to the generators
that reuse these for the "old" pks that validators use.
  • Loading branch information
Henrik Johansson committed Aug 19, 2019
1 parent 7a4a7f5 commit ffe8df5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
5 changes: 5 additions & 0 deletions cmd/gemini/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ func mutation(ctx context.Context, schema *gemini.Schema, _ *gemini.SchemaConfig
}
mutateQuery := mutateStmt.Query
mutateValues := mutateStmt.Values()
defer func() {
v := make(gemini.Value, len(table.PartitionKeys))
copy(v, mutateValues)
source.GiveOld(v)
}()
if w := logger.Check(zap.DebugLevel, "validation statement"); w != nil {
w.Write(zap.String("pretty_cql", mutateStmt.PrettyCQL()))
}
Expand Down
19 changes: 9 additions & 10 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@ type Source struct {
}

func (s *Source) Get() (Value, bool) {
v := s.pick()
values := make([]interface{}, len(v))
// Make a copy to allow callers to work with the slice directly
copy(values, v)
select {
case s.oldValues <- v:
default:
// Old source is full, just drop the value
}
return values, true
return s.pick(), true
}

func (s *Source) GetOld() (Value, bool) {
Expand All @@ -41,6 +32,14 @@ func (s *Source) GetOld() (Value, bool) {
}
}

func (s *Source) GiveOld(v Value) {
select {
case s.oldValues <- v:
default:
// Old source is full, just drop the value
}
}

func (s *Source) pick() Value {
return s.values[s.idxFunc()]
}
Expand Down

0 comments on commit ffe8df5

Please sign in to comment.