diff --git a/tracing/trace_state.cc b/tracing/trace_state.cc index c7285bf5ca..840d7a8c56 100644 --- a/tracing/trace_state.cc +++ b/tracing/trace_state.cc @@ -93,7 +93,7 @@ trace_state::~trace_state() { trace_state_logger.trace("{}: destructing", session_id()); } -void trace_state::stop_foreground_and_write() { +void trace_state::stop_foreground_and_write() noexcept { // Do nothing if state hasn't been initiated if (is_in_state(state::inactive)) { return; diff --git a/tracing/trace_state.hh b/tracing/trace_state.hh index 4c70d0b849..62b87e0297 100644 --- a/tracing/trace_state.hh +++ b/tracing/trace_state.hh @@ -168,7 +168,7 @@ public: * @note The tracing session's "duration" is the time it was in the "foreground" * state. */ - void stop_foreground_and_write(); + void stop_foreground_and_write() noexcept; const utils::UUID& session_id() const { return _records->session_id; @@ -390,14 +390,34 @@ private: */ void build_parameters_map(); + /** + * The actual trace message storing method. + * + * @note This method is allowed to throw. + * @param msg the trace message to store + */ + void trace_internal(sstring msg); + /** * Add a single trace entry - a special case for a simple string. * * @param msg trace message */ - void trace(sstring msg); - void trace(const char* msg) { - trace(sstring(msg)); + void trace(sstring msg) noexcept { + try { + trace_internal(std::move(msg)); + } catch (...) { + // Bump up an error counter and ignore + ++_local_tracing_ptr->stats.trace_errors; + } + } + void trace(const char* msg) noexcept { + try { + trace_internal(sstring(msg)); + } catch (...) { + // Bump up an error counter and ignore + ++_local_tracing_ptr->stats.trace_errors; + } } /** @@ -416,13 +436,13 @@ private: * @param a positional parameters */ template - void trace(const char* fmt, A&&... a); + void trace(const char* fmt, A&&... a) noexcept; template friend void begin(const trace_state_ptr& p, A&&... a); template - friend void trace(const trace_state_ptr& p, A&&... a); + friend void trace(const trace_state_ptr& p, A&&... a) noexcept; friend void set_page_size(const trace_state_ptr& p, int32_t val); friend void set_batchlog_endpoints(const trace_state_ptr& p, const std::unordered_set& val); @@ -434,7 +454,7 @@ private: friend void add_table_name(const trace_state_ptr& p, const sstring& ks_name, const sstring& cf_name); }; -inline void trace_state::trace(sstring message) { +inline void trace_state::trace_internal(sstring message) { if (is_in_state(state::inactive)) { throw std::logic_error("trying to use a trace() before begin() for \"" + message + "\" tracepoint"); } @@ -480,9 +500,9 @@ inline void trace_state::trace(sstring message) { } template -void trace_state::trace(const char* fmt, A&&... a) { +void trace_state::trace(const char* fmt, A&&... a) noexcept { try { - trace(seastar::format(fmt, std::forward(a)...)); + trace_internal(seastar::format(fmt, std::forward(a)...)); } catch (...) { // Bump up an error counter and ignore ++_local_tracing_ptr->stats.trace_errors; @@ -589,7 +609,7 @@ inline void begin(const trace_state_ptr& p, A&&... a) { * @param a trace message format string with optional parameters */ template -inline void trace(const trace_state_ptr& p, A&&... a) { +inline void trace(const trace_state_ptr& p, A&&... a) noexcept { if (p) { p->trace(std::forward(a)...); } @@ -610,7 +630,7 @@ inline std::experimental::optional make_trace_info(const trace_state return std::experimental::nullopt; } -inline void stop_foreground(const trace_state_ptr& state) { +inline void stop_foreground(const trace_state_ptr& state) noexcept { if (state) { state->stop_foreground_and_write(); } diff --git a/tracing/tracing.cc b/tracing/tracing.cc index 27d566d9f1..5dc283a7c6 100644 --- a/tracing/tracing.cc +++ b/tracing/tracing.cc @@ -107,7 +107,7 @@ future<> tracing::start_tracing() { }); } -trace_state_ptr tracing::create_session(trace_type type, trace_state_props_set props) { +trace_state_ptr tracing::create_session(trace_type type, trace_state_props_set props) noexcept { if (!started()) { return nullptr; } @@ -126,7 +126,7 @@ trace_state_ptr tracing::create_session(trace_type type, trace_state_props_set p } } -trace_state_ptr tracing::create_session(const trace_info& secondary_session_info) { +trace_state_ptr tracing::create_session(const trace_info& secondary_session_info) noexcept { if (!started()) { return nullptr; } diff --git a/tracing/tracing.hh b/tracing/tracing.hh index 48a5d11f39..23713a5f5d 100644 --- a/tracing/tracing.hh +++ b/tracing/tracing.hh @@ -470,7 +470,7 @@ public: * * @return tracing state handle */ - trace_state_ptr create_session(trace_type type, trace_state_props_set props); + trace_state_ptr create_session(trace_type type, trace_state_props_set props) noexcept; /** * Create a new secondary tracing session. @@ -479,7 +479,7 @@ public: * * @return tracing state handle */ - trace_state_ptr create_session(const trace_info& secondary_session_info); + trace_state_ptr create_session(const trace_info& secondary_session_info) noexcept; void write_maybe() { if (_pending_for_write_records_count >= write_event_records_threshold || _pending_for_write_records_bulk.size() >= write_event_sessions_threshold) {