Skip to content

Commit d47d3c9

Browse files
committed
fix WeightedICMPSelector
1 parent 1b001d3 commit d47d3c9

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

โ€Žclient/ping_utils.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,21 @@ import (
1111

1212
func newWeightedICMPSelector(servers map[string]string) Selector {
1313
ss := createICMPWeighted(servers)
14-
return &weightedICMPSelector{servers: ss}
14+
wicmps := &weightedICMPSelector{servers: ss}
15+
wicmps.wrs.servers = ss
16+
wicmps.wrs.buildRing()
17+
return wicmps
1518
}
1619

17-
func (s weightedICMPSelector) Select(ctx context.Context, servicePath, serviceMethod string, args interface{}) string {
18-
ss := s.servers
19-
if len(ss) == 0 {
20-
return ""
21-
}
22-
w := nextWeighted(ss)
23-
if w == nil {
24-
return ""
25-
}
26-
return w.Server
20+
func (s *weightedICMPSelector) Select(ctx context.Context, servicePath, serviceMethod string, args interface{}) string {
21+
return s.wrs.Select(ctx, servicePath, serviceMethod, args)
2722
}
2823

2924
func (s *weightedICMPSelector) UpdateServer(servers map[string]string) {
3025
ss := createICMPWeighted(servers)
26+
s.wrs.servers = ss
3127
s.servers = ss
28+
s.wrs.buildRing()
3229
}
3330

3431
func createICMPWeighted(servers map[string]string) []*Weighted {

โ€Žclient/selector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,5 @@ func (s *consistentHashSelector) UpdateServer(servers map[string]string) {
322322
// weightedICMPSelector selects servers with ping result.
323323
type weightedICMPSelector struct {
324324
servers []*Weighted
325+
wrs weightedRoundRobinSelector
325326
}

0 commit comments

Comments
ย (0)