diff --git a/CHANGELOG.md b/CHANGELOG.md index 37ae55e3e..59a54d724 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Refactoring hostpool package test and Expose HostInfo creation (CASSGO-59) +- Fix DisableInitialHostLookup flag ignored when querying system.peers (CASSGO-5) + ### Fixed - Cassandra version unmarshal fix (CASSGO-49) diff --git a/cassandra_test.go b/cassandra_test.go index 54a54f426..2c9ad9583 100644 --- a/cassandra_test.go +++ b/cassandra_test.go @@ -44,7 +44,7 @@ import ( "time" "unicode" - inf "gopkg.in/inf.v0" + "gopkg.in/inf.v0" "github.com/stretchr/testify/require" ) @@ -108,6 +108,40 @@ func TestUseStatementError(t *testing.T) { } } +// TestDisableHostLookupRingRefresh checks that session.ring will not be updated if cluster.DisableInitialHostLookup == true +func TestDisableHostLookupRingRefresh(t *testing.T) { + cluster := createCluster() + cluster.DisableInitialHostLookup = true + + cluster.NumConns = 1 + session := createSessionFromCluster(cluster, t) + defer session.Close() + + oldHosts := make(map[string]*HostInfo) + + for key, host := range session.ring.hosts { + host.broadcastAddress = net.ParseIP("10.10.10.10") + oldHosts[key] = host + } + + // if DisableInitialHostLookup == true - host.broadcastAddress must not be updated. + err := session.refreshRing() + if err != nil { + t.Fatal(err) + } + + for key, host := range session.ring.hosts { + oldHost, ok := oldHosts[key] + if !ok { + t.Fatalf("old host not found for key: %s", key) + } + + if !oldHost.broadcastAddress.Equal(host.broadcastAddress) { + t.Fatalf("broadcast addresses do not match for key: %s", key) + } + } +} + // TestInvalidKeyspace checks that an invalid keyspace will return promptly and without a flood of connections func TestInvalidKeyspace(t *testing.T) { cluster := createCluster() diff --git a/host_source.go b/host_source.go index adcf1a729..914d4ecb0 100644 --- a/host_source.go +++ b/host_source.go @@ -747,6 +747,9 @@ func (s *Session) refreshRing() error { } func refreshRing(r *ringDescriber) error { + if r.session.cfg.DisableInitialHostLookup { + return nil + } hosts, partitioner, err := r.GetHosts() if err != nil { return err diff --git a/session.go b/session.go index ed1a078d3..1fb3be593 100644 --- a/session.go +++ b/session.go @@ -340,7 +340,7 @@ func (s *Session) init() error { go s.reconnectDownedHosts(s.cfg.ReconnectInterval) } - // If we disable the initial host lookup, we need to still check if the + // If we disable the host lookup, we need to still check if the // cluster is using the newer system schema or not... however, if control // connection is disable, we really have no choice, so we just make our // best guess...