in in {fmt} before v10, it provides the specialization of `fmt::formatter<..>`
for `std::string_view` as well as the specialization of `fmt::formatter<..>`
for `fmt::string_view` which is an implementation builtin in {fmt} for
compatibility of pre-C++17. and this type is used even if the code is
compiled with C++ stadandard greater or equal to C++17. also, before v10,
the `fmt::formatter<std::string_view>::format()` is defined so it accepts
`std::string_view`. after v10, `fmt::formatter<std::string_view>` still
exists, but it is now defined using `format_as()` machinery, so it's
`format()` method does not actually accept `std::string_view`, it
accepts `fmt::string_view`, as the former can be converted to
`fmt::string_view`.
this is why we can inherit from `fmt::formatter<std::string_view>` and
use `formatter<std::string_view>::format(foo, ctx);` to implement the
`format()` method with {fmt} v9, but we cannot do this with {fmt} v10,
and we would have following compilation failure:
```
FAILED: service/CMakeFiles/service.dir/RelWithDebInfo/topology_state_machine.cc.o
/home/kefu/.local/bin/clang++ -DFMT_DEPRECATED_OSTREAM -DFMT_SHARED -DSCYLLA_BUILD_MODE=release -DSEASTAR_API_LEVEL=7 -DSEASTAR_LOGGER_COMPILE_TIME_FMT -DSEASTAR_LOGGER_TYPE_STDOUT -DSEASTAR_SCHEDULING_GROUPS_COUNT=16 -DSEASTAR_SSTRING -DXXH_PRIVATE_API -DCMAKE_INTDIR=\"RelWithDebInfo\" -I/home/kefu/dev/scylladb -I/home/kefu/dev/scylladb/build/gen -I/home/kefu/dev/scylladb/seastar/include -I/home/kefu/dev/scylladb/build/seastar/gen/include -I/home/kefu/dev/scylladb/build/seastar/gen/src -ffunction-sections -fdata-sections -O3 -g -gz -std=gnu++20 -fvisibility=hidden -Wall -Werror -Wextra -Wno-error=deprecated-declarations -Wimplicit-fallthrough -Wno-c++11-narrowing -Wno-deprecated-copy -Wno-mismatched-tags -Wno-missing-field-initializers -Wno-overloaded-virtual -Wno-unsupported-friend -Wno-enum-constexpr-conversion -Wno-unused-parameter -ffile-prefix-map=/home/kefu/dev/scylladb=. -march=westmere -mllvm -inline-threshold=2500 -fno-slp-vectorize -U_FORTIFY_SOURCE -Werror=unused-result -MD -MT service/CMakeFiles/service.dir/RelWithDebInfo/topology_state_machine.cc.o -MF service/CMakeFiles/service.dir/RelWithDebInfo/topology_state_machine.cc.o.d -o service/CMakeFiles/service.dir/RelWithDebInfo/topology_state_machine.cc.o -c /home/kefu/dev/scylladb/service/topology_state_machine.cc
/home/kefu/dev/scylladb/service/topology_state_machine.cc:254:41: error: no matching member function for call to 'format'
254 | return formatter<std::string_view>::format(it->second, ctx);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/usr/include/fmt/core.h:2759:22: note: candidate function template not viable: no known conversion from 'seastar::basic_sstring<char, unsigned int, 15>' to 'const fmt::basic_string_view<char>' for 1st argument
2759 | FMT_CONSTEXPR auto format(const T& val, FormatContext& ctx) const
| ^ ~~~~~~~~~~~~
```
because the inherited `format()` method actually comes from
`fmt::formatter<fmt::string_view>`. to reduce the confusion, in this
change, we just inherit from `fmt::format<string_view>`, where
`string_view` is actually `fmt::string_view`. this follows
the document at
https://fmt.dev/latest/api.html#formatting-user-defined-types,
and since there is less indirection under the hood -- we do not
use the specialization created by `FMT_FORMAT_AS` which inherit
from `formatter<fmt::string_view>`, hopefully this can improve
the compilation speed a little bit. also, this change addresses
the build failure with {fmt} v10.
Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
Closes scylladb/scylladb#18299
227 lines
8.4 KiB
C++
227 lines
8.4 KiB
C++
/*
|
|
* Copyright (C) 2020-present ScyllaDB
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
#include <optional>
|
|
#include <variant>
|
|
#include <seastar/core/smp.hh>
|
|
#include <seastar/core/file.hh>
|
|
#include "sstables/types_fwd.hh"
|
|
#include "sstables/sstable_set.hh"
|
|
#include "compaction_fwd.hh"
|
|
#include "mutation_writer/token_group_based_splitting_writer.hh"
|
|
|
|
namespace sstables {
|
|
|
|
enum class compaction_type {
|
|
Compaction = 0,
|
|
Cleanup = 1,
|
|
Validation = 2, // Origin uses this for a compaction that is used exclusively for repair
|
|
Scrub = 3,
|
|
Index_build = 4,
|
|
Reshard = 5,
|
|
Upgrade = 6,
|
|
Reshape = 7,
|
|
Split = 8,
|
|
};
|
|
|
|
struct compaction_completion_desc {
|
|
// Old, existing SSTables that should be deleted and removed from the SSTable set.
|
|
std::vector<shared_sstable> old_sstables;
|
|
// New, fresh SSTables that should be added to SSTable set, replacing the old ones.
|
|
std::vector<shared_sstable> new_sstables;
|
|
// Set of compacted partition ranges that should be invalidated in the cache.
|
|
dht::partition_range_vector ranges_for_cache_invalidation;
|
|
};
|
|
|
|
// creates a new SSTable for a given shard
|
|
using compaction_sstable_creator_fn = std::function<shared_sstable(shard_id shard)>;
|
|
// Replaces old sstable(s) by new one(s) which contain all non-expired data.
|
|
using compaction_sstable_replacer_fn = std::function<void(compaction_completion_desc)>;
|
|
|
|
class compaction_type_options {
|
|
public:
|
|
struct regular {
|
|
};
|
|
struct cleanup {
|
|
};
|
|
struct upgrade {
|
|
};
|
|
struct scrub {
|
|
enum class mode {
|
|
abort, // abort scrub on the first sign of corruption
|
|
skip, // skip corrupt data, including range of rows and/or partitions that are out-of-order
|
|
segregate, // segregate out-of-order data into streams that all contain data with correct order
|
|
validate, // validate data, printing all errors found (sstables are only read, not rewritten)
|
|
};
|
|
mode operation_mode = mode::abort;
|
|
|
|
enum class quarantine_mode {
|
|
include, // scrub all sstables, including quarantined
|
|
exclude, // scrub only non-quarantined sstables
|
|
only, // scrub only quarantined sstables
|
|
};
|
|
quarantine_mode quarantine_operation_mode = quarantine_mode::include;
|
|
|
|
using quarantine_invalid_sstables = bool_class<class quarantine_invalid_sstables_tag>;
|
|
|
|
// Should invalid sstables be moved into quarantine.
|
|
// Only applies to validate-mode.
|
|
quarantine_invalid_sstables quarantine_sstables = quarantine_invalid_sstables::yes;
|
|
};
|
|
struct reshard {
|
|
};
|
|
struct reshape {
|
|
};
|
|
struct split {
|
|
mutation_writer::classify_by_token_group classifier;
|
|
};
|
|
private:
|
|
using options_variant = std::variant<regular, cleanup, upgrade, scrub, reshard, reshape, split>;
|
|
|
|
private:
|
|
options_variant _options;
|
|
|
|
private:
|
|
explicit compaction_type_options(options_variant options) : _options(std::move(options)) {
|
|
}
|
|
|
|
public:
|
|
static compaction_type_options make_reshape() {
|
|
return compaction_type_options(reshape{});
|
|
}
|
|
|
|
static compaction_type_options make_reshard() {
|
|
return compaction_type_options(reshard{});
|
|
}
|
|
|
|
static compaction_type_options make_regular() {
|
|
return compaction_type_options(regular{});
|
|
}
|
|
|
|
static compaction_type_options make_cleanup() {
|
|
return compaction_type_options(cleanup{});
|
|
}
|
|
|
|
static compaction_type_options make_upgrade() {
|
|
return compaction_type_options(upgrade{});
|
|
}
|
|
|
|
static compaction_type_options make_scrub(scrub::mode mode, scrub::quarantine_invalid_sstables quarantine_sstables = scrub::quarantine_invalid_sstables::yes) {
|
|
return compaction_type_options(scrub{.operation_mode = mode, .quarantine_sstables = quarantine_sstables});
|
|
}
|
|
|
|
static compaction_type_options make_split(mutation_writer::classify_by_token_group classifier) {
|
|
return compaction_type_options(split{std::move(classifier)});
|
|
}
|
|
|
|
template <typename... Visitor>
|
|
auto visit(Visitor&&... visitor) const {
|
|
return std::visit(std::forward<Visitor>(visitor)..., _options);
|
|
}
|
|
|
|
template <typename OptionType>
|
|
const auto& as() const {
|
|
return std::get<OptionType>(_options);
|
|
}
|
|
|
|
const options_variant& options() const { return _options; }
|
|
|
|
compaction_type type() const;
|
|
};
|
|
|
|
std::string_view to_string(compaction_type_options::scrub::mode);
|
|
|
|
std::string_view to_string(compaction_type_options::scrub::quarantine_mode);
|
|
|
|
class dummy_tag {};
|
|
using has_only_fully_expired = seastar::bool_class<dummy_tag>;
|
|
|
|
struct compaction_descriptor {
|
|
// List of sstables to be compacted.
|
|
std::vector<sstables::shared_sstable> sstables;
|
|
// This is a snapshot of the table's sstable set, used only for the purpose of expiring tombstones.
|
|
// If this sstable set cannot be provided, expiration will be disabled to prevent data from being resurrected.
|
|
std::optional<sstables::sstable_set> all_sstables_snapshot;
|
|
// Level of sstable(s) created by compaction procedure.
|
|
int level;
|
|
// Threshold size for sstable(s) to be created.
|
|
uint64_t max_sstable_bytes;
|
|
// Can split large partitions at clustering boundary.
|
|
bool can_split_large_partition = false;
|
|
// Run identifier of output sstables.
|
|
sstables::run_id run_identifier;
|
|
// The options passed down to the compaction code.
|
|
// This also selects the kind of compaction to do.
|
|
compaction_type_options options = compaction_type_options::make_regular();
|
|
// If engaged, compaction will cleanup the input sstables by skipping non-owned ranges.
|
|
compaction::owned_ranges_ptr owned_ranges;
|
|
// Required for reshard compaction.
|
|
const dht::sharder* sharder;
|
|
|
|
compaction_sstable_creator_fn creator;
|
|
compaction_sstable_replacer_fn replacer;
|
|
|
|
// Denotes if this compaction task is comprised solely of completely expired SSTables
|
|
sstables::has_only_fully_expired has_only_fully_expired = has_only_fully_expired::no;
|
|
|
|
compaction_descriptor() = default;
|
|
|
|
static constexpr int default_level = 0;
|
|
static constexpr uint64_t default_max_sstable_bytes = std::numeric_limits<uint64_t>::max();
|
|
|
|
explicit compaction_descriptor(std::vector<sstables::shared_sstable> sstables,
|
|
int level = default_level,
|
|
uint64_t max_sstable_bytes = default_max_sstable_bytes,
|
|
run_id run_identifier = run_id::create_random_id(),
|
|
compaction_type_options options = compaction_type_options::make_regular(),
|
|
compaction::owned_ranges_ptr owned_ranges_ = {})
|
|
: sstables(std::move(sstables))
|
|
, level(level)
|
|
, max_sstable_bytes(max_sstable_bytes)
|
|
, run_identifier(run_identifier)
|
|
, options(options)
|
|
, owned_ranges(std::move(owned_ranges_))
|
|
{}
|
|
|
|
explicit compaction_descriptor(sstables::has_only_fully_expired has_only_fully_expired,
|
|
std::vector<sstables::shared_sstable> sstables)
|
|
: sstables(std::move(sstables))
|
|
, level(default_level)
|
|
, max_sstable_bytes(default_max_sstable_bytes)
|
|
, run_identifier(run_id::create_random_id())
|
|
, options(compaction_type_options::make_regular())
|
|
, has_only_fully_expired(has_only_fully_expired)
|
|
{}
|
|
|
|
// Return fan-in of this job, which is equal to its number of runs.
|
|
unsigned fan_in() const;
|
|
// Enables garbage collection for this descriptor, meaning that compaction will be able to purge expired data
|
|
void enable_garbage_collection(sstables::sstable_set snapshot) { all_sstables_snapshot = std::move(snapshot); }
|
|
// Returns total size of all sstables contained in this descriptor
|
|
uint64_t sstables_size() const;
|
|
};
|
|
|
|
}
|
|
|
|
template <>
|
|
struct fmt::formatter<sstables::compaction_type> : fmt::formatter<string_view> {
|
|
auto format(sstables::compaction_type, fmt::format_context& ctx) const -> decltype(ctx.out());
|
|
};
|
|
template <>
|
|
struct fmt::formatter<sstables::compaction_type_options::scrub::mode> : fmt::formatter<string_view> {
|
|
auto format(sstables::compaction_type_options::scrub::mode, fmt::format_context& ctx) const -> decltype(ctx.out());
|
|
};
|
|
template <>
|
|
struct fmt::formatter<sstables::compaction_type_options::scrub::quarantine_mode> : fmt::formatter<string_view> {
|
|
auto format(sstables::compaction_type_options::scrub::quarantine_mode, fmt::format_context& ctx) const -> decltype(ctx.out());
|
|
};
|