From 373659fb5f88e5aac828428716d9326d2a6bfdd1 Mon Sep 17 00:00:00 2001 From: Yukang-Lian Date: Fri, 5 Jun 2026 12:28:58 +0800 Subject: [PATCH] [fix](be) Fix binlog compaction success log ### What problem does this PR solve? Issue Number: None Related PR: #63643 Problem Summary: Binlog compaction can be submitted by the automatic binlog compaction producer without initializing the tablet cumulative compaction policy. The shared compaction success log unconditionally read tablet()->cumulative_compaction_policy() after modify_rowsets(), so a successful binlog compaction could hit the DCHECK and abort even though binlog compaction uses BinlogCompactionPolicy to update the output compaction level. This change keeps the cumulative policy assertion for non-binlog compactions and logs the binlog compaction level for binlog compaction instead. ### Release note Fix a BE crash that could happen after successful automatic row binlog compaction. ### Check List (For Author) - Test: Manual test - build-support/check-format.sh - ./build.sh --be --fe - Manual automatic binlog compaction validation on a local cluster - build-support/run-clang-tidy.sh --build-dir be/build_ASAN attempted but failed on existing/toolchain diagnostics - Behavior changed: No - Does this need documentation: No --- be/src/storage/compaction/compaction.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/be/src/storage/compaction/compaction.cpp b/be/src/storage/compaction/compaction.cpp index ff87dbd676400b..62f35d92018758 100644 --- a/be/src/storage/compaction/compaction.cpp +++ b/be/src/storage/compaction/compaction.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "cloud/cloud_meta_mgr.h" @@ -756,8 +757,14 @@ Status CompactionMixin::execute_compact_impl(int64_t permits) { RETURN_IF_ERROR(modify_rowsets()); - auto* cumu_policy = tablet()->cumulative_compaction_policy(); - DCHECK(cumu_policy); + auto compaction_policy_info = [this]() -> std::string { + if (compaction_type() == ReaderType::READER_BINLOG_COMPACTION) { + return fmt::format("binlog_compaction_level={}", static_cast(compaction_level())); + } + auto* cumu_policy = tablet()->cumulative_compaction_policy(); + DCHECK(cumu_policy); + return fmt::format("cumulative_compaction_policy={}", cumu_policy->name()); + }(); LOG(INFO) << "succeed to do " << compaction_name() << " is_vertical=" << _is_vertical << ". tablet=" << _tablet->tablet_id() << ", output_version=" << _output_version << ", current_max_version=" << tablet()->max_version().second @@ -778,8 +785,7 @@ Status CompactionMixin::execute_compact_impl(int64_t permits) { << ", output_row_num=" << _output_rowset->num_rows() << ", filtered_row_num=" << _stats.filtered_rows << ", merged_row_num=" << _stats.merged_rows - << ". elapsed time=" << watch.get_elapse_second() - << "s. cumulative_compaction_policy=" << cumu_policy->name() + << ". elapsed time=" << watch.get_elapse_second() << "s. " << compaction_policy_info << ", compact_row_per_second=" << cast_set(_input_row_num) / watch.get_elapse_second();