system_keyspace: add read_cdc_generation_opt

The `system_keyspace::read_cdc_generation` loads a cdc generation from
the system tables. One of its preconditions is that the generation
exists - this precondition is quite easy to satisfy in raft mode, and
the function was designed to be used solely in that mode.

In legacy mode however, in case when we revert from raft mode through
recovery, it might be necessary to use generations created in raft mode
for some time. In order to make the function useful as a fallback in
case lookup of a generation in legacy mode fails, introduce a relaxed
variant of `read_cdc_generation` which returns std::nullopt if the
generation does not exist.
This commit is contained in:
Piotr Dulikowski
2024-02-05 12:28:04 +01:00
parent 77a8f5e3d6
commit fb02453686
2 changed files with 20 additions and 3 deletions

View File

@@ -2948,6 +2948,18 @@ std::optional<service::topology_features> system_keyspace::decode_topology_featu
future<cdc::topology_description>
system_keyspace::read_cdc_generation(utils::UUID id) {
auto gen_desc = co_await read_cdc_generation_opt(id);
if (!gen_desc) {
on_internal_error(slogger, format(
"read_cdc_generation: data for CDC generation {} not present", id));
}
co_return std::move(*gen_desc);
}
future<std::optional<cdc::topology_description>>
system_keyspace::read_cdc_generation_opt(utils::UUID id) {
utils::chunked_vector<cdc::token_range_description> entries;
co_await _qp.query_internal(
format("SELECT range_end, streams, ignore_msb FROM {}.{} WHERE key = '{}' AND id = ?",
@@ -2966,9 +2978,7 @@ system_keyspace::read_cdc_generation(utils::UUID id) {
});
if (entries.empty()) {
// The data must be present by precondition.
on_internal_error(slogger, format(
"read_cdc_generation: data for CDC generation {} not present", id));
co_return std::nullopt;
}
co_return cdc::topology_description{std::move(entries)};

View File

@@ -529,6 +529,13 @@ public:
// Precondition: the data is known to be present in the table (because it was committed earlier through group 0).
future<cdc::topology_description> read_cdc_generation(utils::UUID id);
// Read CDC generation data with the given UUID as key.
// Unlike `read_cdc_generation`, does not require the data to be present.
// This method is meant to be used after switching back to legacy mode due to raft recovery,
// as the node will need to fetch definition of a CDC generation that was
// previously created in raft topology mode.
future<std::optional<cdc::topology_description>> read_cdc_generation_opt(utils::UUID id);
// Loads the current clean-up candidate for the CDC generation data. If there is no candidate, returns std::nullopt.
future<std::optional<cdc::generation_id_v2>> get_cdc_generations_cleanup_candidate();