Skip to content

Commit e5331f4

Browse files
committed
fix
1 parent 466f825 commit e5331f4

3 files changed

Lines changed: 59 additions & 3 deletions

File tree

include/paimon/defs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ struct PAIMON_EXPORT Options {
291291
static const char SCAN_TAG_NAME[];
292292
/// "compaction.optimization-interval" - Implying how often to perform an optimization
293293
/// compaction, this configuration is used to ensure the query timeliness of the read-optimized
294-
/// system table.
294+
/// system table. No default value.
295295
static const char COMPACTION_OPTIMIZATION_INTERVAL[];
296296
/// "compaction.total-size-threshold" - When total size is smaller than this threshold, force a
297-
/// full compaction.
297+
/// full compaction. No default value.
298298
static const char COMPACTION_TOTAL_SIZE_THRESHOLD[];
299299
/// "compaction.incremental-size-threshold" - When incremental size is bigger than this
300-
/// threshold, force a full compaction.
300+
/// threshold, force a full compaction. No default value.
301301
static const char COMPACTION_INCREMENTAL_SIZE_THRESHOLD[];
302302
/// "compaction.offpeak.start.hour" - The start of off-peak hours, expressed as an integer
303303
/// between 0 and 23, inclusive. Set to -1 to disable off-peak. Default is -1.

src/paimon/core/mergetree/compact/early_full_compaction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ std::optional<CompactUnit> EarlyFullCompaction::TryFullCompact(
6464
total_size += run.run.TotalSize();
6565
}
6666
if (total_size < total_size_threshold_.value()) {
67+
UpdateLastFullCompaction();
6768
return CompactUnit::FromLevelRuns(max_level, runs);
6869
}
6970
}
@@ -75,6 +76,7 @@ std::optional<CompactUnit> EarlyFullCompaction::TryFullCompact(
7576
}
7677
}
7778
if (incremental_size > incremental_size_threshold_.value()) {
79+
UpdateLastFullCompaction();
7880
return CompactUnit::FromLevelRuns(max_level, runs);
7981
}
8082
}

src/paimon/core/mergetree/compact/early_full_compaction_test.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
&current_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+
&current_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

Comments
 (0)