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

Change default port if provided in new cluster #1645

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michaelraney
Copy link

@michaelraney michaelraney commented Aug 16, 2022

Currently, when creating a cluster, the contact points can contain the port as well. Currently this does not change the port when a new cluster is configured, causing timeout issues to peers. This especially impacting when using TLS which is using 9142 instead of 9042. If user does not set Cluster.Port connection to peers will fail. Traditionally, cassandra drivers do not support connecting to nodes on different cql ports. All nodes must have the same cql port. The result is users may end up connected only to provided seeds initial host without connecting to peers. This pull request adds port assignment to NewCluster by extracting it from the host string if provided

Previously when using the following connection, initial control connection will connect to provided host with 9142. Discovered peers will connect to 9042 the default.

cluster := gocql.NewCluster("cassandra.us-east-1.amazonaws.com:9142")

User must add the port after to fix.

cluster := gocql.NewCluster("cassandra.us-east-1.amazonaws.com:9142")
cluster.Port = 9142

This change will allow user to create connection string and the default host will be the one provided if found. Eliminating simple mistake.

cluster := gocql.NewCluster("cassandra.us-east-1.amazonaws.com:9142")

Change default Port if provided host arrray during creating a new clustor
@martin-sucha
Copy link
Contributor

Thanks for the pull request!

Cassandra 4.0 supports different ports per node (see 8f058c6). However, with Cassandra 4.0 and later, the ClusterConfig.Port will be ignored (instead gocql will use the port from system.peers_v2) so the change should be safe with Cassandra 4.0.

Could this change break something? What should happen if the seeds have different ports? For example shouldn't gocql.NewCluster("hostname1:9142", "hostname2") use 9042 instead of 9142? Shouldn't we try to infer the port only if all the ports are the same?

In any case, please add an entry to the AUTHORS file.

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

Successfully merging this pull request may close these issues.

None yet

2 participants