From 1b92cbeabeb53004b098498842167e3140071078 Mon Sep 17 00:00:00 2001 From: Piotr Dulikowski Date: Wed, 18 Mar 2020 18:58:20 +0100 Subject: [PATCH] cdc: add an object for tracking progress of cdc mutations CDC metrics, apart from tracking "total" metrics for all performed CDC operations, also track metrics for "failed" operations. Because the result of the CDC operation depends on whether all CDC mutations were written successfully by storage_proxy, checking for failure and incrementing appropriate counters is deferred after all write response handlers finish. The `cdc::operation_result_tracker` object was created for that purpose. It contains all the details needed to accurately update the metrics based on what actually happened in the `augment_mutation_call` function, and holds a flag which tells if any of write response handlers failed. This object is supposed to be referenced by write response handlers for CDC mutations created after the same `augment_mutation_call`. After all write response handlers are destroyed, the destructor of `operation_result_tracker` will update appropriate metrics. Actual creating and attaching this object to write response handlers will be done in subsequent commits. --- cdc/log.cc | 22 ++++++++++++++++++++++ cdc/stats.hh | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) 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; + } +}; + }