summaryrefslogtreecommitdiff
path: root/src/mongo/client/sdam/server_selector.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/client/sdam/server_selector.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/client/sdam/server_selector.cpp')
-rw-r--r--src/mongo/client/sdam/server_selector.cpp51
1 files changed, 23 insertions, 28 deletions
diff --git a/src/mongo/client/sdam/server_selector.cpp b/src/mongo/client/sdam/server_selector.cpp
index 76d08324f03..5dd58d95684 100644
--- a/src/mongo/client/sdam/server_selector.cpp
+++ b/src/mongo/client/sdam/server_selector.cpp
@@ -230,40 +230,35 @@ bool SdamServerSelector::_containsAllTags(ServerDescriptionPtr server, const BSO
void SdamServerSelector::filterTags(std::vector<ServerDescriptionPtr>* servers,
const TagSet& tagSet) {
- const auto& tagSetList = tagSet.getTagBSON();
+ const auto& checkTags = tagSet.getTagBSON();
- if (tagSetList.isEmpty()) {
+ if (checkTags.nFields() == 0)
return;
- }
- for (const auto& tagSetElem : tagSetList) {
- if (tagSetElem.type() != BSONType::Object) {
- LOGV2_WARNING(4671202,
- "Invalid tag set specified for server selection; tag sets should be"
- " specified as a BSON object",
- "tag"_attr = tagSetElem);
- continue;
+ const auto predicate = [&](const ServerDescriptionPtr& s) {
+ auto it = checkTags.begin();
+ while (it != checkTags.end()) {
+ if (it->isABSONObj()) {
+ const BSONObj& tags = it->Obj();
+ if (_containsAllTags(s, tags)) {
+ // found a match -- don't remove the server
+ return false;
+ }
+ } else {
+ LOGV2_WARNING(
+ 4671202,
+ "Invalid tags specified for server selection; tags should be specified as "
+ "bson Objects",
+ "tag"_attr = *it);
+ }
+ ++it;
}
- const auto predicate = [&](const ServerDescriptionPtr& s) {
- const bool shouldRemove = !_containsAllTags(s, tagSetElem.embeddedObject());
- return shouldRemove;
- };
-
- auto it = std::remove_if(servers->begin(), servers->end(), predicate);
- // If none of the server descriptions match the tag set, then continue on to check the next
- // tag set in the list. Otherwise, if at least one of the server descriptions match the tag
- // set criteria, then we've found our preferred host(s) to read from.
- if (it != servers->begin()) {
- servers->erase(it, servers->end());
- return;
- }
- }
+ // remove the server
+ return true;
+ };
- // Getting here means a non-empty tag set list was specified but none of the server descriptions
- // matched any of the tag sets in the list. We've therefore failed to find any server
- // description matching the read preference tag criteria.
- servers->clear();
+ servers->erase(std::remove_if(servers->begin(), servers->end(), predicate), servers->end());
}
bool SdamServerSelector::recencyFilter(const ReadPreferenceSetting& readPref,