Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Make all consistency levels for cassandra queries configurable (#262)
Browse files Browse the repository at this point in the history
* Make Cassandra consistency levels configurable

* fix high-cons one check

* change config order to high,mid,low
  • Loading branch information
Kiran RG authored Jul 28, 2017
1 parent 7fc068e commit 8c9381a
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions clients/metadata/metadata_cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,41 @@ type CassandraMetadataService struct {
// interface implementation check
var _ m.TChanMetadataService = (*CassandraMetadataService)(nil)

func parseConsistency(cfgCons string) (lowCons gocql.Consistency, midCons gocql.Consistency, highCons gocql.Consistency) {

// use a minimum default consistency of 'One'
lowCons, midCons, highCons = gocql.One, gocql.One, gocql.One

switch cons := strings.Split(cfgCons, ","); len(cons) {
case 3:
lowCons = gocql.ParseConsistency(strings.TrimSpace(cons[2]))
fallthrough

case 2:
midCons = gocql.ParseConsistency(strings.TrimSpace(cons[1]))
if len(cons) == 2 {
lowCons = midCons
}
fallthrough

case 1:
highCons = gocql.ParseConsistency(strings.TrimSpace(cons[0]))
}

return
}

// NewCassandraMetadataService creates an instance of TChanMetadataServiceClient backed up by Cassandra.
func NewCassandraMetadataService(cfg configure.CommonMetadataConfig, log bark.Logger) (*CassandraMetadataService, error) {

if log == nil {
log = bark.NewLoggerFromLogrus(logrus.StandardLogger())
}

// use a minimum consistency of 'Two', so that reads from a recently added (non-current) cassandra
// host, does not result in inconsistent data.
lowCons, midCons := gocql.Two, gocql.Two
highCons := gocql.ParseConsistency(cfg.GetConsistency())

if highCons == gocql.One {

envType := configure.NewCommonConfigure().GetEnvironment()
if envType == configure.EnvProduction {
log.Panic("Highest consistency level of ONE should only be used in TestEnvironment")
}
lowCons, midCons, highCons := parseConsistency(cfg.GetConsistency())

lowCons, midCons = gocql.One, gocql.One
if highCons == gocql.One && configure.NewCommonConfigure().GetEnvironment() == configure.EnvProduction {
log.Panic("Highest consistency level of ONE should only be used in TestEnvironment")
}

clusterName := cfg.GetClusterName()
Expand Down

0 comments on commit 8c9381a

Please sign in to comment.