Skip to content

Commit

Permalink
Do not call GetHosts() when it is enough to use cached hosts data
Browse files Browse the repository at this point in the history
  • Loading branch information
sylwiaszunejko committed Dec 11, 2024
1 parent 3652cee commit 2b12b53
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
10 changes: 2 additions & 8 deletions policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,10 +982,7 @@ func (d *dcAwareRR) IsOperational(session *Session) error {
return nil
}

hosts, _, err := session.hostSource.GetHosts()
if err != nil {
return fmt.Errorf("gocql: unable to check if session is operational: %v", err)
}
hosts := session.hostSource.allHosts()
for _, host := range hosts {
if !session.cfg.filterHost(host) && host.DataCenter() == d.local {
// Policy can work properly only if there is at least one host from target DC
Expand Down Expand Up @@ -1103,10 +1100,7 @@ func (d *rackAwareRR) IsOperational(session *Session) error {
if session.cfg.disableInit || session.cfg.disableControlConn {
return nil
}
hosts, _, err := session.hostSource.GetHosts()
if err != nil {
return fmt.Errorf("gocql: unable to check if session is operational: %v", err)
}
hosts := session.hostSource.allHosts()
for _, host := range hosts {
if !session.cfg.filterHost(host) && host.DataCenter() == d.localDC && host.Rack() == d.localRack {
// Policy can work properly only if there is at least one host from target DC+Rack
Expand Down
7 changes: 3 additions & 4 deletions tablet_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func TestTablets(t *testing.T) {
panic(fmt.Sprintf("unable to create table: %v", err))
}

hosts, _, err := session.hostSource.GetHosts()
assertTrue(t, "err == nil", err == nil)
hosts := session.hostSource.allHosts()

hostAddresses := []string{}
for _, host := range hosts {
Expand All @@ -37,7 +36,7 @@ func TestTablets(t *testing.T) {
i := 0
for i < 50 {
i = i + 1
err = session.Query(`INSERT INTO test1.table1 (pk, ck, v) VALUES (?, ?, ?);`, i, i%5, i%2).WithContext(ctx).Exec()
err := session.Query(`INSERT INTO test1.table1 (pk, ck, v) VALUES (?, ?, ?);`, i, i%5, i%2).WithContext(ctx).Exec()
if err != nil {
t.Fatal(err)
}
Expand All @@ -52,7 +51,7 @@ func TestTablets(t *testing.T) {
var ck int
var v int

err = session.Query(`SELECT pk, ck, v FROM test1.table1 WHERE pk = ?;`, i).WithContext(ctx).Consistency(One).Trace(trace).Scan(&pk, &ck, &v)
err := session.Query(`SELECT pk, ck, v FROM test1.table1 WHERE pk = ?;`, i).WithContext(ctx).Consistency(One).Trace(trace).Scan(&pk, &ck, &v)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 2b12b53

Please sign in to comment.