diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-14 14:26:38 -0300 |
| commit | 294bc6ecabf14c09c9bc8644704921dcf97cb44e (patch) | |
| tree | 279b1e0bab53901a1647ac63c1c724f0f789a663 /src/mongo/client/sdam/server_selector.cpp | |
| parent | 70be7c27a251621187a1de533462ae2bb1e3bd39 (diff) | |
| parent | 1e917fd798aa25b7066d4b414b51184f13d5a092 (diff) | |
Update upstream source from tag 'upstream/6.0.10'debian/6.0.10-1
Update to upstream version '6.0.10'
with Debian dir 2d176fa254eee97b139f712fec5709641335a8c3
Diffstat (limited to 'src/mongo/client/sdam/server_selector.cpp')
| -rw-r--r-- | src/mongo/client/sdam/server_selector.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/mongo/client/sdam/server_selector.cpp b/src/mongo/client/sdam/server_selector.cpp index 5dd58d95684..76d08324f03 100644 --- a/src/mongo/client/sdam/server_selector.cpp +++ b/src/mongo/client/sdam/server_selector.cpp @@ -230,35 +230,40 @@ bool SdamServerSelector::_containsAllTags(ServerDescriptionPtr server, const BSO void SdamServerSelector::filterTags(std::vector<ServerDescriptionPtr>* servers, const TagSet& tagSet) { - const auto& checkTags = tagSet.getTagBSON(); + const auto& tagSetList = tagSet.getTagBSON(); - if (checkTags.nFields() == 0) + if (tagSetList.isEmpty()) { return; + } - 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; + 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; } - // remove the server - return true; - }; + 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; + } + } - servers->erase(std::remove_if(servers->begin(), servers->end(), predicate), servers->end()); + // 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(); } bool SdamServerSelector::recencyFilter(const ReadPreferenceSetting& readPref, |
