Skip to content

Commit

Permalink
feat cache: separate successful update and no changes
Browse files Browse the repository at this point in the history
Relates: <HIDDEN_URL>
commit_hash:a0bfafe1a9aaf8e80640c519ab698a8e53e1b699
  • Loading branch information
pinbraerts committed Nov 8, 2024
1 parent c34ab2f commit d840e87
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/include/userver/cache/cache_statistics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions core/src/cache/cache_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<std::chrono::milliseconds>(update_stop_time - update_start_time_);
Expand Down
3 changes: 3 additions & 0 deletions core/src/cache/cache_update_trait_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit d840e87

Please sign in to comment.