Skip to content

Commit

Permalink
[PBM-1171] handle 4.2 getShardMap
Browse files Browse the repository at this point in the history
  • Loading branch information
defbin committed Sep 18, 2023
1 parent 4def1fe commit f62ec00
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pbm/pbm.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,13 +942,24 @@ func getClusterMembersImpl(ctx context.Context, m *mongo.Client) ([]Shard, error
return nil, errors.WithMessage(err, "query")
}

// the map field is mapping of shard names to replset uri
// if shard name is not set, mongodb will provide unique name for it
// (e.g. the replset name of the shard)
// for configsvr, key name is "config"
var shardMap struct{ Map map[string]string }
if err := res.Decode(&shardMap); err != nil {
return nil, errors.WithMessage(err, "decode")
}

shards := make([]Shard, 0, len(shardMap.Map))
for id, host := range shardMap.Map {
if id == "<local>" || strings.ContainsAny(id, "/:") {
// till 4.2, map field is like connStrings (added in 4.4)
// and <local> key is uri of the directly (w/o mongos) connected replset
// skip not shard name
continue
}

rs, _, _ := strings.Cut(host, "/")
shards = append(shards, Shard{
ID: id,
Expand Down

0 comments on commit f62ec00

Please sign in to comment.