@@ -322,6 +322,41 @@ TEST_F(PureDiskTSTest, BackgroundOffloading) {
322322 EXPECT_EQ (metrics.tiered_stats .allocated_bytes , kNum * 4096 );
323323}
324324
325+ // Verify correctness of our offloading startegy, offloading values only after second access.
326+ TEST_F (PureDiskTSTest, OffloadingStrategy) {
327+ // Create value and wait to be offlaoded
328+ string value = BuildString (3000 );
329+ Run ({" set" , " key" , value});
330+ ExpectConditionWithinTimeout ([&] { return GetMetrics ().db_stats [0 ].tiered_entries == 1 ; });
331+
332+ // Check base values
333+ auto metrics = GetMetrics ();
334+ EXPECT_EQ (metrics.tiered_stats .total_fetches , 0 );
335+ EXPECT_EQ (metrics.tiered_stats .total_uploads , 0 );
336+ EXPECT_EQ (metrics.tiered_stats .total_stashes , 1 );
337+
338+ // Repeat a few times
339+ for (size_t i = 1 ; i <= 3 ; i++) {
340+ // Value is not uploaded after first read
341+ Run ({" get" , " key" });
342+ metrics = GetMetrics ();
343+ EXPECT_EQ (metrics.tiered_stats .total_fetches , 2 * i - 1 );
344+ EXPECT_EQ (metrics.tiered_stats .total_uploads , i - 1 );
345+
346+ // But on second read upload should happend at the end of chain due to two touches
347+ Run ({" get" , " key" });
348+ ExpectConditionWithinTimeout ([&] { return GetMetrics ().tiered_stats .total_uploads == i; });
349+ metrics = GetMetrics ();
350+ EXPECT_EQ (metrics.tiered_stats .total_fetches , 2 * i);
351+
352+ // Wait for offloading again
353+ ExpectConditionWithinTimeout ([&] { return GetMetrics ().db_stats [0 ].tiered_entries == 1 ; });
354+ metrics = GetMetrics ();
355+ EXPECT_EQ (metrics.tiered_stats .total_offloading_stashes , i);
356+ EXPECT_EQ (metrics.tiered_stats .total_stashes , i + 1 );
357+ }
358+ }
359+
325360// Test FLUSHALL while reading entries
326361TEST_F (PureDiskTSTest, FlushAll) {
327362 const int kNum = 500 ;
0 commit comments