diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2020-03-10 17:23:57 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-16 21:35:40 +0000 |
commit | 5780368c29834ffb07e1a26590c1e372fb13f950 (patch) | |
tree | cf2ad8daaa81bc4ef3e0cc2e4129e42140bcda6a | |
parent | 304a242aa85bd70a3d902b5aacf7a6e4c4ac7df4 (diff) | |
download | mongo-5780368c29834ffb07e1a26590c1e372fb13f950.tar.gz |
SERVER-46765 remove VersionInfoInterface::isSameMajorVersion
-rw-r--r-- | src/mongo/db/s/balancer/balancer.cpp | 34 | ||||
-rw-r--r-- | src/mongo/util/version.cpp | 33 | ||||
-rw-r--r-- | src/mongo/util/version.h | 6 |
3 files changed, 26 insertions, 47 deletions
diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp index 5c4b267034f..07ccfe125e4 100644 --- a/src/mongo/db/s/balancer/balancer.cpp +++ b/src/mongo/db/s/balancer/balancer.cpp @@ -35,6 +35,7 @@ #include <algorithm> #include <memory> +#include <pcrecpp.h> #include <string> #include "mongo/base/status_with.h" @@ -135,29 +136,26 @@ private: * in the cluster. */ void warnOnMultiVersion(const vector<ClusterStatistics::ShardStatistics>& clusterStats) { + static const auto& majorMinorRE = *new pcrecpp::RE(R"re(^(\d+)\.(\d+)\.)re"); auto&& vii = VersionInfoInterface::instance(); - - bool isMultiVersion = false; - for (const auto& stat : clusterStats) { - if (!vii.isSameMajorVersion(stat.mongoVersion.c_str())) { - isMultiVersion = true; - break; - } - } + auto hasMyVersion = [&](auto&& stat) { + int major; + int minor; + return majorMinorRE.PartialMatch(pcrecpp::StringPiece(stat.mongoVersion), &major, &minor) && + major == vii.majorVersion() && minor == vii.minorVersion(); + }; // If we're all the same version, don't message - if (!isMultiVersion) + if (std::all_of(clusterStats.begin(), clusterStats.end(), hasMyVersion)) return; - StringBuilder sb; - sb << "Multi version cluster detected. Local version: " << vii.version() - << ", shard versions: "; - - for (const auto& stat : clusterStats) { - sb << stat.shardId << " is at " << stat.mongoVersion << "; "; - } - - LOGV2_WARNING(21875, "{sb_str}", "sb_str"_attr = sb.str()); + BSONObjBuilder shardVersions; + for (const auto& stat : clusterStats) + shardVersions << stat.shardId << stat.mongoVersion; + LOGV2_WARNING(21875, + "Multiversion cluster detected", + "localVersion"_attr = vii.version(), + "shardVersions"_attr = shardVersions.done()); } } // namespace diff --git a/src/mongo/util/version.cpp b/src/mongo/util/version.cpp index a2c17c5e93c..04de18b76b3 100644 --- a/src/mongo/util/version.cpp +++ b/src/mongo/util/version.cpp @@ -45,8 +45,10 @@ #include <boost/iterator/transform_iterator.hpp> #include <pcrecpp.h> +#include <fmt/format.h> #include <sstream> +#include "mongo/base/string_data.h" #include "mongo/db/jsobj.h" #include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" @@ -54,6 +56,10 @@ namespace mongo { namespace { +std::string formatVersionString(StringData versioned, const VersionInfoInterface& provider) { + return format(FMT_STRING("{} version v{}"), versioned, provider.version()); +} + class FallbackVersionInfo : public VersionInfoInterface { public: int majorVersion() const noexcept final { @@ -124,21 +130,8 @@ const VersionInfoInterface& VersionInfoInterface::instance(NotEnabledAction acti fassertFailed(40278); } -bool VersionInfoInterface::isSameMajorVersion(const char* otherVersion) const noexcept { - int major = -1, minor = -1; - pcrecpp::RE ver_regex("^(\\d+)\\.(\\d+)\\."); - ver_regex.PartialMatch(otherVersion, &major, &minor); - - if (major == -1 || minor == -1) - return false; - - return (major == majorVersion() && minor == minorVersion()); -} - std::string VersionInfoInterface::makeVersionString(StringData binaryName) const { - std::stringstream ss; - ss << binaryName << " v" << version(); - return ss.str(); + return format(FMT_STRING("{} v{}"), binaryName, version()); } void VersionInfoInterface::appendBuildInfo(BSONObjBuilder* result) const { @@ -233,21 +226,15 @@ void VersionInfoInterface::logBuildInfo() const { } std::string mongoShellVersion(const VersionInfoInterface& provider) { - std::stringstream ss; - ss << "MongoDB shell version v" << provider.version(); - return ss.str(); + return formatVersionString("MongoDB shell", provider); } std::string mongosVersion(const VersionInfoInterface& provider) { - std::stringstream ss; - ss << "mongos version v" << provider.version(); - return ss.str(); + return formatVersionString("mongos", provider); } std::string mongodVersion(const VersionInfoInterface& provider) { - std::stringstream ss; - ss << "db version v" << provider.version(); - return ss.str(); + return formatVersionString("db", provider); } } // namespace mongo diff --git a/src/mongo/util/version.h b/src/mongo/util/version.h index a9a2f0084cd..0492afeb5bc 100644 --- a/src/mongo/util/version.h +++ b/src/mongo/util/version.h @@ -139,12 +139,6 @@ public: std::string openSSLVersion(StringData prefix = "", StringData suffix = "") const; /** - * Returns true if the running version has the same major and minor version as the provided - * string. Note that the minor version is checked, despite the name of this function. - */ - bool isSameMajorVersion(const char* otherVersion) const noexcept; - - /** * Uses the provided text to make a pretty representation of the version. */ std::string makeVersionString(StringData binaryName) const; |