diff --git a/db/system_keyspace.cc b/db/system_keyspace.cc index f34ad84617..5bfbc141d9 100644 --- a/db/system_keyspace.cc +++ b/db/system_keyspace.cc @@ -2948,6 +2948,18 @@ std::optional system_keyspace::decode_topology_featu future 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> +system_keyspace::read_cdc_generation_opt(utils::UUID id) { utils::chunked_vector 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)}; diff --git a/db/system_keyspace.hh b/db/system_keyspace.hh index aad5ea5cb5..ea5307ed8e 100644 --- a/db/system_keyspace.hh +++ b/db/system_keyspace.hh @@ -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 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> 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> get_cdc_generations_cleanup_candidate();