diff options
author | Benety Goh <benety@mongodb.com> | 2019-06-14 17:58:33 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2019-07-06 07:47:11 -0400 |
commit | 8619df155584acfde99c0c1ed0188c33c03129d2 (patch) | |
tree | 2526b81e6d14e684e6a2f902a82d1a1c98876cf9 | |
parent | 3a446772adac78d516cf3a86ec8d60ec4004ee71 (diff) | |
download | mongo-8619df155584acfde99c0c1ed0188c33c03129d2.tar.gz |
SERVER-39705 add multikey paths to MultikeyPathTracker::mergeMultikeyPaths() invariant message
(cherry picked from commit 1822f7f35f4f86149c81ecbf753957beeebb825a)
-rw-r--r-- | src/mongo/db/multi_key_path_tracker.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/multi_key_path_tracker.h | 5 | ||||
-rw-r--r-- | src/mongo/db/multi_key_path_tracker_test.cpp | 21 |
3 files changed, 31 insertions, 19 deletions
diff --git a/src/mongo/db/multi_key_path_tracker.cpp b/src/mongo/db/multi_key_path_tracker.cpp index 3265cf1019c..d1c2c1ca293 100644 --- a/src/mongo/db/multi_key_path_tracker.cpp +++ b/src/mongo/db/multi_key_path_tracker.cpp @@ -29,18 +29,40 @@ #include "mongo/platform/basic.h" +#include <sstream> + #include "mongo/db/multi_key_path_tracker.h" #include "mongo/util/assert_util.h" +#include "mongo/util/str.h" namespace mongo { const OperationContext::Decoration<MultikeyPathTracker> MultikeyPathTracker::get = OperationContext::declareDecoration<MultikeyPathTracker>(); +// static +std::string MultikeyPathTracker::dumpMultikeyPaths(const MultikeyPaths& multikeyPaths) { + std::stringstream ss; + + ss << "[ "; + for (const auto& multikeyComponents : multikeyPaths) { + ss << "[ "; + for (const auto& multikeyComponent : multikeyComponents) { + ss << multikeyComponent << " "; + } + ss << "] "; + } + ss << "]"; + + return ss.str(); +} + void MultikeyPathTracker::mergeMultikeyPaths(MultikeyPaths* toMergeInto, const MultikeyPaths& newPaths) { - invariant(toMergeInto->size() == newPaths.size()); + invariant(toMergeInto->size() == newPaths.size(), + str::stream() << "toMergeInto: " << dumpMultikeyPaths(*toMergeInto) << "; newPaths: " + << dumpMultikeyPaths(newPaths)); for (auto idx = std::size_t(0); idx < toMergeInto->size(); ++idx) { toMergeInto->at(idx).insert(newPaths[idx].begin(), newPaths[idx].end()); } diff --git a/src/mongo/db/multi_key_path_tracker.h b/src/mongo/db/multi_key_path_tracker.h index 8058f134adf..1fb1ee20fac 100644 --- a/src/mongo/db/multi_key_path_tracker.h +++ b/src/mongo/db/multi_key_path_tracker.h @@ -56,6 +56,11 @@ class MultikeyPathTracker { public: static const OperationContext::Decoration<MultikeyPathTracker> get; + /** + * Returns a string representation of MultikeyPaths for logging. + */ + static std::string dumpMultikeyPaths(const MultikeyPaths& multikeyPaths); + static void mergeMultikeyPaths(MultikeyPaths* toMergeInto, const MultikeyPaths& newPaths); // Decoration requires a default constructor. diff --git a/src/mongo/db/multi_key_path_tracker_test.cpp b/src/mongo/db/multi_key_path_tracker_test.cpp index 7c19eb69dc9..580b69519f3 100644 --- a/src/mongo/db/multi_key_path_tracker_test.cpp +++ b/src/mongo/db/multi_key_path_tracker_test.cpp @@ -42,28 +42,13 @@ namespace mongo { namespace { -std::string dumpMultikeyPaths(const MultikeyPaths& multikeyPaths) { - std::stringstream ss; - - ss << "[ "; - for (const auto multikeyComponents : multikeyPaths) { - ss << "[ "; - for (const auto multikeyComponent : multikeyComponents) { - ss << multikeyComponent << " "; - } - ss << "] "; - } - ss << "]"; - - return ss.str(); -} - void assertMultikeyPathsAreEqual(const MultikeyPaths& actual, const MultikeyPaths& expected) { bool match = (expected == actual); if (!match) { - FAIL(str::stream() << "Expected: " << dumpMultikeyPaths(expected) << ", " + FAIL(str::stream() << "Expected: " << MultikeyPathTracker::dumpMultikeyPaths(expected) + << ", " << "Actual: " - << dumpMultikeyPaths(actual)); + << MultikeyPathTracker::dumpMultikeyPaths(actual)); } ASSERT(match); } |