summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/window_function/partition_iterator_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/window_function/partition_iterator_test.cpp')
-rw-r--r--src/mongo/db/pipeline/window_function/partition_iterator_test.cpp78
1 files changed, 37 insertions, 41 deletions
diff --git a/src/mongo/db/pipeline/window_function/partition_iterator_test.cpp b/src/mongo/db/pipeline/window_function/partition_iterator_test.cpp
index 8b7a6beab76..cb6b5bcf1bf 100644
--- a/src/mongo/db/pipeline/window_function/partition_iterator_test.cpp
+++ b/src/mongo/db/pipeline/window_function/partition_iterator_test.cpp
@@ -499,20 +499,22 @@ TEST_F(PartitionIteratorTest, MemoryUsageAccountsForDocumentIteratorCache) {
const auto mock = DocumentSourceMock::createForTest(docs, getExpCtx());
[[maybe_unused]] auto accessor = makeDefaultAccessor(mock, boost::none);
- size_t initialDocSize = docs[0].getDocument().getCurrentApproximateSize();
+ size_t initialDocSize = docs[0].getDocument().getApproximateSize();
- // Pull in the first document, and verify the reported size of the iterator is roughly the size
- // of the document.
+ // Pull in the first document, and verify the reported size of the iterator is roughly double
+ // the size of the document. The size of the iterator is double the size of the document because
+ // we greedily fill the cache, so each internal document in memory stores two copies of
+ // largeStr.
ASSERT_DOCUMENT_EQ(*_iter->current(), docs[0].getDocument());
- ASSERT_GT(_iter->getApproximateSize(), initialDocSize);
- ASSERT_LT(_iter->getApproximateSize(), initialDocSize + 500);
+ ASSERT_GT(_iter->getApproximateSize(), initialDocSize * 2);
+ ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 2 + 500);
// Pull in the second document. Both docs remain in the cache so the reported memory should
// include both.
advance();
ASSERT_DOCUMENT_EQ(*_iter->current(), docs[1].getDocument());
- ASSERT_GT(_iter->getApproximateSize(), initialDocSize);
- ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 2 + 500);
+ ASSERT_GT(_iter->getApproximateSize(), initialDocSize * 2 * 2);
+ ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 2 * 2 + 500);
}
TEST_F(PartitionIteratorTest, MemoryUsageAccountsForArraysInDocumentIteratorCache) {
@@ -523,21 +525,21 @@ TEST_F(PartitionIteratorTest, MemoryUsageAccountsForArraysInDocumentIteratorCach
const auto mock = DocumentSourceMock::createForTest(docs, getExpCtx());
[[maybe_unused]] auto accessor = makeDefaultAccessor(mock, boost::none);
- size_t initialDocSize = docs[0].getDocument().getCurrentApproximateSize();
+ size_t initialDocSize = docs[0].getDocument().getApproximateSize();
- // Pull in the first document, and verify the reported size of the iterator is roughly the size
- // of the document. The reason we can't use EQ is that for memory tracking we call shred() so
- // that the document cache will not increase when fields are accessed
+ // Pull in the first document, and verify the reported size of the iterator is roughly
+ // triple the size of the document. The reason for this is that 'largeStr' is cached twice; once
+ // for the 'arr' element and once for the nested 'subObj' element.
ASSERT_DOCUMENT_EQ(*_iter->current(), docs[0].getDocument());
- ASSERT_GT(_iter->getApproximateSize(), initialDocSize);
- ASSERT_LT(_iter->getApproximateSize(), initialDocSize + 1024);
+ ASSERT_GT(_iter->getApproximateSize(), initialDocSize * 3);
+ ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 3 + 1024);
// Pull in the second document. Both docs remain in the cache so the reported memory should
// include both.
advance();
ASSERT_DOCUMENT_EQ(*_iter->current(), docs[1].getDocument());
- ASSERT_GT(_iter->getApproximateSize(), initialDocSize * 2);
- ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 2 + 1024);
+ ASSERT_GT(_iter->getApproximateSize(), (initialDocSize * 3) * 2);
+ ASSERT_LT(_iter->getApproximateSize(), (initialDocSize * 3) * 2 + 1024);
}
TEST_F(PartitionIteratorTest, MemoryUsageAccountsForNestedArraysInDocumentIteratorCache) {
@@ -548,21 +550,21 @@ TEST_F(PartitionIteratorTest, MemoryUsageAccountsForNestedArraysInDocumentIterat
const auto mock = DocumentSourceMock::createForTest(docs, getExpCtx());
[[maybe_unused]] auto accessor = makeDefaultAccessor(mock, boost::none);
- size_t initialDocSize = docs[0].getDocument().getCurrentApproximateSize();
+ size_t initialDocSize = docs[0].getDocument().getApproximateSize();
- // Pull in the first document, and verify the reported size of the iterator is roughly the size
- // of the document. The reason we can't use EQ is that for memory tracking we call shred() so
- // that the document cache will not increase when fields are accessed
+ // Pull in the first document, and verify the reported size of the iterator is roughly
+ // triple the size of the document. The reason for this is that 'largeStr' is cached twice; once
+ // for the 'arr' element and once for the nested 'subObj' element.
ASSERT_DOCUMENT_EQ(*_iter->current(), docs[0].getDocument());
- ASSERT_GT(_iter->getApproximateSize(), initialDocSize);
- ASSERT_LT(_iter->getApproximateSize(), initialDocSize + 1024);
+ ASSERT_GT(_iter->getApproximateSize(), initialDocSize * 3);
+ ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 3 + 1024);
// Pull in the second document. Both docs remain in the cache so the reported memory should
// include both.
advance();
ASSERT_DOCUMENT_EQ(*_iter->current(), docs[1].getDocument());
- ASSERT_GT(_iter->getApproximateSize(), initialDocSize * 2);
- ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 2 + 1024);
+ ASSERT_GT(_iter->getApproximateSize(), (initialDocSize * 3) * 2);
+ ASSERT_LT(_iter->getApproximateSize(), (initialDocSize * 3) * 2 + 1024);
}
TEST_F(PartitionIteratorTest, MemoryUsageAccountsForNestedObjInDocumentIteratorCache) {
@@ -573,12 +575,13 @@ TEST_F(PartitionIteratorTest, MemoryUsageAccountsForNestedObjInDocumentIteratorC
const auto mock = DocumentSourceMock::createForTest(docs, getExpCtx());
[[maybe_unused]] auto accessor = makeDefaultAccessor(mock, boost::none);
- size_t initialDocSize = docs[0].getDocument().getCurrentApproximateSize();
+ size_t initialDocSize = docs[0].getDocument().getApproximateSize();
- // Pull in the first document, and verify the reported size.
+ // Pull in the first document, and verify the reported size. TODO SERVER-57011: The approximate
+ // size should not double count the nested strings.
ASSERT_DOCUMENT_EQ(*_iter->current(), docs[0].getDocument());
- ASSERT_GT(_iter->getApproximateSize(), initialDocSize);
- ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 2);
+ ASSERT_GT(_iter->getApproximateSize(), initialDocSize * 3);
+ ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 4);
}
TEST_F(PartitionIteratorTest, MemoryUsageAccountsForReleasedDocuments) {
@@ -589,27 +592,20 @@ TEST_F(PartitionIteratorTest, MemoryUsageAccountsForReleasedDocuments) {
const auto mock = DocumentSourceMock::createForTest(docs, getExpCtx());
auto accessor = makeDefaultAccessor(mock, boost::none);
- size_t initialDocSize = docs[0].getDocument().getCurrentApproximateSize();
+ size_t initialDocSize = docs[0].getDocument().getApproximateSize();
- // Pull in the first document, and verify the reported size of the iterator is roughly the size
- // of the document.
+ // Pull in the first document, and verify the reported size of the iterator is roughly double
+ // the size of the document.
ASSERT_DOCUMENT_EQ(*accessor[0], docs[0].getDocument());
- ASSERT_GT(_iter->getApproximateSize(), initialDocSize);
- ASSERT_LT(_iter->getApproximateSize(), initialDocSize + 1024);
-
- // Read the field so that it is coppied into the cache. This will make the document bigger but
- // shouldn't affect memory tracking.
- auto iterSizeBeforeAccess = _iter->getApproximateSize();
- docs[0].getDocument()["a"];
- ASSERT_GT(docs[0].getDocument().getCurrentApproximateSize(), initialDocSize);
- ASSERT_EQ(_iter->getApproximateSize(), iterSizeBeforeAccess);
+ ASSERT_GT(_iter->getApproximateSize(), initialDocSize * 2);
+ ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 2 + 1024);
// The accessor will have marked the first document as expired, and thus freed on the next call
// to advance().
advance();
ASSERT_DOCUMENT_EQ(*_iter->current(), docs[1].getDocument());
- ASSERT_GT(_iter->getApproximateSize(), initialDocSize);
- ASSERT_LT(_iter->getApproximateSize(), initialDocSize + 1024);
+ ASSERT_GT(_iter->getApproximateSize(), initialDocSize * 2);
+ ASSERT_LT(_iter->getApproximateSize(), initialDocSize * 2 + 1024);
}
TEST_F(PartitionIteratorTest, ManualPolicy) {