Skip to content

Commit

Permalink
Merge "Use gocqlx" from Henrik
Browse files Browse the repository at this point in the history
Refactored to use github.com/scylladb/gocqlx/qb and a new Store interface is implemented which in essence replaces the preivous Session.

Fixes: #95
  • Loading branch information
penberg authored May 17, 2019
2 parents 375625e + e71b0b9 commit 2f4f5e5
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 262 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

## [1.0.1] - 2019-05-16

- A new Store abstraction is introduced in preparation to enable
implementations such as an in-memory store.
- Gemini now uses github.com/scylladb/gocqlx/qb builder.
- Gemini ensures that primary key buckets do not overflow int32.
- Gemini now accepts a list of node host names or IPs for the test
and Oracle clusters.
Expand Down
49 changes: 32 additions & 17 deletions cmd/gemini/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/briandowns/spinner"
"github.com/pkg/errors"
"github.com/scylladb/gemini"
"github.com/scylladb/gemini/store"
"github.com/spf13/cobra"
"golang.org/x/net/context"
)
Expand Down Expand Up @@ -44,11 +45,17 @@ const (
)

type Status struct {
WriteOps int `json:"write_ops"`
WriteErrors int `json:"write_errors"`
ReadOps int `json:"read_ops"`
ReadErrors int `json:"read_errors"`
Errors []gemini.JobError `json:"errors,omitempty"`
WriteOps int `json:"write_ops"`
WriteErrors int `json:"write_errors"`
ReadOps int `json:"read_ops"`
ReadErrors int `json:"read_errors"`
Errors []JobError `json:"errors,omitempty"`
}

type JobError struct {
Timestamp time.Time
Message string `json:"message"`
Query string `json:"query"`
}

type Results interface {
Expand All @@ -60,7 +67,7 @@ func interactive() bool {
return !nonInteractive
}

type testJob func(context.Context, *sync.WaitGroup, *gemini.Schema, gemini.Table, *gemini.Session, gemini.PartitionRange, chan Status, string, *os.File)
type testJob func(context.Context, *sync.WaitGroup, *gemini.Schema, *gemini.Table, store.Store, gemini.PartitionRange, chan Status, string, *os.File)

func (r *Status) Merge(sum *Status) Status {
sum.WriteOps += r.WriteOps
Expand Down Expand Up @@ -127,6 +134,14 @@ func readSchema(confFile string) (*gemini.Schema, error) {
return schemaBuilder.Build(), nil
}

type createBuilder struct {
stmt string
}

func (cb createBuilder) ToCql() (stmt string, names []string) {
return cb.stmt, nil
}

func run(cmd *cobra.Command, args []string) {
if pkNumberPerThread <= 0 || pkNumberPerThread > (math.MaxInt32/concurrency) {
pkNumberPerThread = math.MaxInt32 / concurrency
Expand Down Expand Up @@ -162,15 +177,15 @@ func run(cmd *cobra.Command, args []string) {
jsonSchema, _ := json.MarshalIndent(schema, "", " ")
fmt.Printf("Schema: %v\n", string(jsonSchema))

session := gemini.NewSession(testClusterHost, oracleClusterHost)
defer session.Close()
store := store.New(schema, testClusterHost, oracleClusterHost)
defer store.Close()

if dropSchema && mode != readMode {
for _, stmt := range schema.GetDropSchema() {
if verbose {
fmt.Println(stmt)
}
if err := session.Mutate(stmt); err != nil {
if err := store.Mutate(createBuilder{stmt: stmt}); err != nil {
fmt.Printf("%v", err)
return
}
Expand All @@ -180,16 +195,16 @@ func run(cmd *cobra.Command, args []string) {
if verbose {
fmt.Println(stmt)
}
if err := session.Mutate(stmt); err != nil {
if err := store.Mutate(createBuilder{stmt: stmt}); err != nil {
fmt.Printf("%v", err)
return
}
}

runJob(Job, schema, session, mode, outFile)
runJob(Job, schema, store, mode, outFile)
}

func runJob(f testJob, schema *gemini.Schema, s *gemini.Session, mode string, out *os.File) {
func runJob(f testJob, schema *gemini.Schema, s store.Store, mode string, out *os.File) {
c := make(chan Status)
minRange := 0
maxRange := pkNumberPerThread
Expand Down Expand Up @@ -259,7 +274,7 @@ func runJob(f testJob, schema *gemini.Schema, s *gemini.Session, mode string, ou
reporter.Wait()
}

func mutationJob(schema *gemini.Schema, table gemini.Table, s *gemini.Session, p gemini.PartitionRange, testStatus *Status, out *os.File) {
func mutationJob(schema *gemini.Schema, table *gemini.Table, s store.Store, p gemini.PartitionRange, testStatus *Status, out *os.File) {
mutateStmt, err := schema.GenMutateStmt(table, &p)
if err != nil {
fmt.Printf("Failed! Mutation statement generation failed: '%v'\n", err)
Expand All @@ -272,7 +287,7 @@ func mutationJob(schema *gemini.Schema, table gemini.Table, s *gemini.Session, p
fmt.Println(mutateStmt.PrettyCQL())
}
if err := s.Mutate(mutateQuery, mutateValues...); err != nil {
e := gemini.JobError{
e := JobError{
Timestamp: time.Now(),
Message: "Mutation failed: " + err.Error(),
Query: mutateStmt.PrettyCQL(),
Expand All @@ -284,7 +299,7 @@ func mutationJob(schema *gemini.Schema, table gemini.Table, s *gemini.Session, p
}
}

func validationJob(schema *gemini.Schema, table gemini.Table, s *gemini.Session, p gemini.PartitionRange, testStatus *Status, out *os.File) {
func validationJob(schema *gemini.Schema, table *gemini.Table, s store.Store, p gemini.PartitionRange, testStatus *Status, out *os.File) {
checkStmt := schema.GenCheckStmt(table, &p)
checkQuery := checkStmt.Query
checkValues := checkStmt.Values()
Expand All @@ -293,7 +308,7 @@ func validationJob(schema *gemini.Schema, table gemini.Table, s *gemini.Session,
}
if err := s.Check(table, checkQuery, checkValues...); err != nil {
// De-duplication needed?
e := gemini.JobError{
e := JobError{
Timestamp: time.Now(),
Message: "Validation failed: " + err.Error(),
Query: checkStmt.PrettyCQL(),
Expand All @@ -305,7 +320,7 @@ func validationJob(schema *gemini.Schema, table gemini.Table, s *gemini.Session,
}
}

func Job(ctx context.Context, wg *sync.WaitGroup, schema *gemini.Schema, table gemini.Table, s *gemini.Session, p gemini.PartitionRange, c chan Status, mode string, out *os.File) {
func Job(ctx context.Context, wg *sync.WaitGroup, schema *gemini.Schema, table *gemini.Table, s store.Store, p gemini.PartitionRange, c chan Status, mode string, out *os.File) {
defer wg.Done()
testStatus := Status{}

Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ module github.com/scylladb/gemini
go 1.12

require (
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/briandowns/spinner v0.0.0-20190311160019-998b3556fb3f
github.com/fatih/color v1.7.0 // indirect
github.com/gocql/gocql v0.0.0-20190301043612-f6df8288f9b4
github.com/gocql/gocql v0.0.0-20190423091413-b99afaf3b163
github.com/google/go-cmp v0.2.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-isatty v0.0.6 // indirect
github.com/pkg/errors v0.8.1
github.com/scylladb/go-set v1.0.2
github.com/scylladb/gocqlx v1.3.0
github.com/segmentio/ksuid v1.0.2
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
github.com/stretchr/testify v1.3.0 // indirect
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0
golang.org/x/net v0.0.0-20190313082753-5c2c250b6a70
Expand Down
9 changes: 7 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/briandowns/spinner v0.0.0-20190311160019-998b3556fb3f h1:MABudtpeYW3sx6sh8sy8k8nPRIQTTvGUOvmUbdvlIGM=
github.com/briandowns/spinner v0.0.0-20190311160019-998b3556fb3f/go.mod h1:hw/JEQBIE+c/BLI4aKM8UU8v+ZqrD3h7HC27kKt8JQU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/set v0.2.1 h1:nn2CaJyknWE/6txyUDGwysr3G5QC6xWB/PtVjPBbeaA=
github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
Expand All @@ -31,10 +33,13 @@ github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/scylladb/go-reflectx v1.0.1/go.mod h1:rWnOfDIRWBGN0miMLIcoPt/Dhi2doCMZqwMCJ3KupFc=
github.com/scylladb/go-set v1.0.2 h1:SkvlMCKhP0wyyct6j+0IHJkBkSZL+TDzZ4E7f7BCcRE=
github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs=
github.com/scylladb/gocql v1.0.1 h1:LVWuLOTllhzKNh4QzPEe/gbsTVww1Li1xTHLv/vaTvY=
github.com/scylladb/gocql v1.0.1/go.mod h1:4Fw1eo5iaEhDUs8XyuhSVCVy52Jq3L+/3GJgYkwc+/0=
github.com/scylladb/gocqlx v1.3.0 h1:PKbWHoRAB2+sgVwKhhFTYwlDdXhFzvMZdQc0JMolLMs=
github.com/scylladb/gocqlx v1.3.0/go.mod h1:1CisD8Z+VB7ByxGyc3B9OXusRNgWWtCMkO+hNCpgZAc=
github.com/segmentio/ksuid v1.0.2 h1:9yBfKyw4ECGTdALaF09Snw3sLJmYIX6AbPJrAy6MrDc=
github.com/segmentio/ksuid v1.0.2/go.mod h1:BXuJDr2byAiHuQaQtSKoXh1J0YmUDurywOXgB2w+OSU=
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
Expand Down
Loading

0 comments on commit 2f4f5e5

Please sign in to comment.