From 7fc99590302408eddaf8097f679f7f52e53f038a Mon Sep 17 00:00:00 2001 From: Calvin Neo Date: Fri, 24 Apr 2026 17:30:33 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #10813 Signed-off-by: ti-chi-bot --- dbms/src/Storages/KVStore/KVStore.h | 6 ++- .../KVStore/MultiRaft/Persistence.cpp | 44 ++++++++++++++----- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/dbms/src/Storages/KVStore/KVStore.h b/dbms/src/Storages/KVStore/KVStore.h index 6ba908485b4..f8e02688342 100644 --- a/dbms/src/Storages/KVStore/KVStore.h +++ b/dbms/src/Storages/KVStore/KVStore.h @@ -27,6 +27,7 @@ #include #include +#include namespace TiDB { @@ -353,13 +354,14 @@ class KVStore final : private boost::noncopyable TMTContext & tmt, const RegionTaskLock & region_task_lock, UInt64 index, - UInt64 term) const; + UInt64 term, + std::string_view persist_extra_msg) const; void persistRegion( const Region & region, const RegionTaskLock & region_task_lock, PersistRegionReason reason, - const char * extra_msg) const; + std::string_view extra_msg) const; bool tryRegisterEagerRaftLogGCTask(const RegionPtr & region, RegionTaskLock &); diff --git a/dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp b/dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp index b34d863d88e..112411a728c 100644 --- a/dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp +++ b/dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp @@ -32,7 +32,7 @@ void KVStore::persistRegion( const Region & region, const RegionTaskLock & region_task_lock, PersistRegionReason reason, - const char * extra_msg) const + std::string_view extra_msg) const { RUNTIME_CHECK_MSG( region_persister, @@ -40,7 +40,9 @@ void KVStore::persistRegion( StackTrace().toString()); auto reason_id = magic_enum::enum_underlying(reason); - std::string caller = fmt::format("{} {}", PersistRegionReasonMap[reason_id], extra_msg); + std::string caller = fmt::format("{}", PersistRegionReasonMap[reason_id]); + if (!extra_msg.empty()) + caller = fmt::format("{} {}", caller, extra_msg); LOG_INFO( log, "Start to persist {}, cache size: {} bytes for `{}`", @@ -134,13 +136,16 @@ bool KVStore::tryFlushRegionData( // force persist auto & curr_region = *curr_region_ptr; - LOG_DEBUG( - log, - "flush region due to tryFlushRegionData by force, region_id={} term={} index={}", - curr_region.id(), - term, - index); - if (!forceFlushRegionDataImpl(curr_region, try_until_succeed, tmt, region_task_lock, index, term)) + const auto force_persist_msg = fmt::format("by force, term={} index={}", term, index); + LOG_DEBUG(log, "{} flush region due to tryFlushRegionData {}", curr_region.toString(false), force_persist_msg); + if (!forceFlushRegionDataImpl( + curr_region, + try_until_succeed, + tmt, + region_task_lock, + index, + term, + force_persist_msg)) { throw Exception(ErrorCodes::LOGICAL_ERROR, "Force flush region failed, region_id={}", region_id); } @@ -215,19 +220,33 @@ bool KVStore::canFlushRegionDataImpl( if (can_flush && flush_if_possible) { // This rarely happens when there are too may raft logs, which don't trigger a proactive flush. +<<<<<<< HEAD LOG_INFO( log, "{} flush region due to tryFlushRegionData, index {} term {} truncated_index {} truncated_term {}" " gap {}/{}", curr_region.toString(false), +======= + const auto flush_msg = fmt::format( + "index {} term {} truncated_index {} truncated_term {} gap {}/{} table_in_mem_size={} table_id={} " + "keyspace={}", +>>>>>>> 0dc254b776 (KVStore: reduce log (#10813)) index, term, truncated_index, truncated_term, current_applied_gap, +<<<<<<< HEAD gap_threshold); +======= + gap_threshold, + curr_region_ptr->getRegionTableSize(), + curr_region_ptr->getMappedTableID(), + curr_region_ptr->getKeyspaceID()); + LOG_DEBUG(log, "{} flush region due to tryFlushRegionData, {}", curr_region.toString(false), flush_msg); +>>>>>>> 0dc254b776 (KVStore: reduce log (#10813)) GET_METRIC(tiflash_raft_region_flush_bytes, type_flushed).Observe(size_bytes); - return forceFlushRegionDataImpl(curr_region, try_until_succeed, tmt, region_task_lock, index, term); + return forceFlushRegionDataImpl(curr_region, try_until_succeed, tmt, region_task_lock, index, term, flush_msg); } else { @@ -243,7 +262,8 @@ bool KVStore::forceFlushRegionDataImpl( TMTContext & tmt, const RegionTaskLock & region_task_lock, UInt64 index, - UInt64 term) const + UInt64 term, + std::string_view persist_extra_msg) const { Stopwatch watch; if (index) @@ -258,7 +278,7 @@ bool KVStore::forceFlushRegionDataImpl( } // flush cache in storage level is done, persist the region info - persistRegion(curr_region, region_task_lock, PersistRegionReason::Flush, ""); + persistRegion(curr_region, region_task_lock, PersistRegionReason::Flush, persist_extra_msg); // CompactLog will be done in proxy soon, we advance the eager truncate index in TiFlash curr_region.updateRaftLogEagerIndex(index); curr_region.cleanApproxMemCacheInfo(); From 99b9a656cb8095dea2b10ca3948a12ff90279d74 Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Fri, 29 May 2026 14:53:58 +0800 Subject: [PATCH 2/2] try resolve conflict Signed-off-by: JaySon-Huang --- .../Storages/KVStore/MultiRaft/Persistence.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp b/dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp index 112411a728c..d94174f4254 100644 --- a/dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp +++ b/dbms/src/Storages/KVStore/MultiRaft/Persistence.cpp @@ -220,31 +220,18 @@ bool KVStore::canFlushRegionDataImpl( if (can_flush && flush_if_possible) { // This rarely happens when there are too may raft logs, which don't trigger a proactive flush. -<<<<<<< HEAD - LOG_INFO( - log, - "{} flush region due to tryFlushRegionData, index {} term {} truncated_index {} truncated_term {}" - " gap {}/{}", - curr_region.toString(false), -======= const auto flush_msg = fmt::format( - "index {} term {} truncated_index {} truncated_term {} gap {}/{} table_in_mem_size={} table_id={} " + "index {} term {} truncated_index {} truncated_term {} gap {}/{} table_id={} " "keyspace={}", ->>>>>>> 0dc254b776 (KVStore: reduce log (#10813)) index, term, truncated_index, truncated_term, current_applied_gap, -<<<<<<< HEAD - gap_threshold); -======= gap_threshold, - curr_region_ptr->getRegionTableSize(), curr_region_ptr->getMappedTableID(), curr_region_ptr->getKeyspaceID()); LOG_DEBUG(log, "{} flush region due to tryFlushRegionData, {}", curr_region.toString(false), flush_msg); ->>>>>>> 0dc254b776 (KVStore: reduce log (#10813)) GET_METRIC(tiflash_raft_region_flush_bytes, type_flushed).Observe(size_bytes); return forceFlushRegionDataImpl(curr_region, try_until_succeed, tmt, region_task_lock, index, term, flush_msg); } @@ -285,4 +272,4 @@ bool KVStore::forceFlushRegionDataImpl( GET_METRIC(tiflash_raft_apply_write_command_duration_seconds, type_flush_region).Observe(watch.elapsedSeconds()); return true; } -} // namespace DB \ No newline at end of file +} // namespace DB