Skip to content

Commit 9e9338f

Browse files
committed
Fix connection issue in Amazon Keyspaces
In Amazon Keyspaces, system.local returns the localhost address and system.peers returns a host that contains the same hostID as localhost. This causes the connection issue in refreshRing(), where host address is overwritten with the localhost address and a host with the same hostID results in the "cannot find host" error. This commit fixes GetHosts() so that it ignores localhost if the same hsotID is included in peerHosts.
1 parent c75ff5f commit 9e9338f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

host_source.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,21 @@ func (r *ringDescriber) GetHosts() ([]*HostInfo, string, error) {
722722
return r.prevHosts, r.prevPartitioner, err
723723
}
724724

725-
hosts := append([]*HostInfo{localHost}, peerHosts...)
725+
// if the same HostID exists in peerHosts, localHost needs to be excluded to work properly with Amazon Keyspaces (CASSGO-72, #1873)
726+
var hasSameHostID bool
727+
for _, h := range peerHosts {
728+
if h.HostID() == localHost.HostID() {
729+
hasSameHostID = true
730+
}
731+
}
732+
733+
var hosts []*HostInfo
734+
if hasSameHostID {
735+
hosts = peerHosts
736+
} else {
737+
hosts = append([]*HostInfo{localHost}, peerHosts...)
738+
}
739+
726740
var partitioner string
727741
if len(hosts) > 0 {
728742
partitioner = hosts[0].Partitioner()

0 commit comments

Comments
 (0)