Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
36 changes: 35 additions & 1 deletion cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
"time"
"unicode"

inf "gopkg.in/inf.v0"
"gopkg.in/inf.v0"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions host_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down