Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cassandra table options flag #2575

Merged
merged 8 commits into from
Jun 8, 2020

Conversation

kwSeo
Copy link
Contributor

@kwSeo kwSeo commented May 10, 2020

What this PR does:
This PR adds cassandra.table-options flag and storage.cassandra.table_options configuration option to customize Cassandra table options when creating index or chunk table by table-manager.

Configuration Example

storage:
  engine: "chunks"
  cassandra:
    addresses: "127.0.0.1"
    port: 9042
    keyspace: "cortex"
    consistency: "ONE"
    auth: false
    table_options: "CLUSTERING ORDER BY (range DESC)
      AND comment = 'Important records'
      AND compaction = { 'class' : 'LeveledCompactionStrategy' }"

EDIT: rename table_with -> table_options

Which issue(s) this PR fixes:
Fixes #2453

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I like the idea of being able to configure this. However, I think it would be better to do it using a well defined struct instead of just passing a string.

PRIMARY KEY (hash, range)
)`, desc.Name)
if c.cfg.TableWith != "" {
query = fmt.Sprintf("%s WITH %s", query, c.cfg.TableWith)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, joining a string like this for a query to Cassandra is dangerous. If the end goal is to change the compaction strategy, I think that would be better handled with a CompactionConfig struct that a parameterizes all of the possible compactions strategies into a config and generates the appropriate query string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtlisi @pracucci

Thank you for review! I agree your opinion.
And there are some considerations.
Some of table options for Cassandra are related to duration, like this:

gc_grace_seconds = 864000
default_time_to_live = 0
tombstone_compaction_interval = 864000
max_sstable_age_days = 100
...

I thought table options like above are suitable for time.Duration type.
But some of names for table options indicate time unit.
I am not sure if time.Duration is suitable.
There is a way to rename the table options but I'm concerned about user confusion.
I am curious about your opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is specifically for Cassandra,I recommend using types that will make input correspond to Cassandra. That way users already familiar with the system will be able to directly copy config values over.

So in the cases you mentioned above I would use int values. Just make sure you document each option in the flag help text.

Copy link

@coelho coelho May 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtlisi

In our use case, we are using ScyllaDB, which is compatible but contains many options that are not default in Cassandra.

https://docs.scylladb.com/getting-started/ddl/
CTRL-F scylla_encryption_options

It is a bad idea to assume what flags the Cassandra server will support. In my opinion this should be made extensible and the current PR does that nicely.

This is a niche flag that will only be used by those who fully understand the implications of changing the flag, better solved by documentation, and already have authorization on the Cassandra server through the configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtlisi
In addition to @coelho, there may be another use cases, such as DataStax products.
Also, table options depend on the Cassandra version.
It is hard to find all options and consider all differences.
My goals have been just caching and compaction strategy.
But this issue seems to have more considerations than I think.
If you still think joining string is dangerous, it may need another way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, and I agree in some cases a separate string makes sense. @pracucci WDYT?

@@ -66,6 +67,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.DurationVar(&cfg.MinBackoff, "cassandra.retry-min-backoff", 100*time.Millisecond, "Minimum time to wait before retrying a failed request. (Default = 100ms)")
f.DurationVar(&cfg.MaxBackoff, "cassandra.retry-max-backoff", 10*time.Second, "Maximum time to wait before retrying a failed request. (Default = 10s)")
f.IntVar(&cfg.QueryConcurrency, "cassandra.query-concurrency", 0, "Limit number of concurrent queries to Cassandra. (Default is 0: no limit)")
f.StringVar(&cfg.TableWith, "cassandra.table-with", "", "Table options used to create index or chunk tables.(Default = \"\": use default table options of Cassandra")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend naming this variable TableOptions and the flag table-options.

Also the help text should explain that the provided string will be concatenated to all table creation operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtlisi
I have renamed table-with to table-options and improved the help text.

# Table options used to create index or chunk tables.(Default = "": use
# default table options of Cassandra
# CLI flag: -cassandra.table-with
[table_with: <string> | default = ""]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure to update https://github.com/cortexproject/cortex/blob/master/docs/production/storage-cassandra.md with information about this flag. As well as warnings about the potential issues a user could face by misconfiguring it.

Copy link
Contributor Author

@kwSeo kwSeo May 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtlisi @coelho
I have written the description about table_options to the storage-cassandra.md.
I think I am not that good at English...
Please check if there is anything strange about the contents.

Copy link

@coelho coelho May 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
EDIT: Great English btw, no worries :)

@pull-request-size pull-request-size bot added size/L and removed size/M labels May 23, 2020
@kwSeo kwSeo requested a review from jtlisi May 31, 2020 15:14
Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please rebase when you get a chance.

@kwSeo kwSeo force-pushed the add_cassandra_flags branch from 2474ab0 to 3caa5bb Compare June 3, 2020 01:04
@kwSeo
Copy link
Contributor Author

kwSeo commented Jun 3, 2020

@jtlisi
Thank you for your review.
I have done rebase.

@kwSeo kwSeo requested a review from jtlisi June 4, 2020 13:44
@kwSeo kwSeo force-pushed the add_cassandra_flags branch from b3180a1 to 3caa5bb Compare June 8, 2020 15:09
@kwSeo kwSeo force-pushed the add_cassandra_flags branch from 3caa5bb to 8a55066 Compare June 8, 2020 15:13
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cassandra CompactionStrategy
4 participants