diff --git a/cdc/log.cc b/cdc/log.cc index da932d7b1a..7739779bd7 100644 --- a/cdc/log.cc +++ b/cdc/log.cc @@ -126,6 +126,28 @@ cdc::stats::stats() { register_counters(counters_failed, "failed"); } +cdc::operation_result_tracker::~operation_result_tracker() { + auto update_stats = [this] (stats::counters& counters) { + if (_details.was_split) { + counters.split_count++; + } else { + counters.unsplit_count++; + } + counters.touches.apply(_details.touched_parts); + if (_details.had_preimage) { + counters.with_preimage_count++; + } + if (_details.had_postimage) { + counters.with_postimage_count++; + } + }; + + update_stats(_stats.counters_total); + if (_failed) { + update_stats(_stats.counters_failed); + } +} + class cdc::cdc_service::impl : service::migration_listener::empty_listener { friend cdc_service; db_context _ctxt; diff --git a/cdc/stats.hh b/cdc/stats.hh index 7edf8e5580..22ed9679d1 100644 --- a/cdc/stats.hh +++ b/cdc/stats.hh @@ -89,4 +89,32 @@ public: stats(); }; +// Contains the details on what happened during a CDC operation. +struct operation_details final { + stats::part_type_set touched_parts; + bool was_split = false; + bool had_preimage = false; + bool had_postimage = false; +}; + +// This object tracks the lifetime of write handlers related to one CDC operation. After all +// write handlers for the operation finish, CDC metrics are updated. +class operation_result_tracker final { + stats& _stats; + operation_details _details; + bool _failed; + +public: + operation_result_tracker(stats& stats, operation_details details) + : _stats(stats) + , _details(details) + , _failed(false) + {} + ~operation_result_tracker(); + + void on_mutation_failed() { + _failed = true; + } +}; + }