Skip to content

Commit

Permalink
Add a flag to disable compression on Cassandra connection (#1675)
Browse files Browse the repository at this point in the history
* Added flags for driving cassandra connection compression through config

Signed-off-by: Sagar Anand <[email protected]>

* updated disable-compression flag for backward compatibility

Signed-off-by: Sagar Anand <[email protected]>

* Refactored for disable-compression flag

Signed-off-by: Sagar Anand <[email protected]>
  • Loading branch information
sagaranand015 authored and yurishkuro committed Jul 29, 2019
1 parent f6fc248 commit 815ad51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/cassandra/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Configuration struct {
MaxRetryAttempts int `validate:"min=0" yaml:"max_retry_attempt"`
ProtoVersion int `yaml:"proto_version"`
Consistency string `yaml:"consistency"`
DisableCompression bool `yaml:"disable-compression"`
Port int `yaml:"port"`
Authenticator Authenticator `yaml:"authenticator"`
DisableAutoDiscovery bool `yaml:"disable_auto_discovery"`
Expand Down Expand Up @@ -128,7 +129,11 @@ func (c *Configuration) NewCluster() *gocql.ClusterConfig {
if c.Port != 0 {
cluster.Port = c.Port
}
cluster.Compressor = gocql.SnappyCompressor{}

if !c.DisableCompression {
cluster.Compressor = gocql.SnappyCompressor{}
}

if c.Consistency == "" {
cluster.Consistency = gocql.LocalOne
} else {
Expand Down
6 changes: 6 additions & 0 deletions plugin/storage/cassandra/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
suffixKeyspace = ".keyspace"
suffixDC = ".local-dc"
suffixConsistency = ".consistency"
suffixDisableCompression = ".disable-compression"
suffixProtoVer = ".proto-version"
suffixSocketKeepAlive = ".socket-keep-alive"
suffixUsername = ".username"
Expand Down Expand Up @@ -163,6 +164,10 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
nsConfig.namespace+suffixConsistency,
nsConfig.Consistency,
"The Cassandra consistency level, e.g. ANY, ONE, TWO, THREE, QUORUM, ALL, LOCAL_QUORUM, EACH_QUORUM, LOCAL_ONE (default LOCAL_ONE)")
flagSet.Bool(
nsConfig.namespace+suffixDisableCompression,
false,
"Disables the use of the default Snappy Compression while connecting to the Cassandra Cluster if set to true. This is useful for connecting to Cassandra Clusters(like Azure Cosmos Db with Cassandra API) that do not support SnappyCompression")
flagSet.Int(
nsConfig.namespace+suffixProtoVer,
nsConfig.ProtoVersion,
Expand Down Expand Up @@ -243,6 +248,7 @@ func (cfg *namespaceConfig) initFromViper(v *viper.Viper) {
cfg.TLS.ServerName = v.GetString(cfg.namespace + suffixServerName)
cfg.TLS.EnableHostVerification = v.GetBool(cfg.namespace + suffixVerifyHost)
cfg.EnableDependenciesV2 = v.GetBool(cfg.namespace + suffixEnableDependenciesV2)
cfg.DisableCompression = v.GetBool(cfg.namespace + suffixDisableCompression)
}

// GetPrimary returns primary configuration.
Expand Down

0 comments on commit 815ad51

Please sign in to comment.