Skip to content

Commit 5a023a6

Browse files
authored
Merge pull request #1110 from percona/PBM-1512-fix-sharded-cluster-hidden-mem-reporting
PBM-1512: Remove cli validation for available agents
2 parents e2c5d52 + 873b9e7 commit 5a023a6

File tree

2 files changed

+3
-59
lines changed

2 files changed

+3
-59
lines changed

pbm/topo/cluster.go

+3-36
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package topo
22

33
import (
44
"context"
5-
"fmt"
65
"strings"
76

87
"go.mongodb.org/mongo-driver/bson"
@@ -121,7 +120,6 @@ func ClusterMembers(ctx context.Context, m *mongo.Client) ([]Shard, error) {
121120
return nil, errors.Wrap(err, "define cluster state")
122121
}
123122

124-
// sharded cluster topo
125123
var shards []Shard
126124
if inf.IsMongos() || inf.IsSharded() {
127125
members, err := getShardMapImpl(ctx, m)
@@ -137,15 +135,10 @@ func ClusterMembers(ctx context.Context, m *mongo.Client) ([]Shard, error) {
137135
return shards, nil
138136
}
139137

140-
// RS topo
141-
hosts, err := GetReplsetHosts(ctx, m)
142-
if err != nil {
143-
return nil, errors.Wrap(err, "get all hosts for RS")
144-
}
145138
shards = []Shard{{
146139
ID: inf.SetName,
147140
RS: inf.SetName,
148-
Host: fmt.Sprintf("%s/%s", inf.SetName, strings.Join(hosts, ",")),
141+
Host: inf.SetName + "/" + strings.Join(inf.Hosts, ","),
149142
}}
150143
return shards, nil
151144
}
@@ -160,44 +153,18 @@ func getShardMapImpl(ctx context.Context, m *mongo.Client) (map[ReplsetName]Shar
160153
// if shard name is not set, mongodb will provide unique name for it
161154
// (e.g. the replset name of the shard)
162155
// for configsvr, key name is "config"
163-
// hosts field is used to discover hidden members, which are not present in map field
164-
var shardMap struct {
165-
Map map[string]string
166-
Hosts map[string]string
167-
}
156+
var shardMap struct{ Map map[string]string }
168157
if err := res.Decode(&shardMap); err != nil {
169158
return nil, errors.Wrap(err, "decode")
170159
}
171160

172-
// Example of the hosts field from command output:
173-
// hosts: {
174-
// 'rs103:27017': 'rs1',
175-
// 'rs101:27017': 'rs1',
176-
// 'cfg02:27017': 'config',
177-
// ...
178-
// }
179-
// hostsByShard will contain even hidden RS members
180-
hostsByShard := map[string][]string{}
181-
for host, shardID := range shardMap.Hosts {
182-
hostsByShard[shardID] = append(hostsByShard[shardID], host)
183-
}
184-
185-
// for PSMDB 6 and below, config srv is not reported within hosts field
186-
if len(hostsByShard["config"]) == 0 {
187-
cfgHostgs, err := GetReplsetHosts(ctx, m)
188-
if err != nil {
189-
return nil, errors.Wrap(err, "get all hosts for config RS")
190-
}
191-
hostsByShard["config"] = cfgHostgs
192-
}
193-
194161
shards := make(map[string]Shard, len(shardMap.Map))
195162
for id, host := range shardMap.Map {
196163
rs, _, _ := strings.Cut(host, "/")
197164
shards[rs] = Shard{
198165
ID: id,
199166
RS: rs,
200-
Host: fmt.Sprintf("%s/%s", rs, strings.Join(hostsByShard[id], ",")),
167+
Host: host,
201168
}
202169
}
203170

pbm/topo/topo.go

-23
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ func collectTopoCheckErrors(
107107

108108
hosts := strings.Split(uri, ",")
109109
members := make(map[NodeURI][]error, len(hosts))
110-
anyAvail := false
111110
for _, host := range hosts {
112111
a, ok := agents[host]
113112
if !ok || a.Arbiter {
@@ -131,16 +130,9 @@ func collectTopoCheckErrors(
131130
}
132131

133132
members[host] = errs
134-
if len(errs) == 0 {
135-
anyAvail = true
136-
}
137133
}
138134

139135
rv.Replsets[rsName] = members
140-
141-
if !anyAvail {
142-
rv.Missed = append(rv.Missed, rsName)
143-
}
144136
}
145137

146138
if rv.hasError() {
@@ -195,21 +187,6 @@ func GetReplsetStatus(ctx context.Context, m *mongo.Client) (*ReplsetStatus, err
195187
return status, nil
196188
}
197189

198-
// GetReplsetHosts returns host names for all RS members.
199-
// It includes also hidden and passive RS members.
200-
func GetReplsetHosts(ctx context.Context, m *mongo.Client) ([]string, error) {
201-
s, err := GetReplsetStatus(ctx, m)
202-
if err != nil {
203-
return nil, errors.Wrap(err, "get replset status")
204-
}
205-
206-
hosts := []string{}
207-
for _, m := range s.Members {
208-
hosts = append(hosts, m.Name)
209-
}
210-
return hosts, nil
211-
}
212-
213190
func GetNodeStatus(ctx context.Context, m *mongo.Client, name string) (*NodeStatus, error) {
214191
s, err := GetReplsetStatus(ctx, m)
215192
if err != nil {

0 commit comments

Comments
 (0)