Skip to content

Commit

Permalink
strike datacentre spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
bgerrity committed Jan 9, 2025
1 parent 37030fb commit cbfcd16
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ type ClusterConfig struct {
// If DisableInitialHostLookup then the driver will not attempt to get host info
// from the system.peers table, this will mean that the driver will connect to
// hosts supplied and will not attempt to lookup the hosts information, this will
// mean that data_centre, rack and token information will not be available and as
// mean that data_center, rack and token information will not be available and as
// such host filtering and token aware query routing will not be available.
DisableInitialHostLookup bool

Expand Down
14 changes: 10 additions & 4 deletions filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,20 @@ func DenyAllFilter() HostFilter {
})
}

// DataCentreHostFilter filters all hosts such that they are in the same data centre
// as the supplied data centre.
func DataCentreHostFilter(dataCentre string) HostFilter {
// DataCenterHostFilter filters all hosts such that they are in the same data center
// as the supplied data center.
func DataCenterHostFilter(dataCenter string) HostFilter {
return HostFilterFunc(func(host *HostInfo) bool {
return host.DataCenter() == dataCentre
return host.DataCenter() == dataCenter
})
}

// Deprecated: Use DataCenterHostFilter instead.
// DataCentreHostFilter is an alias that doesn't use the preferred spelling.
func DataCentreHostFilter(dataCenter string) HostFilter {
return DataCenterHostFilter(dataCenter)
}

// WhiteListHostFilter filters incoming hosts by checking that their address is
// in the initial hosts whitelist.
func WhiteListHostFilter(hosts ...string) HostFilter {
Expand Down
10 changes: 8 additions & 2 deletions filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ func TestFilter_DenyAll(t *testing.T) {
}
}

func TestFilter_DataCentre(t *testing.T) {
f := DataCentreHostFilter("dc1")
func TestFilter_DataCenter(t *testing.T) {
f := DataCenterHostFilter("dc1")
fDeprecated := DataCentreHostFilter("dc1")

tests := [...]struct {
dc string
accept bool
Expand All @@ -113,5 +115,9 @@ func TestFilter_DataCentre(t *testing.T) {
} else if test.accept {
t.Errorf("%d: should have been accepted but wasn't", i)
}

if f.Accept(&HostInfo{dataCenter: test.dc}) != fDeprecated.Accept(&HostInfo{dataCenter: test.dc}) {
t.Errorf("%d: DataCenterHostFilter and DataCentreHostFilter should be the same", i)
}
}
}
9 changes: 5 additions & 4 deletions host_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ import (
"time"
)

var ErrCannotFindHost = errors.New("cannot find host")
var ErrHostAlreadyExists = errors.New("host already exists")
var (
ErrCannotFindHost = errors.New("cannot find host")
ErrHostAlreadyExists = errors.New("host already exists")
)

type nodeState int32

Expand Down Expand Up @@ -111,7 +113,6 @@ func (c cassVersion) Before(major, minor, patch int) bool {
} else if c.Minor == minor && c.Patch < patch {
return true
}

}
return false
}
Expand Down Expand Up @@ -439,7 +440,7 @@ func (h *HostInfo) String() string {
connectAddr, source := h.connectAddressLocked()
return fmt.Sprintf("[HostInfo hostname=%q connectAddress=%q peer=%q rpc_address=%q broadcast_address=%q "+
"preferred_ip=%q connect_addr=%q connect_addr_source=%q "+
"port=%d data_centre=%q rack=%q host_id=%q version=%q state=%s num_tokens=%d]",
"port=%d data_center=%q rack=%q host_id=%q version=%q state=%s num_tokens=%d]",
h.hostname, h.connectAddress, h.peer, h.rpcAddress, h.broadcastAddress, h.preferredIP,
connectAddr, source,
h.port, h.dataCenter, h.rack, h.hostId, h.version, h.state, len(h.tokens))
Expand Down
16 changes: 7 additions & 9 deletions policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package gocql

//This file will be the future home for more policies
// This file will be the future home for more policies

import (
"context"
Expand Down Expand Up @@ -159,7 +159,7 @@ type RetryPolicy interface {
// //Assign to a query
// query.RetryPolicy(&gocql.SimpleRetryPolicy{NumRetries: 1})
type SimpleRetryPolicy struct {
NumRetries int //Number of times to retry a query
NumRetries int // Number of times to retry a query
}

// Attempt tells gocql to attempt the query again based on query.Attempts being less
Expand Down Expand Up @@ -839,8 +839,8 @@ type dcAwareRR struct {
}

// DCAwareRoundRobinPolicy is a host selection policies which will prioritize and
// return hosts which are in the local datacentre before returning hosts in all
// other datercentres
// return hosts which are in the local datacenter before returning hosts in all
// other datacenters
func DCAwareRoundRobinPolicy(localDC string) HostSelectionPolicy {
return &dcAwareRR{local: localDC}
}
Expand Down Expand Up @@ -885,7 +885,6 @@ func roundRobbin(shift int, hosts ...[]*HostInfo) NextHost {
currentlyObserved := 0

return func() SelectedHost {

// iterate over layers
for {
if currentLayer == len(hosts) {
Expand Down Expand Up @@ -921,7 +920,7 @@ func (d *dcAwareRR) Pick(q ExecutableQuery) NextHost {

// RackAwareRoundRobinPolicy is a host selection policies which will prioritize and
// return hosts which are in the local rack, before hosts in the local datacenter but
// a different rack, before hosts in all other datercentres
// a different rack, before hosts in all other datacenters

type rackAwareRR struct {
// lastUsedHostIdx keeps the index of the last used host.
Expand Down Expand Up @@ -1031,14 +1030,13 @@ func (s *singleHostReadyPolicy) Ready() bool {
type ConvictionPolicy interface {
// Implementations should return `true` if the host should be convicted, `false` otherwise.
AddFailure(error error, host *HostInfo) bool
//Implementations should clear out any convictions or state regarding the host.
// Implementations should clear out any convictions or state regarding the host.
Reset(host *HostInfo)
}

// SimpleConvictionPolicy implements a ConvictionPolicy which convicts all hosts
// regardless of error
type SimpleConvictionPolicy struct {
}
type SimpleConvictionPolicy struct{}

func (e *SimpleConvictionPolicy) AddFailure(error error, host *HostInfo) bool {
return true
Expand Down

0 comments on commit cbfcd16

Please sign in to comment.