apache / apache/cassandra-gocql-driver

cowHostList uses outdated logic for host uniqueness

Open
#1,757 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.7k
Forks
658
PR merge metrics
No merged PRs in 30d

Description

Please answer these questions before submitting your issue. Thanks!

### What version of Cassandra are you using?
any

### What version of Gocql are you using?
`v1.6.0`

### What version of Go are you using?
`1.22`

### What did you do?
My cluster is hidden behind proxy, all nodes are mapped to one address, but different ports.
For this purpose i have use custom `AddressTranslator` that maps `broadcase_address` of nodes nodes to host+port of the proxy.

It works great, but unfortunately if one node goes down I begin experiencing queries returning `ErrNoConnections`.
Source of the problem is the following, when nodes are being added to the `roundRobinHostPolicy`:
https://github.com/gocql/gocql/blob/6d279ed01c1069d14420584f3f7d5bc1794cf804/policies.go#L331-L333

It uses `cowHostList.add` to do the job, which does deduplication via `HostInfo.Equal`:
https://github.com/gocql/gocql/blob/6d279ed01c1069d14420584f3f7d5bc1794cf804/policies.go#L50-L60

Which relies on `h.ConnectAddress().Equal(host.ConnectAddress())`:
https://github.com/gocql/gocql/blob/6d279ed01c1069d14420584f3f7d5bc1794cf804/host_source.go#L135-L142

As result I end-up with only one node in the `roundRobinHostPolicy.hosts` pool and if this node is one that does not work, then I get `ErrNoConnections` after first retry.

### What did you expect to see?
Everything works as supposed to

### What did you see instead?
`ErrNoConnections`

Contributor guide

Open the contributing guide

Research direction

Read the cowHostList logic in policies.go, especially roundRobinHostPolicy and HostInfo.Equal, then inspect ConnectAddress in host_source.go. Reproduce the proxy setup with an AddressTranslator mapping nodes to one address with different ports. Done means distinct proxy host-and-port endpoints remain usable in the round-robin pool and the ErrNoConnections behavior is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
cassandra, go
Domain
databases, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.