diff options
author | Rushan Chen <rushan.chen@mongodb.com> | 2021-12-29 12:46:16 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-12-29 13:13:06 +0000 |
commit | c87e167ecf9616be6a5878411b87faade3f2ac31 (patch) | |
tree | 489c91379dc2f520cd98ce60227ed8f4f8981f00 | |
parent | b3a66de85077da1e8304bb3e86736f1f061c5419 (diff) | |
download | mongo-c87e167ecf9616be6a5878411b87faade3f2ac31.tar.gz |
SERVER-62283 stop gap measure to prevent underflow asserting
-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 |