test: Fix exit condition of row_cache_test::test_eviction_from_invalidated

The test populates the cache, then invalidates it, then tries to push
huge (10x times the segment size) chunks into seastar memory hoping that
the invalid entries will be evicted. The exit condition on the last
stage is -- total memory of the region (sum of both -- used and free)
becomes less than the size of one chunk.

However, the condition is wrong, because cache usually contains a dummy
entry that's not necessarily on lru and on some test iteration it may
happen that

  evictable size < chunk size < evictable size + dummy size

In this case test fails with bad_alloc being unable to evict the memory
from under the dummy.

fixes: #7959
tests: unit(row_cache_test), unit(the failing case with the triggering
       seed from the issue + 200 times more with random seeds)

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
Message-Id: <20210309134138.28099-1-xemul@scylladb.com>
(cherry picked from commit 096e452db9)
This commit is contained in:
Pavel Emelyanov
2021-03-09 16:41:38 +03:00
committed by Avi Kivity
parent f2af68850c
commit a60f394d9a

View File

@@ -910,8 +910,20 @@ SEASTAR_TEST_CASE(test_eviction_from_invalidated) {
std::vector<sstring> tmp;
auto alloc_size = logalloc::segment_size * 10;
while (tracker.region().occupancy().total_space() > alloc_size) {
tmp.push_back(uninitialized_string(alloc_size));
/*
* Now allocate huge chunks on the region until it gives up
* with bad_alloc. At that point the region must not have more
* memory than the chunk size, neither it must contain rows
* or partitions (except for dummy entries)
*/
try {
while (true) {
tmp.push_back(uninitialized_string(alloc_size));
}
} catch (const std::bad_alloc&) {
BOOST_REQUIRE(tracker.region().occupancy().total_space() < alloc_size);
BOOST_REQUIRE(tracker.get_stats().partitions == 0);
BOOST_REQUIRE(tracker.get_stats().rows == 0);
}
});
}