mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-22 07:42:16 +00:00
Add keyspace_rf_change_plan to migration_plan.
The keyspace_rf_change_plan consists of:
- completion - info about the request for which all migrations are done. Only one
request can be completed at the time, even if more have finished migrations
(the rest will be completed later). Based on it:
- next_replication is cleared;
- new keyspace properties are saved (only if succeeded);
- request is removed from ongoing_rf_changes;
- the request is marked as done in system.topology_requests.
- aborts - info about requests that cannot complete because the required
rf change is impossible (e.g. no available nodes in a required rack).
Multiple requests can be aborted in a single plan. Based on each:
- next_replication is set to current_replication (rolling back);
- the request is marked as aborted with an error in system.topology_requests.
The scheduled rebuilds will be kept in migration_plan::_migrations.
Based on that the canonical_mutations are generated.
Add update_topology_state_with_mixed_change and use it if any schema
changes are required, i.e. if plan contains keyspace_rf_change_plan::completion.
176 lines
7.2 KiB
C++
176 lines
7.2 KiB
C++
/*
|
|
* Copyright (C) 2024-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.1
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <concepts>
|
|
#include <cstdint>
|
|
#include <set>
|
|
#include <unordered_set>
|
|
|
|
#include <seastar/core/sstring.hh>
|
|
|
|
#include "dht/token.hh"
|
|
#include "mutation/canonical_mutation.hh"
|
|
#include "mutation/mutation.hh"
|
|
#include "schema/schema.hh"
|
|
#include "service/topology_state_machine.hh"
|
|
#include "mutation/timestamp.hh"
|
|
#include "utils/UUID.hh"
|
|
|
|
namespace service {
|
|
|
|
template<typename Builder>
|
|
class topology_mutation_builder_base {
|
|
private:
|
|
Builder& self() {
|
|
return *static_cast<Builder*>(this);
|
|
}
|
|
|
|
protected:
|
|
enum class collection_apply_mode {
|
|
overwrite,
|
|
update,
|
|
};
|
|
|
|
using builder_base = topology_mutation_builder_base<Builder>;
|
|
|
|
Builder& apply_atomic(const char* cell, const data_value& value);
|
|
template<std::ranges::range C>
|
|
requires std::convertible_to<std::ranges::range_value_t<C>, data_value>
|
|
Builder& apply_set(const char* cell, collection_apply_mode apply_mode, const C& c);
|
|
Builder& set(const char* cell, node_state value);
|
|
Builder& set(const char* cell, topology_request value);
|
|
Builder& set(const char* cell, global_topology_request value);
|
|
Builder& set(const char* cell, const sstring& value);
|
|
Builder& set(const char* cell, const raft::server_id& value);
|
|
Builder& set(const char* cell, const uint32_t& value);
|
|
Builder& set(const char* cell, cleanup_status value);
|
|
Builder& set(const char* cell, intended_storage_mode value);
|
|
Builder& set(const char* cell, const utils::UUID& value);
|
|
Builder& set(const char* cell, bool value);
|
|
Builder& set(const char* cell, const char* value);
|
|
Builder& set(const char* cell, const db_clock::time_point& value);
|
|
|
|
Builder& del(const char* cell);
|
|
};
|
|
|
|
class topology_mutation_builder;
|
|
|
|
class topology_node_mutation_builder
|
|
: public topology_mutation_builder_base<topology_node_mutation_builder> {
|
|
|
|
friend builder_base;
|
|
|
|
topology_mutation_builder& _builder;
|
|
deletable_row& _r;
|
|
|
|
private:
|
|
row& row();
|
|
api::timestamp_type timestamp() const;
|
|
const schema& schema() const;
|
|
ttl_opt ttl() const { return std::nullopt; }
|
|
|
|
public:
|
|
topology_node_mutation_builder(topology_mutation_builder&, raft::server_id);
|
|
|
|
using builder_base::set;
|
|
using builder_base::del;
|
|
topology_node_mutation_builder& set(const char* cell, const std::unordered_set<raft::server_id>& nodes_ids);
|
|
topology_node_mutation_builder& set(const char* cell, const std::unordered_set<dht::token>& value);
|
|
topology_node_mutation_builder& set(const char* cell, const std::set<sstring>& value);
|
|
|
|
canonical_mutation build();
|
|
};
|
|
|
|
class topology_mutation_builder
|
|
: public topology_mutation_builder_base<topology_mutation_builder> {
|
|
|
|
friend builder_base;
|
|
friend class topology_node_mutation_builder;
|
|
|
|
schema_ptr _s;
|
|
mutation _m;
|
|
api::timestamp_type _ts;
|
|
|
|
std::optional<topology_node_mutation_builder> _node_builder;
|
|
|
|
private:
|
|
row& row();
|
|
api::timestamp_type timestamp() const;
|
|
const schema& schema() const;
|
|
ttl_opt ttl() const { return std::nullopt; }
|
|
|
|
public:
|
|
topology_mutation_builder(api::timestamp_type ts);
|
|
topology_mutation_builder& set_transition_state(topology::transition_state);
|
|
topology_mutation_builder& set_version(topology::version_t);
|
|
topology_mutation_builder& set_fence_version(topology::version_t);
|
|
topology_mutation_builder& set_session(session_id);
|
|
topology_mutation_builder& set_tablet_balancing_enabled(bool);
|
|
topology_mutation_builder& set_new_cdc_generation_data_uuid(const utils::UUID& value);
|
|
topology_mutation_builder& set_committed_cdc_generations(const std::vector<cdc::generation_id>& values);
|
|
topology_mutation_builder& set_new_keyspace_rf_change_data(const sstring &ks_name, const std::map<sstring, sstring> &rf_per_dc);
|
|
topology_mutation_builder& set_unpublished_cdc_generations(const std::vector<cdc::generation_id>& values);
|
|
topology_mutation_builder& set_global_topology_request(global_topology_request);
|
|
topology_mutation_builder& set_global_topology_request_id(const utils::UUID&);
|
|
topology_mutation_builder& set_upgrade_state_done();
|
|
topology_mutation_builder& add_enabled_features(const std::set<sstring>& value);
|
|
topology_mutation_builder& add_ignored_nodes(const std::unordered_set<raft::server_id>& value);
|
|
topology_mutation_builder& set_ignored_nodes(const std::unordered_set<raft::server_id>& value);
|
|
topology_mutation_builder& add_new_committed_cdc_generation(const cdc::generation_id& value);
|
|
topology_mutation_builder& del_transition_state();
|
|
topology_mutation_builder& del_session();
|
|
topology_mutation_builder& del_global_topology_request();
|
|
topology_mutation_builder& del_global_topology_request_id();
|
|
topology_mutation_builder& queue_global_topology_request_id(const utils::UUID& value);
|
|
topology_mutation_builder& drop_first_global_topology_request_id(const std::vector<utils::UUID>&, const utils::UUID&);
|
|
topology_mutation_builder& pause_rf_change_request(const utils::UUID&);
|
|
topology_mutation_builder& resume_rf_change_request(const std::unordered_set<utils::UUID>&, const utils::UUID&);
|
|
topology_mutation_builder& start_rf_change_migrations(const utils::UUID&);
|
|
topology_mutation_builder& finish_rf_change_migrations(const std::unordered_set<utils::UUID>&, const utils::UUID&);
|
|
topology_node_mutation_builder& with_node(raft::server_id);
|
|
canonical_mutation build() { return canonical_mutation{std::move(_m)}; }
|
|
};
|
|
|
|
class topology_request_tracking_mutation_builder :
|
|
public topology_mutation_builder_base<topology_request_tracking_mutation_builder> {
|
|
|
|
schema_ptr _s;
|
|
mutation _m;
|
|
api::timestamp_type _ts;
|
|
deletable_row& _r;
|
|
bool _set_type;
|
|
|
|
public:
|
|
row& row();
|
|
const schema& schema() const;
|
|
api::timestamp_type timestamp() const;
|
|
ttl_opt ttl() const;
|
|
|
|
topology_request_tracking_mutation_builder(utils::UUID id, bool set_type = false);
|
|
using builder_base::set;
|
|
using builder_base::del;
|
|
topology_request_tracking_mutation_builder& set(const char* cell, topology_request value);
|
|
topology_request_tracking_mutation_builder& set(const char* cell, global_topology_request value);
|
|
topology_request_tracking_mutation_builder& abort(sstring error);
|
|
topology_request_tracking_mutation_builder& done(std::optional<sstring> error = std::nullopt);
|
|
topology_request_tracking_mutation_builder& set_truncate_table_data(const table_id& table_id);
|
|
topology_request_tracking_mutation_builder& set_new_keyspace_rf_change_data(const sstring& ks_name, const std::map<sstring, sstring>& rf_per_dc);
|
|
topology_request_tracking_mutation_builder& set_snapshot_tables_data(const std::unordered_set<table_id>&, const sstring& tag, bool);
|
|
topology_request_tracking_mutation_builder& set_finalize_migration_data(const sstring& ks_name);
|
|
|
|
canonical_mutation build() { return canonical_mutation{std::move(_m)}; }
|
|
};
|
|
|
|
extern template class topology_mutation_builder_base<topology_mutation_builder>;
|
|
extern template class topology_mutation_builder_base<topology_node_mutation_builder>;
|
|
extern template class topology_mutation_builder_base<topology_request_tracking_mutation_builder>;
|
|
|
|
} // namespace service
|