@@ -9,8 +9,10 @@ import (
9
9
"fmt"
10
10
"net"
11
11
"net/http"
12
+ "net/netip"
12
13
"regexp"
13
14
"runtime"
15
+ "slices"
14
16
"sort"
15
17
"strconv"
16
18
"strings"
@@ -25,6 +27,7 @@ import (
25
27
"github.com/scylladb/scylla-manager/v3/pkg/util/pointer"
26
28
"github.com/scylladb/scylla-manager/v3/pkg/util/prom"
27
29
"github.com/scylladb/scylla-manager/v3/pkg/util/slice"
30
+ slices2 "github.com/scylladb/scylla-manager/v3/pkg/util2/slices"
28
31
"github.com/scylladb/scylla-manager/v3/swagger/gen/scylla/v1/client/operations"
29
32
"github.com/scylladb/scylla-manager/v3/swagger/gen/scylla/v1/models"
30
33
"go.uber.org/multierr"
@@ -492,12 +495,12 @@ func (c *Client) describeRing(params *operations.StorageServiceDescribeRingByKey
492
495
493
496
ring := Ring {
494
497
ReplicaTokens : make ([]ReplicaTokenRanges , 0 ),
495
- HostDC : map [string ]string {},
498
+ HostDC : map [netip. Addr ]string {},
496
499
}
497
500
dcTokens := make (map [string ]int )
498
501
499
502
replicaTokens := make (map [uint64 ][]TokenRange )
500
- replicaHash := make (map [uint64 ][]string )
503
+ replicaHash := make (map [uint64 ][]netip. Addr )
501
504
502
505
isNetworkTopologyStrategy := true
503
506
rf := len (resp .Payload [0 ].Endpoints )
@@ -513,12 +516,18 @@ func (c *Client) describeRing(params *operations.StorageServiceDescribeRingByKey
513
516
return Ring {}, errors .Wrap (err , "parse EndToken" )
514
517
}
515
518
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
+ })
518
527
519
528
// Aggregate replica set token ranges
520
- hash := ReplicaHash (p . Endpoints )
521
- replicaHash [hash ] = p . Endpoints
529
+ hash := ReplicaHash (replicaSet )
530
+ replicaHash [hash ] = replicaSet
522
531
replicaTokens [hash ] = append (replicaTokens [hash ], TokenRange {
523
532
StartToken : startToken ,
524
533
EndToken : endToken ,
@@ -541,7 +550,11 @@ func (c *Client) describeRing(params *operations.StorageServiceDescribeRingByKey
541
550
542
551
// Update host to DC mapping
543
552
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
545
558
}
546
559
547
560
// Update DC token metrics
@@ -582,11 +595,11 @@ func (c *Client) describeRing(params *operations.StorageServiceDescribeRingByKey
582
595
}
583
596
584
597
// 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 {
586
599
hash := xxhash .New ()
587
600
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
590
603
}
591
604
return hash .Sum64 ()
592
605
}
0 commit comments