Skip to content

Commit

Permalink
GODRIVER-2572 Resolve misaligned server selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Aug 8, 2023
1 parent a474c8c commit 2bc53da
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions mongo/description/server_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (selector writeServerSelector) String() string {
return selector.info().String()
}

func (writeServerSelector) SelectServer(t Topology, s []Server) ([]Server, error) {
func (writeServerSelector) SelectServer(t Topology, candidates []Server) ([]Server, error) {
switch t.Kind {
case Single, LoadBalanced:
return candidates, nil
Expand Down Expand Up @@ -218,26 +218,24 @@ func (selector readPrefServerSelector) String() string {
return selector.info().String()
}

func (selector readPrefServerSelector) SelectServer(t Topology, s []Server) ([]Server, error) {
return ServerSelectorFunc(func(t Topology, candidates []Server) ([]Server, error) {
if t.Kind == LoadBalanced {
// In LoadBalanced mode, there should only be one server in the topology and it must be selected. We check
// this before checking MaxStaleness support because there's no monitoring in this mode, so the candidate
// server wouldn't have a wire version set, which would result in an error.
return candidates, nil
}
func (selector readPrefServerSelector) SelectServer(t Topology, candidates []Server) ([]Server, error) {
if t.Kind == LoadBalanced {
// In LoadBalanced mode, there should only be one server in the topology and it must be selected. We check
// this before checking MaxStaleness support because there's no monitoring in this mode, so the candidate
// server wouldn't have a wire version set, which would result in an error.
return candidates, nil
}

switch t.Kind {
case Single:
return candidates, nil
case ReplicaSetNoPrimary, ReplicaSetWithPrimary:
return selectForReplicaSet(selector.rp, selector.isOutputAggregate, t, candidates)
case Sharded:
return selectByKind(candidates, Mongos), nil
}
switch t.Kind {
case Single:
return candidates, nil
case ReplicaSetNoPrimary, ReplicaSetWithPrimary:
return selectForReplicaSet(selector.rp, selector.isOutputAggregate, t, candidates)
case Sharded:
return selectByKind(candidates, Mongos), nil
}

return nil, nil
})
return nil, nil
}

// OutputAggregateSelector selects servers based on the provided read preference
Expand Down

0 comments on commit 2bc53da

Please sign in to comment.