@@ -453,6 +453,14 @@ func (h *HostInfo) IsUp() bool {
453453}
454454
455455func (h * HostInfo ) HostnameAndPort () string {
456+ h .mu .RLock ()
457+ if h .hostname != "" {
458+ s := net .JoinHostPort (h .hostname , strconv .Itoa (h .port ))
459+ h .mu .RUnlock ()
460+ return s
461+ }
462+ h .mu .RUnlock ()
463+
456464 h .mu .Lock ()
457465 defer h .mu .Unlock ()
458466 if h .hostname == "" {
@@ -463,8 +471,8 @@ func (h *HostInfo) HostnameAndPort() string {
463471}
464472
465473func (h * HostInfo ) ConnectAddressAndPort () string {
466- h .mu .Lock ()
467- defer h .mu .Unlock ()
474+ h .mu .RLock ()
475+ defer h .mu .RUnlock ()
468476 addr , _ := h .connectAddressLocked ()
469477 return net .JoinHostPort (addr .String (), strconv .Itoa (h .port ))
470478}
@@ -484,10 +492,7 @@ func (h *HostInfo) String() string {
484492
485493// Polls system.peers at a specific interval to find new hosts
486494type ringDescriber struct {
487- session * Session
488- mu sync.Mutex
489- prevHosts []* HostInfo
490- prevPartitioner string
495+ session * Session
491496}
492497
493498// Returns true if we are using system_schema.keyspaces instead of system.schema_keyspaces
@@ -806,7 +811,7 @@ func (r *ringDescriber) getClusterPeerInfo(localHost *HostInfo) ([]*HostInfo, er
806811
807812// Return true if the host is a valid peer
808813func isValidPeer (host * HostInfo ) bool {
809- return ! (len (host .RPCAddress () ) == 0 ||
814+ return ! (len (host .rpcAddress ) == 0 ||
810815 host .hostId == "" ||
811816 host .dataCenter == "" ||
812817 host .missingRack ||
@@ -815,17 +820,14 @@ func isValidPeer(host *HostInfo) bool {
815820
816821// GetHosts returns a list of hosts found via queries to system.local and system.peers
817822func (r * ringDescriber ) GetHosts () ([]* HostInfo , string , error ) {
818- r .mu .Lock ()
819- defer r .mu .Unlock ()
820-
821823 localHost , err := r .getLocalHostInfo ()
822824 if err != nil {
823- return r . prevHosts , r . prevPartitioner , err
825+ return nil , "" , err
824826 }
825827
826828 peerHosts , err := r .getClusterPeerInfo (localHost )
827829 if err != nil {
828- return r . prevHosts , r . prevPartitioner , err
830+ return nil , "" , err
829831 }
830832
831833 hosts := append ([]* HostInfo {localHost }, peerHosts ... )
@@ -1048,13 +1050,13 @@ func (b *errorBroadcaster) newListener() <-chan error {
10481050
10491051func (b * errorBroadcaster ) broadcast (err error ) {
10501052 b .mu .Lock ()
1051- defer b .mu .Unlock ()
10521053 curListeners := b .listeners
1053- if len (curListeners ) > 0 {
1054- b .listeners = nil
1055- } else {
1054+ if len (curListeners ) == 0 {
1055+ b .mu .Unlock ()
10561056 return
10571057 }
1058+ b .listeners = nil
1059+ b .mu .Unlock ()
10581060
10591061 for _ , listener := range curListeners {
10601062 listener <- err
0 commit comments