From d840e87dffb2bc2eaf3e24ec90566ac507eef36e Mon Sep 17 00:00:00 2001 From: pinbraerts Date: Fri, 8 Nov 2024 13:32:29 +0300 Subject: [PATCH] feat cache: separate successful update and no changes Relates: commit_hash:a0bfafe1a9aaf8e80640c519ab698a8e53e1b699 --- core/include/userver/cache/cache_statistics.hpp | 2 +- core/src/cache/cache_statistics.cpp | 11 ++++++++--- core/src/cache/cache_update_trait_impl.cpp | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/include/userver/cache/cache_statistics.hpp b/core/include/userver/cache/cache_statistics.hpp index 84d2aee94f6e..90b82385c118 100644 --- a/core/include/userver/cache/cache_statistics.hpp +++ b/core/include/userver/cache/cache_statistics.hpp @@ -41,7 +41,7 @@ struct Statistics final { void DumpMetric(utils::statistics::Writer& writer, const Statistics& stats); -enum class UpdateState { kNotFinished, kSuccess, kFailure }; +enum class UpdateState { kNotFinished, kSuccess, kNoChanges, kFailure }; } // namespace impl diff --git a/core/src/cache/cache_statistics.cpp b/core/src/cache/cache_statistics.cpp index cdb07d0017c2..efccc2ed2f39 100644 --- a/core/src/cache/cache_statistics.cpp +++ b/core/src/cache/cache_statistics.cpp @@ -113,7 +113,7 @@ void UpdateStatisticsScope::Finish(std::size_t total_documents_count) { void UpdateStatisticsScope::FinishNoChanges() { ++update_stats_.update_no_changes_count; - DoFinish(impl::UpdateState::kSuccess); + DoFinish(impl::UpdateState::kNoChanges); } void UpdateStatisticsScope::FinishWithError() { @@ -136,8 +136,13 @@ void UpdateStatisticsScope::DoFinish(impl::UpdateState new_state) { if (state_ != impl::UpdateState::kNotFinished) return; const auto update_stop_time = utils::datetime::SteadyNow(); - if (new_state == impl::UpdateState::kSuccess) { - update_stats_.last_successful_update_start_time = update_start_time_; + switch (new_state) { + case impl::UpdateState::kSuccess: + case impl::UpdateState::kNoChanges: + update_stats_.last_successful_update_start_time = update_start_time_; + break; + default: + break; } update_stats_.last_update_duration = std::chrono::duration_cast(update_stop_time - update_start_time_); diff --git a/core/src/cache/cache_update_trait_impl.cpp b/core/src/cache/cache_update_trait_impl.cpp index 770a84e74861..5563e6229c99 100644 --- a/core/src/cache/cache_update_trait_impl.cpp +++ b/core/src/cache/cache_update_trait_impl.cpp @@ -446,6 +446,9 @@ void CacheUpdateTrait::Impl::CheckUpdateState(impl::UpdateState update_state, st case impl::UpdateState::kSuccess: LOG_INFO() << "Updated cache update_type=" << update_type_str << " name=" << name_; break; + case impl::UpdateState::kNoChanges: + LOG_INFO() << "No changes for cache update_type=" << update_type_str << " name=" << name_; + break; case impl::UpdateState::kFailure: throw std::runtime_error("FinishWithError"); }