Skip to content

Commit cb139a3

Browse files
bgerrityjoao-r-reis
authored andcommitted
standardize datacenter spelling
This change keeps the repo internally consistent in the spelling of "datacenter". The public interface is kept to prevent breakage. Patch by Brendan Gerrity; reviewed by João Reis, James Hartig for CASSGO-35
1 parent fb11fad commit cb139a3

File tree

6 files changed

+34
-20
lines changed

6 files changed

+34
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@@ -30,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3031

3132
- Remove HostPoolHostPolicy from gocql package (CASSGO-21)
3233

34+
- Standardized spelling of datacenter (CASSGO-35)
35+
3336
### Fixed
3437

3538
- Retry policy now takes into account query idempotency (CASSGO-27)

cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ type ClusterConfig struct {
198198
// If DisableInitialHostLookup then the driver will not attempt to get host info
199199
// from the system.peers table, this will mean that the driver will connect to
200200
// hosts supplied and will not attempt to lookup the hosts information, this will
201-
// mean that data_centre, rack and token information will not be available and as
201+
// mean that data_center, rack and token information will not be available and as
202202
// such host filtering and token aware query routing will not be available.
203203
DisableInitialHostLookup bool
204204

filters.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,20 @@ func DenyAllFilter() HostFilter {
5353
})
5454
}
5555

56-
// DataCentreHostFilter filters all hosts such that they are in the same data centre
57-
// as the supplied data centre.
58-
func DataCentreHostFilter(dataCentre string) HostFilter {
56+
// DataCenterHostFilter filters all hosts such that they are in the same data center
57+
// as the supplied data center.
58+
func DataCenterHostFilter(dataCenter string) HostFilter {
5959
return HostFilterFunc(func(host *HostInfo) bool {
60-
return host.DataCenter() == dataCentre
60+
return host.DataCenter() == dataCenter
6161
})
6262
}
6363

64+
// Deprecated: Use DataCenterHostFilter instead.
65+
// DataCentreHostFilter is an alias that doesn't use the preferred spelling.
66+
func DataCentreHostFilter(dataCenter string) HostFilter {
67+
return DataCenterHostFilter(dataCenter)
68+
}
69+
6470
// WhiteListHostFilter filters incoming hosts by checking that their address is
6571
// in the initial hosts whitelist.
6672
func WhiteListHostFilter(hosts ...string) HostFilter {

filters_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ func TestFilter_DenyAll(t *testing.T) {
9595
}
9696
}
9797

98-
func TestFilter_DataCentre(t *testing.T) {
99-
f := DataCentreHostFilter("dc1")
98+
func TestFilter_DataCenter(t *testing.T) {
99+
f := DataCenterHostFilter("dc1")
100+
fDeprecated := DataCentreHostFilter("dc1")
101+
100102
tests := [...]struct {
101103
dc string
102104
accept bool
@@ -113,5 +115,9 @@ func TestFilter_DataCentre(t *testing.T) {
113115
} else if test.accept {
114116
t.Errorf("%d: should have been accepted but wasn't", i)
115117
}
118+
119+
if f.Accept(&HostInfo{dataCenter: test.dc}) != fDeprecated.Accept(&HostInfo{dataCenter: test.dc}) {
120+
t.Errorf("%d: DataCenterHostFilter and DataCentreHostFilter should be the same", i)
121+
}
116122
}
117123
}

host_source.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ import (
3535
"time"
3636
)
3737

38-
var ErrCannotFindHost = errors.New("cannot find host")
39-
var ErrHostAlreadyExists = errors.New("host already exists")
38+
var (
39+
ErrCannotFindHost = errors.New("cannot find host")
40+
ErrHostAlreadyExists = errors.New("host already exists")
41+
)
4042

4143
type nodeState int32
4244

@@ -111,7 +113,6 @@ func (c cassVersion) Before(major, minor, patch int) bool {
111113
} else if c.Minor == minor && c.Patch < patch {
112114
return true
113115
}
114-
115116
}
116117
return false
117118
}
@@ -439,7 +440,7 @@ func (h *HostInfo) String() string {
439440
connectAddr, source := h.connectAddressLocked()
440441
return fmt.Sprintf("[HostInfo hostname=%q connectAddress=%q peer=%q rpc_address=%q broadcast_address=%q "+
441442
"preferred_ip=%q connect_addr=%q connect_addr_source=%q "+
442-
"port=%d data_centre=%q rack=%q host_id=%q version=%q state=%s num_tokens=%d]",
443+
"port=%d data_center=%q rack=%q host_id=%q version=%q state=%s num_tokens=%d]",
443444
h.hostname, h.connectAddress, h.peer, h.rpcAddress, h.broadcastAddress, h.preferredIP,
444445
connectAddr, source,
445446
h.port, h.dataCenter, h.rack, h.hostId, h.version, h.state, len(h.tokens))

policies.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
package gocql
2626

27-
//This file will be the future home for more policies
27+
// This file will be the future home for more policies
2828

2929
import (
3030
"context"
@@ -157,7 +157,7 @@ type RetryPolicy interface {
157157
// //Assign to a query
158158
// query.RetryPolicy(&gocql.SimpleRetryPolicy{NumRetries: 1})
159159
type SimpleRetryPolicy struct {
160-
NumRetries int //Number of times to retry a query
160+
NumRetries int // Number of times to retry a query
161161
}
162162

163163
// Attempt tells gocql to attempt the query again based on query.Attempts being less
@@ -696,8 +696,8 @@ type dcAwareRR struct {
696696
}
697697

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

744744
return func() SelectedHost {
745-
746745
// iterate over layers
747746
for {
748747
if currentLayer == len(hosts) {
@@ -778,7 +777,7 @@ func (d *dcAwareRR) Pick(q ExecutableQuery) NextHost {
778777

779778
// RackAwareRoundRobinPolicy is a host selection policies which will prioritize and
780779
// return hosts which are in the local rack, before hosts in the local datacenter but
781-
// a different rack, before hosts in all other datercentres
780+
// a different rack, before hosts in all other datacenters
782781

783782
type rackAwareRR struct {
784783
// lastUsedHostIdx keeps the index of the last used host.
@@ -888,14 +887,13 @@ func (s *singleHostReadyPolicy) Ready() bool {
888887
type ConvictionPolicy interface {
889888
// Implementations should return `true` if the host should be convicted, `false` otherwise.
890889
AddFailure(error error, host *HostInfo) bool
891-
//Implementations should clear out any convictions or state regarding the host.
890+
// Implementations should clear out any convictions or state regarding the host.
892891
Reset(host *HostInfo)
893892
}
894893

895894
// SimpleConvictionPolicy implements a ConvictionPolicy which convicts all hosts
896895
// regardless of error
897-
type SimpleConvictionPolicy struct {
898-
}
896+
type SimpleConvictionPolicy struct{}
899897

900898
func (e *SimpleConvictionPolicy) AddFailure(error error, host *HostInfo) bool {
901899
return true

0 commit comments

Comments
 (0)