Large reserves in allocating_section can cause stalls. We already log reserve increase, but we don't know which table it belongs to: lsa - LSA allocation failure, increasing reserve in section 0x600009f94590 to 128 segments; Allocating sections used for updating row cache on memtable flush are notoriously problematic. Each table has its own row_cache, so its own allocating_section(s). If we attached table name to those sections, we could identify which table is causing problems. In some issues we suspected system.raft, but we can't be sure. This patch allows naming allocating_sections for the purpose of identifying them in such log messages. I use abstract_formatter for this purpose to avoid the cost of formatting strings on the hot path (e.g. index_reader). And also to avoid duplicating strings which are already stored elsewhere. Fixes #25799 Closes scylladb/scylladb#27470
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
/*
|
|
* Copyright (C) 2025-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <fmt/format.h>
|
|
#include <functional>
|
|
|
|
/// Type-erased formatter.
|
|
/// Allows passing formattable objects without exposing their types.
|
|
class abstract_formatter {
|
|
std::function<void(fmt::format_context&)> _formatter;
|
|
public:
|
|
abstract_formatter() = default;
|
|
|
|
template<typename Func>
|
|
requires std::is_invocable_v<Func, fmt::format_context&>
|
|
explicit abstract_formatter(Func&& f) : _formatter(std::forward<Func>(f)) {}
|
|
|
|
fmt::format_context::iterator format_to(fmt::format_context& ctx) const {
|
|
if (_formatter) {
|
|
_formatter(ctx);
|
|
}
|
|
return ctx.out();
|
|
}
|
|
|
|
explicit operator bool() const noexcept { return bool(_formatter); }
|
|
};
|
|
|
|
template <> struct fmt::formatter<abstract_formatter> {
|
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
|
|
|
auto format(const abstract_formatter& formatter, fmt::format_context& ctx) const {
|
|
return formatter.format_to(ctx);
|
|
}
|
|
};
|