@@ -1504,6 +1504,65 @@ TEST_P(AsyncDataCacheTest, ssdWriteOptions) {
15041504 }
15051505}
15061506
1507+ TEST_P (AsyncDataCacheTest, ssdFlushThresholdBytes) {
1508+ constexpr uint64_t kRamBytes = 16UL << 20 ; // 16 MB
1509+ constexpr uint64_t kSsdBytes = 64UL << 20 ; // 64 MB
1510+
1511+ struct {
1512+ double maxWriteRatio;
1513+ double ssdSavableRatio;
1514+ int32_t minSsdSavableBytes;
1515+ uint64_t ssdFlushThresholdBytes;
1516+ bool expectedSaveToSsd;
1517+
1518+ std::string debugString () const {
1519+ return fmt::format (
1520+ " maxWriteRatio {}, ssdSavableRatio {}, minSsdSavableBytes {}, ssdFlushThresholdBytes {}, expectedSaveToSsd {}" ,
1521+ maxWriteRatio,
1522+ ssdSavableRatio,
1523+ minSsdSavableBytes,
1524+ ssdFlushThresholdBytes,
1525+ expectedSaveToSsd);
1526+ }
1527+ } testSettings[] = {
1528+ // Ratio-based threshold not met, ssdFlushThresholdBytes disabled (0).
1529+ // No flush expected.
1530+ {0.8 , 0.95 , 32 << 20 , 0 , false },
1531+ // Ratio-based threshold not met, but ssdFlushThresholdBytes is small
1532+ // (1MB).
1533+ // Flush expected due to absolute threshold.
1534+ {0.8 , 0.95 , 32 << 20 , 1UL << 20 , true },
1535+ // Ratio-based threshold met. ssdFlushThresholdBytes disabled.
1536+ // Flush expected due to ratio.
1537+ {0.8 , 0.3 , 4 << 20 , 0 , true },
1538+ // Both thresholds could trigger. Flush expected.
1539+ {0.8 , 0.3 , 4 << 20 , 1UL << 20 , true }};
1540+
1541+ for (const auto & testData : testSettings) {
1542+ SCOPED_TRACE (testData.debugString ());
1543+ initializeCache (
1544+ kRamBytes ,
1545+ kSsdBytes ,
1546+ 0 ,
1547+ true ,
1548+ AsyncDataCache::Options (
1549+ testData.maxWriteRatio ,
1550+ testData.ssdSavableRatio ,
1551+ testData.minSsdSavableBytes ,
1552+ AsyncDataCache::kDefaultNumShards ,
1553+ testData.ssdFlushThresholdBytes ));
1554+ // Load data half of the in-memory capacity.
1555+ loadLoop (0 , kRamBytes / 2 );
1556+ waitForPendingLoads ();
1557+ auto stats = cache_->refreshStats ();
1558+ if (testData.expectedSaveToSsd ) {
1559+ EXPECT_GT (stats.ssdStats ->entriesWritten , 0 );
1560+ } else {
1561+ EXPECT_EQ (stats.ssdStats ->entriesWritten , 0 );
1562+ }
1563+ }
1564+ }
1565+
15071566TEST_P (AsyncDataCacheTest, appendSsdSaveable) {
15081567 constexpr uint64_t kRamBytes = 64UL << 20 ; // 64 MB
15091568 constexpr uint64_t kSsdBytes = 128UL << 20 ; // 128 MB
0 commit comments