diff options
-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 |