@@ -208,4 +208,58 @@ TEST_F(EarlyFullCompactionTest, TestThresholdTriggersWhenIntervalFails) {
208208 ASSERT_FALSE (early_full_compaction.TryFullCompact (/* num_levels=*/ 5 , runs));
209209}
210210
211+ TEST_F (EarlyFullCompactionTest, TestUpdateLastWhenFullCompactIsTriggeredByTotalSize) {
212+ int64_t current_time = 10000l ;
213+
214+ TestableEarlyFullCompaction early_full_compaction (/* full_compaction_interval=*/ 1000l ,
215+ /* total_size_threshold=*/ 500l ,
216+ /* incremental_size_threshold=*/ std::nullopt ,
217+ ¤t_time);
218+ // First time, interval should trigger even if size (600) > threshold (500)
219+ auto runs = CreateRuns ({300l , 300l });
220+ auto compact_unit = early_full_compaction.TryFullCompact (/* num_levels=*/ 5 , runs);
221+ ASSERT_TRUE (compact_unit);
222+ ASSERT_EQ (compact_unit->output_level , 4 );
223+
224+ current_time = 10100l ;
225+ // Second time, compaction triggered by total_size_threshold
226+ runs = CreateRuns ({300l , 100l });
227+ compact_unit = early_full_compaction.TryFullCompact (/* num_levels=*/ 5 , runs);
228+ ASSERT_TRUE (compact_unit);
229+ ASSERT_EQ (compact_unit->output_level , 4 );
230+
231+ current_time = 11001l ;
232+ // Third time, compaction cannot be triggered as 11001 - 10100 < 1000 full_compaction_interval
233+ runs = CreateRuns ({300l , 300l });
234+ compact_unit = early_full_compaction.TryFullCompact (/* num_levels=*/ 5 , runs);
235+ ASSERT_FALSE (compact_unit);
236+ }
237+
238+ TEST_F (EarlyFullCompactionTest, TestUpdateLastWhenFullCompactIsTriggeredByIncSize) {
239+ int64_t current_time = 10000l ;
240+
241+ TestableEarlyFullCompaction early_full_compaction (/* full_compaction_interval=*/ 1000l ,
242+ /* total_size_threshold=*/ std::nullopt ,
243+ /* incremental_size_threshold=*/ 500 ,
244+ ¤t_time);
245+ // First time, interval should trigger even if size (400) < threshold (500)
246+ std::vector<LevelSortedRun> runs = {CreateLevelSortedRun (0 , 300 ), CreateLevelSortedRun (0 , 100 )};
247+ auto compact_unit = early_full_compaction.TryFullCompact (/* num_levels=*/ 5 , runs);
248+ ASSERT_TRUE (compact_unit);
249+ ASSERT_EQ (compact_unit->output_level , 4 );
250+
251+ current_time = 10100l ;
252+ // Second time, compaction triggered by total_size_threshold
253+ runs = {CreateLevelSortedRun (0 , 300 ), CreateLevelSortedRun (0 , 300 )};
254+ compact_unit = early_full_compaction.TryFullCompact (/* num_levels=*/ 5 , runs);
255+ ASSERT_TRUE (compact_unit);
256+ ASSERT_EQ (compact_unit->output_level , 4 );
257+
258+ current_time = 11001l ;
259+ // Third time, compaction cannot be triggered as 11001 - 10100 < 1000 full_compaction_interval
260+ runs = {CreateLevelSortedRun (0 , 300 ), CreateLevelSortedRun (0 , 100 )};
261+ compact_unit = early_full_compaction.TryFullCompact (/* num_levels=*/ 5 , runs);
262+ ASSERT_FALSE (compact_unit);
263+ }
264+
211265} // namespace paimon::test
0 commit comments