db: system_keyspace: improve system.raft_snapshot_config schema

Remove the `ip_addr` column which was not used. IP addresses are not
part of Raft configuration now and they can change dynamically.

Swap the `server_id` and `disposition` columns in the clustering key, so
when querying the configuration, we first obtain all servers with the
current disposition and then all servers with the previous disposition
(note that a server may appear both in current and previous).
This commit is contained in:
Kamil Braun
2023-01-13 18:15:07 +01:00
parent c3ed82e5fb
commit 2bfe85ce9b
2 changed files with 5 additions and 6 deletions

View File

@@ -238,10 +238,9 @@ schema_ptr system_keyspace::raft_snapshot_config() {
auto id = generate_legacy_id(system_keyspace::NAME, RAFT_SNAPSHOT_CONFIG);
return schema_builder(system_keyspace::NAME, RAFT_SNAPSHOT_CONFIG, std::optional(id))
.with_column("group_id", timeuuid_type, column_kind::partition_key)
.with_column("server_id", uuid_type, column_kind::clustering_key)
.with_column("disposition", ascii_type, column_kind::clustering_key) // can be 'CURRENT` or `PREVIOUS'
.with_column("server_id", uuid_type, column_kind::clustering_key)
.with_column("can_vote", boolean_type)
.with_column("ip_addr", inet_addr_type)
.set_comment("RAFT configuration for the latest snapshot descriptor")
.with_version(generate_schema_version(id))

View File

@@ -129,7 +129,7 @@ future<raft::snapshot_descriptor> raft_sys_table_storage::load_snapshot_descript
// have a single snapshot installed at a time
const auto& snp_row = snp_rs->one();
// Fetch current and previous raft configurations for the snapshot
static const auto load_cfg_cql = format("SELECT server_id, disposition, can_vote FROM system.{} WHERE group_id = ?", db::system_keyspace::RAFT_SNAPSHOT_CONFIG);
static const auto load_cfg_cql = format("SELECT disposition, server_id, can_vote FROM system.{} WHERE group_id = ?", db::system_keyspace::RAFT_SNAPSHOT_CONFIG);
::shared_ptr<cql3::untyped_result_set> cfg_rs = co_await _qp.execute_internal(load_cfg_cql, {_group_id.id}, cql3::query_processor::cache_internal::yes);
raft::configuration cfg;
@@ -166,16 +166,16 @@ future<> raft_sys_table_storage::store_snapshot_descriptor(const raft::snapshot_
static const auto delete_raft_cfg_cql = format("DELETE FROM system.{} WHERE group_id = ?", db::system_keyspace::RAFT_SNAPSHOT_CONFIG);
co_await _qp.execute_internal(delete_raft_cfg_cql, {_group_id.id}, cql3::query_processor::cache_internal::yes);
// store current and previous raft configurations
static const auto store_raft_cfg_cql = format("INSERT INTO system.{} (group_id, server_id, disposition, can_vote) VALUES (?, ?, ?, ?)",
static const auto store_raft_cfg_cql = format("INSERT INTO system.{} (group_id, disposition, server_id, can_vote) VALUES (?, ?, ?, ?)",
db::system_keyspace::RAFT_SNAPSHOT_CONFIG);
for (const raft::config_member& srv : snap.config.current) {
co_await _qp.execute_internal(store_raft_cfg_cql,
{_group_id.id, srv.addr.id.id, "CURRENT", srv.can_vote},
{_group_id.id, "CURRENT", srv.addr.id.id, srv.can_vote},
cql3::query_processor::cache_internal::yes);
}
for (const raft::config_member& srv : snap.config.previous) {
co_await _qp.execute_internal(store_raft_cfg_cql,
{_group_id.id, srv.addr.id.id, "PREVIOUS", srv.can_vote},
{_group_id.id, "PREVIOUS", srv.addr.id.id, srv.can_vote},
cql3::query_processor::cache_internal::yes);
}
// Also update the latest snapshot id in `system.raft` table