@@ -9,8 +9,10 @@ import (
99 "fmt"
1010 "net"
1111 "net/http"
12+ "net/netip"
1213 "regexp"
1314 "runtime"
15+ "slices"
1416 "sort"
1517 "strconv"
1618 "strings"
@@ -25,6 +27,7 @@ import (
2527 "github.com/scylladb/scylla-manager/v3/pkg/util/pointer"
2628 "github.com/scylladb/scylla-manager/v3/pkg/util/prom"
2729 "github.com/scylladb/scylla-manager/v3/pkg/util/slice"
30+ slices2 "github.com/scylladb/scylla-manager/v3/pkg/util2/slices"
2831 "github.com/scylladb/scylla-manager/v3/swagger/gen/scylla/v1/client/operations"
2932 "github.com/scylladb/scylla-manager/v3/swagger/gen/scylla/v1/models"
3033 "go.uber.org/multierr"
@@ -492,12 +495,12 @@ func (c *Client) describeRing(params *operations.StorageServiceDescribeRingByKey
492495
493496 ring := Ring {
494497 ReplicaTokens : make ([]ReplicaTokenRanges , 0 ),
495- HostDC : map [string ]string {},
498+ HostDC : map [netip. Addr ]string {},
496499 }
497500 dcTokens := make (map [string ]int )
498501
499502 replicaTokens := make (map [uint64 ][]TokenRange )
500- replicaHash := make (map [uint64 ][]string )
503+ replicaHash := make (map [uint64 ][]netip. Addr )
501504
502505 isNetworkTopologyStrategy := true
503506 rf := len (resp .Payload [0 ].Endpoints )
@@ -513,12 +516,18 @@ func (c *Client) describeRing(params *operations.StorageServiceDescribeRingByKey
513516 return Ring {}, errors .Wrap (err , "parse EndToken" )
514517 }
515518
516- // Ensure deterministic order or nodes in replica set
517- sort .Strings (p .Endpoints )
519+ replicaSet , err := slices2 .MapWithError (p .Endpoints , netip .ParseAddr )
520+ if err != nil {
521+ return Ring {}, err
522+ }
523+ // Ensure deterministic order of nodes in replica set
524+ slices .SortFunc (replicaSet , func (a , b netip.Addr ) int {
525+ return a .Compare (b )
526+ })
518527
519528 // Aggregate replica set token ranges
520- hash := ReplicaHash (p . Endpoints )
521- replicaHash [hash ] = p . Endpoints
529+ hash := ReplicaHash (replicaSet )
530+ replicaHash [hash ] = replicaSet
522531 replicaTokens [hash ] = append (replicaTokens [hash ], TokenRange {
523532 StartToken : startToken ,
524533 EndToken : endToken ,
@@ -541,7 +550,11 @@ func (c *Client) describeRing(params *operations.StorageServiceDescribeRingByKey
541550
542551 // Update host to DC mapping
543552 for _ , e := range p .EndpointDetails {
544- ring .HostDC [e .Host ] = e .Datacenter
553+ ip , err := netip .ParseAddr (e .Host )
554+ if err != nil {
555+ return Ring {}, err
556+ }
557+ ring .HostDC [ip ] = e .Datacenter
545558 }
546559
547560 // Update DC token metrics
@@ -582,11 +595,11 @@ func (c *Client) describeRing(params *operations.StorageServiceDescribeRingByKey
582595}
583596
584597// ReplicaHash hashes replicas so that it can be used as a map key.
585- func ReplicaHash (replicaSet []string ) uint64 {
598+ func ReplicaHash (replicaSet []netip. Addr ) uint64 {
586599 hash := xxhash .New ()
587600 for _ , r := range replicaSet {
588- _ , _ = hash .WriteString (r ) // nolint: errcheck
589- _ , _ = hash .WriteString ("," ) // nolint: errcheck
601+ _ , _ = hash .WriteString (r . String ()) // nolint: errcheck
602+ _ , _ = hash .WriteString ("," ) // nolint: errcheck
590603 }
591604 return hash .Sum64 ()
592605}
0 commit comments