diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/pipeline/window_function/partition_iterator_test.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
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.cpp | 78 |
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) { |
