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

Allow configuration of Cassandra's host selection policy #4069

Merged
merged 3 commits into from
Apr 16, 2021

Conversation

ChinYing-Li
Copy link
Contributor

Signed-off-by: ChinYing-Li [email protected]

What this PR does:
Though I am not an expert of Cassandra (learning!), I took reference from uber/peloton.
The default HostSelectionPolicy is RoundRobinHostPolicy; only RoundRobinHostPolicy and TokenAwareSelectionPolicy are supported.
Any suggestion is appreciated!

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

Checklist

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

@ChinYing-Li ChinYing-Li changed the title Allow configuration of Cassandra's host selection policy (#) Allow configuration of Cassandra's host selection policy Apr 10, 2021
Copy link
Contributor

@stevesg stevesg left a comment

Choose a reason for hiding this comment

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

Looks good, though I would just improve the documentation for the option a little.

I can't comment on whether the set of options are the correct ones to expose or not, someone with more experience with Cassandra can perhaps offer an opinion.

@@ -63,6 +64,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&cfg.DisableInitialHostLookup, "cassandra.disable-initial-host-lookup", false, "Instruct the cassandra driver to not attempt to get host info from the system.peers table.")
f.BoolVar(&cfg.SSL, "cassandra.ssl", false, "Use SSL when connecting to cassandra instances.")
f.BoolVar(&cfg.HostVerification, "cassandra.host-verification", true, "Require SSL certificate validation.")
f.StringVar(&cfg.HostSelectionPolicy, "cassandra.host-selection-policy", "", "Policy for selecting Cassandra host.")
Copy link
Contributor

Choose a reason for hiding this comment

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

To improve the documentation for this, perhaps we could set the default (instead of checking for ""), and list the supported options.

Suggested change
f.StringVar(&cfg.HostSelectionPolicy, "cassandra.host-selection-policy", "", "Policy for selecting Cassandra host.")
f.StringVar(&cfg.HostSelectionPolicy, "cassandra.host-selection-policy", "RoundRobin", "Policy for selecting Cassandra host. Supported values are: RoundRobin, TokenAware.")

Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

LGTM, thank you.

Copy link
Contributor

@stevesg stevesg left a comment

Choose a reason for hiding this comment

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

Thanks for updating the documentation. I think you need to do make doc again, but the CI should let you know.

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 LGTM, however I have a nit and a optional suggestion

@@ -180,6 +182,15 @@ func (cfg *Config) setClusterConfig(cluster *gocql.ClusterConfig) error {
}
}
}

if cfg.HostSelectionPolicy == "RoundRobin" {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion(non-blocking): consider defining RoundRobin and TokenAware as constant enums. For example:

const (
  SelectionPolicyRoundRobin = "RoundRobin"
  SelectionPolicyTokenAware = "TokenAware"
)

@@ -63,6 +64,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&cfg.DisableInitialHostLookup, "cassandra.disable-initial-host-lookup", false, "Instruct the cassandra driver to not attempt to get host info from the system.peers table.")
f.BoolVar(&cfg.SSL, "cassandra.ssl", false, "Use SSL when connecting to cassandra instances.")
f.BoolVar(&cfg.HostVerification, "cassandra.host-verification", true, "Require SSL certificate validation.")
f.StringVar(&cfg.HostSelectionPolicy, "cassandra.host-selection-policy", "RoundRobin", "Policy for selecting Cassandra host. Supported values are: RoundRobin, TokenAware.")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'm not crazy about the config values requiring capitalization. Would it be possible to rename the config values to be round-robin and token-aware? Or is there an existing convention that would make the current values preferable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose the config values simply because I didn't find similar StringVar for reference. We can avoid capitalization.

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! Good work.

@ChinYing-Li Please rebase onto master when you get a chance.

@jtlisi
Copy link
Contributor

jtlisi commented Apr 16, 2021

@ChinYing-Li it looks like you merged master into your branch instead of rebasing. This makes the PR much less readable and didn't fix the conflict with master. Would you mind cleaning this up to just be the commits you added on top of the master branch?

@pstibrany
Copy link
Contributor

pstibrany commented Apr 16, 2021

@ChinYing-Li it looks like you merged master into your branch instead of rebasing. This makes the PR much less readable and didn't fix the conflict with master. Would you mind cleaning this up to just be the commits you added on top of the master branch?

We do this quite often, and it's also what Github does when you use "Resolve conflicts" button in the UI. Github shows changed files correctly (as does Goland, haven't checked other tools). Why do you write that it makes PR much less readable?

Note that we always squash when merging to master, so in the end, it looks like single commit on the master anyway (svn-style :))

@pstibrany pstibrany merged commit d04b521 into cortexproject:master Apr 16, 2021
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: allow HostSelectionPolicy to be set to TokenAwarePolicy
4 participants