diff options
author | Arun Banala <arun.banala@mongodb.com> | 2021-03-08 11:57:49 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-11 21:41:57 +0000 |
commit | abf0352882f93e760537d612401eb9fb6e5a030e (patch) | |
tree | e6cba7b8fe599cb1772da229917c0bacdd68f91b /src/mongo/db/pipeline/lookup_set_cache_test.cpp | |
parent | 558bef726dc857223d672e552601668f3d6f4cd3 (diff) | |
download | mongo-abf0352882f93e760537d612401eb9fb6e5a030e.tar.gz |
SERVER-54296 Fix incorrect cache size estimate logic in lookup_set_cache.h
Diffstat (limited to 'src/mongo/db/pipeline/lookup_set_cache_test.cpp')
-rw-r--r-- | src/mongo/db/pipeline/lookup_set_cache_test.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/lookup_set_cache_test.cpp b/src/mongo/db/pipeline/lookup_set_cache_test.cpp index c0a2479e01a..6670b5b5971 100644 --- a/src/mongo/db/pipeline/lookup_set_cache_test.cpp +++ b/src/mongo/db/pipeline/lookup_set_cache_test.cpp @@ -207,4 +207,39 @@ TEST(LookupSetCacheTest, CachedValuesDontRespectCollation) { ASSERT_EQ(2U, fooResult->size()); } +TEST(LookupSetCacheTest, DocumentWithStorageCachePopulated) { + LookupSetCache cache(defaultComparator); + + // Use a BSONObj backed Document so that the Document's hot storage isn't populated at + // initialization. + BSONObj input = BSON("a" << 1); + const auto doc1 = Document(input); + const auto sizeOfDoc1Before = doc1.getApproximateSize(); + auto key = Value("foo"_sd); + + // Insert a cache entry and verify that both the key and the document are accounted for in the + // cache size. + cache.insert(key, doc1); + ASSERT_EQ(cache.getMemoryUsage(), sizeOfDoc1Before + key.getApproximateSize()); + + + // A second document with the same key should require additional memory usage to store the + // document, but not the key. + auto prevCacheSize = cache.getMemoryUsage(); + const auto doc2 = Document({{"a", 2}}); + cache.insert(key, doc2); + ASSERT_EQ(cache.getMemoryUsage(), prevCacheSize + doc2.getApproximateSize()); + + // Calling serializeForSorter() should grow the overall document size. Verify that growing the + // size of the 'Document' object does not have impact on the size stored in 'cache'. + prevCacheSize = cache.getMemoryUsage(); + BufBuilder builder; + doc1.serializeForSorter(builder); + ASSERT_LT(sizeOfDoc1Before, doc1.getApproximateSize()); + ASSERT_EQ(prevCacheSize, cache.getMemoryUsage()); + + cache.evictOne(); + ASSERT_EQ(cache.getMemoryUsage(), 0); +} + } // namespace mongo |