Skip to content

Commit

Permalink
Use persistence config consistency for schema version check (#2291)
Browse files Browse the repository at this point in the history
* Use persistence config consistency for Cassandra schema version checking
* Update CQL schema tools accordingly
  • Loading branch information
wxing1292 committed Dec 14, 2021
1 parent 074d8eb commit baf3b94
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
3 changes: 0 additions & 3 deletions common/persistence/cassandra/schema_version_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ func NewSchemaVersionReader(session gocql.Session) *SchemaVersionReader {
// ReadSchemaVersion returns the current schema version for the Keyspace
func (svr *SchemaVersionReader) ReadSchemaVersion(keyspace string) (string, error) {
query := svr.session.Query(readSchemaVersionCQL, keyspace)
// when querying the DB schema version, override to local quorum
// in case Cassandra node down (compared to using ALL)
query.Consistency(gocql.LocalQuorum)

iter := query.Iter()
var version string
Expand Down
9 changes: 6 additions & 3 deletions tools/cassandra/cqlclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type (
Timeout int
numReplicas int
Datacenter string
Consistency string
TLS *auth.TLS
}
)
Expand Down Expand Up @@ -135,6 +136,11 @@ func (cfg *CQLClientConfig) toCassandraConfig() *config.Cassandra {
Keyspace: cfg.Keyspace,
TLS: cfg.TLS,
Datacenter: cfg.Datacenter,
Consistency: &config.CassandraStoreConsistency{
Default: &config.CassandraConsistencySettings{
Consistency: cfg.Consistency,
},
},
}

return &cassandraConfig
Expand Down Expand Up @@ -178,9 +184,6 @@ func (client *cqlClient) CreateSchemaVersionTables() error {
// ReadSchemaVersion returns the current schema version for the Keyspace
func (client *cqlClient) ReadSchemaVersion() (string, error) {
query := client.session.Query(readSchemaVersionCQL, client.keyspace)
// when querying the DB schema version, override to local quorum
// in case Cassandra node down (compared to using ALL)
query.Consistency(gocql.LocalQuorum)

iter := query.Iter()
var version string
Expand Down
1 change: 1 addition & 0 deletions tools/cassandra/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func newCQLClientConfig(cli *cli.Context) (*CQLClientConfig, error) {
Keyspace: cli.GlobalString(schema.CLIOptKeyspace),
numReplicas: cli.Int(schema.CLIOptReplicationFactor),
Datacenter: cli.String(schema.CLIOptDatacenter),
Consistency: cli.String(schema.CLIOptConsistency),
}

if cli.GlobalBool(schema.CLIFlagEnableTLS) {
Expand Down
2 changes: 2 additions & 0 deletions tools/common/schema/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ const (
CLIOptReplicationFactor = "replication-factor"
// CLIOptDatacenter is the cli option for NetworkTopologyStrategy datacenter
CLIOptDatacenter = "datacenter"
// CLIOptConsistency is the cli option for consistency settings
CLIOptConsistency = "consistency"
// CLIOptQuiet is the cli option for quiet mode
CLIOptQuiet = "quiet"
// CLIOptForce is the cli option for force mode
Expand Down

0 comments on commit baf3b94

Please sign in to comment.