diff options
author | Rushan Chen <rushan.chen@mongodb.com> | 2021-12-29 12:46:16 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-25 10:45:14 +0000 |
commit | 58f618e55409436aacb24d9d79f5333d8fa85bcc (patch) | |
tree | 04a308d75bd361d3f16c6fb556e7d1abd3aabd01 | |
parent | 69cf1448e3f015bc439d7fb526ddcfbf2fe2e5c5 (diff) | |
download | mongo-58f618e55409436aacb24d9d79f5333d8fa85bcc.tar.gz |
SERVER-62283 stop gap measure to prevent underflow asserting
(cherry picked from commit c87e167ecf9616be6a5878411b87faade3f2ac31)
-rw-r--r-- | src/mongo/db/pipeline/memory_usage_tracker.h | 20 | ||||
-rw-r--r-- | src/mongo/db/pipeline/memory_usage_tracker_test.cpp | 10 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/mongo/db/pipeline/memory_usage_tracker.h b/src/mongo/db/pipeline/memory_usage_tracker.h index 8bf1e6437c6..275183081ef 100644 --- a/src/mongo/db/pipeline/memory_usage_tracker.h +++ b/src/mongo/db/pipeline/memory_usage_tracker.h @@ -29,6 +29,7 @@ #pragma once +#include <algorithm> #include <memory> #include <utility> @@ -49,11 +50,20 @@ public: PerFunctionMemoryTracker() = delete; void update(long long diff) { - tassert(5578603, - str::stream() << "Underflow on memory tracking, attempting to add " << diff - << " but only " << _currentMemoryBytes << " available", - diff >= 0 || _currentMemoryBytes >= std::abs(diff)); - set(_currentMemoryBytes + diff); + + // TODO SERVER-61281: this is a temporary measure in tackling the problem in this + // ticket. It prevents the underflow from happening but doesn't address the cause + // which is inaccurate tracking. + // Once inaccurate tracking is resolved, the underflow assertion below could be + // restored. + // tassert(5578603, + // str::stream() << "Underflow on memory tracking, attempting to add " << + // diff + // << " but only " << _currentMemoryBytes << " available", + // diff >= 0 || _currentMemoryBytes >= std::abs(diff)); + // set(_currentMemoryBytes + diff); + + set(std::max(_currentMemoryBytes + diff, 0LL)); } void set(long long total) { diff --git a/src/mongo/db/pipeline/memory_usage_tracker_test.cpp b/src/mongo/db/pipeline/memory_usage_tracker_test.cpp index f0514d86758..cc354e7fd69 100644 --- a/src/mongo/db/pipeline/memory_usage_tracker_test.cpp +++ b/src/mongo/db/pipeline/memory_usage_tracker_test.cpp @@ -109,14 +109,18 @@ DEATH_TEST_F(MemoryUsageTrackerTest, _tracker.update(-100); } -DEATH_TEST_F(MemoryUsageTrackerTest, - UpdateFunctionUsageToNegativeIsDisallowed, - "Underflow on memory tracking") { +TEST_F(MemoryUsageTrackerTest, UpdateFunctionUsageToNegativeIsDisallowed) { _funcTracker.set(50LL); ASSERT_EQ(_tracker.currentMemoryBytes(), 50LL); ASSERT_EQ(_tracker.maxMemoryBytes(), 50LL); + // TODO SERVER-61281: Temporarily disable the assert (and associated test) in + // PerFunctionMemoryTracker.update() to prevent inaccurate tracking to cause underflow errors + // Once accurate tracking is implemented and no underflow should happen, this negative test + // could be restored to verify that "Underflow on memory tracking" is reported. + _funcTracker.update(-100); + ASSERT_EQ(_tracker.currentMemoryBytes(), 0LL); } } // namespace |