streaming: specialize fmt::formatter<stream_reason>

this is a part of a series to migrating from `operator<<(ostream&, ..)`
based formatting to fmtlib based formatting. the goal here is to enable
fmtlib to print `stream_reason` without the help of `operator<<`.

please note, because we still cannot use the generic formatter for
std::unordered_map provided by fmtlib, so in order to drop `operator<<`
for `stream_reason`, and to print `unordered_map<stream_reason>`,
`fmt::join()` is used as a temporary solution. we will audit all
`fmt::join()` calls, after removing the homebrew formatter of
`std::unordered_map`.

the corresponding `operator<<()` are dropped dropped in this change,
as all its callers are now using fmtlib for formatting now.

Refs #13245

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes #13609
This commit is contained in:
Kefu Chai
2023-04-20 18:42:18 +08:00
committed by Botond Dénes
parent ecb5380638
commit 9215adee46
5 changed files with 28 additions and 33 deletions

View File

@@ -969,7 +969,6 @@ scylla_core = (['message/messaging_service.cc',
'streaming/stream_manager.cc',
'streaming/stream_result_future.cc',
'streaming/stream_session_state.cc',
'streaming/stream_reason.cc',
'streaming/consumer.cc',
'clocks-impl.cc',
'partition_slice_builder.cc',

View File

@@ -5016,7 +5016,7 @@ bool storage_service::is_repair_based_node_ops_enabled(streaming::stream_reason
}
}
bool global_enabled = _db.local().get_config().enable_repair_based_node_ops();
slogger.info("enable_repair_based_node_ops={}, allowed_repair_based_node_ops={}", global_enabled, enabled_set);
slogger.info("enable_repair_based_node_ops={}, allowed_repair_based_node_ops={{{}}}", global_enabled, fmt::join(enabled_set, " ,"));
return global_enabled && enabled_set.contains(reason);
}

View File

@@ -7,7 +7,6 @@ target_sources(streaming
stream_coordinator.cc
stream_manager.cc
stream_plan.cc
stream_reason.cc
stream_receive_task.cc
stream_request.cc
stream_result_future.cc

View File

@@ -1,27 +0,0 @@
/*
* Copyright (C) 2020-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "streaming/stream_reason.hh"
#include <ostream>
namespace streaming {
std::ostream& operator<<(std::ostream& out, stream_reason r) {
switch (r) {
case stream_reason::unspecified: out << "unspecified"; break;
case stream_reason::bootstrap: out << "bootstrap"; break;
case stream_reason::decommission: out << "decommission"; break;
case stream_reason::removenode: out << "removenode"; break;
case stream_reason::rebuild: out << "rebuild"; break;
case stream_reason::repair: out << "repair"; break;
case stream_reason::replace: out << "replace"; break;
}
return out;
}
}

View File

@@ -9,7 +9,8 @@
#pragma once
#include <cstdint>
#include <ostream>
#include <string_view>
#include <fmt/format.h>
namespace streaming {
@@ -23,6 +24,29 @@ enum class stream_reason : uint8_t {
replace,
};
std::ostream& operator<<(std::ostream& out, stream_reason r);
}
template <>
struct fmt::formatter<streaming::stream_reason> : fmt::formatter<std::string_view> {
template <typename FormatContext>
auto format(const streaming::stream_reason& r, FormatContext& ctx) const {
using enum streaming::stream_reason;
switch (r) {
case unspecified:
return formatter<std::string_view>::format("unspecified", ctx);
case bootstrap:
return formatter<std::string_view>::format("bootstrap", ctx);
case decommission:
return formatter<std::string_view>::format("decommission", ctx);
case removenode:
return formatter<std::string_view>::format("removenode", ctx);
case rebuild:
return formatter<std::string_view>::format("rebuild", ctx);
case repair:
return formatter<std::string_view>::format("repair", ctx);
case replace:
return formatter<std::string_view>::format("replace", ctx);
}
std::abort();
}
};