From cbfcd166bda1d4e616c08caea4f064ef42414842 Mon Sep 17 00:00:00 2001 From: Brendan Gerrity Date: Tue, 19 Nov 2024 10:50:02 -0500 Subject: [PATCH] strike datacentre spelling --- cluster.go | 2 +- filters.go | 14 ++++++++++---- filters_test.go | 10 ++++++++-- host_source.go | 9 +++++---- policies.go | 16 +++++++--------- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/cluster.go b/cluster.go index 413695ca4..0eb0441ad 100644 --- a/cluster.go +++ b/cluster.go @@ -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 diff --git a/filters.go b/filters.go index f51de7fe2..312bd0d1a 100644 --- a/filters.go +++ b/filters.go @@ -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 { diff --git a/filters_test.go b/filters_test.go index 68bf2ad75..a1abec207 100644 --- a/filters_test.go +++ b/filters_test.go @@ -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 @@ -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) + } } } diff --git a/host_source.go b/host_source.go index a0bab9ad0..1aebc3b43 100644 --- a/host_source.go +++ b/host_source.go @@ -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 @@ -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 } @@ -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)) diff --git a/policies.go b/policies.go index 1157da87b..49be67134 100644 --- a/policies.go +++ b/policies.go @@ -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" @@ -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 @@ -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} } @@ -885,7 +885,6 @@ func roundRobbin(shift int, hosts ...[]*HostInfo) NextHost { currentlyObserved := 0 return func() SelectedHost { - // iterate over layers for { if currentLayer == len(hosts) { @@ -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. @@ -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