Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Nov 7, 2024
1 parent 80590bd commit 59996ac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 59 deletions.
52 changes: 14 additions & 38 deletions nexus/types/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::internal_api::params::DnsConfigParams;
use crate::inventory::Collection;
pub use crate::inventory::SourceNatConfig;
pub use crate::inventory::ZpoolName;
use blueprint_diff::ClickhouseClusterConfigDiffTables;
use blueprint_display::BpClickhouseKeepersSubtableSchema;
use blueprint_display::BpClickhouseServersSubtableSchema;
use derive_more::From;
Expand Down Expand Up @@ -491,45 +492,20 @@ impl<'a> BlueprintDisplay<'a> {
return None;
};

let kvlist = KvListWithHeading::new_unchanged(
CLICKHOUSE_CLUSTER_CONFIG_HEADING,
vec![
(GENERATION, config.generation.to_string()),
(
CLICKHOUSE_MAX_USED_SERVER_ID,
config.max_used_server_id.to_string(),
),
(
CLICKHOUSE_MAX_USED_KEEPER_ID,
config.max_used_keeper_id.to_string(),
),
(CLICKHOUSE_CLUSTER_NAME, config.cluster_name.clone()),
(CLICKHOUSE_CLUSTER_SECRET, config.cluster_secret.clone()),
(
CLICKHOUSE_HIGHEST_SEEN_KEEPER_LEADER_COMMITTED_LOG_INDEX,
config
.highest_seen_keeper_leader_committed_log_index
.to_string(),
),
],
);

let keepers = BpSledSubtable::new(
BpClickhouseKeepersSubtableSchema {},
BpGeneration::Value(config.generation),
(config.generation, &config.keepers)
.rows(BpDiffState::Unchanged)
.collect(),
);
let servers = BpSledSubtable::new(
BpClickhouseServersSubtableSchema {},
BpGeneration::Value(config.generation),
(config.generation, &config.servers)
.rows(BpDiffState::Unchanged)
.collect(),
);
let diff_table =
ClickhouseClusterConfigDiffTables::single_blueprint_table(
BpDiffState::Unchanged,
config,
);

Some((kvlist, keepers, servers))
Some((
diff_table.metadata,
diff_table.keepers,
// Safety: The call to
// `ClickhouseClusterConfigDiffTables::single_blueprint_table`
// always returns all tables.
diff_table.servers.unwrap(),
))
}
}

Expand Down
45 changes: 24 additions & 21 deletions nexus/types/src/deployment/blueprint_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,55 +1006,58 @@ impl ClickhouseClusterConfigDiffTables {
/// The "before" inventory collection or blueprint does not have a relevant
/// keeper configuration.
pub fn added_to_blueprint(after: &ClickhouseClusterConfig) -> Self {
Self::single_blueprint_table(BpDiffState::Added, after)
}

/// We are diffing two `Blueprint`s, but The latest bluerprint does not have
/// a `ClickhouseClusterConfig`.
pub fn removed_from_blueprint(before: &ClickhouseClusterConfig) -> Self {
Self::single_blueprint_table(BpDiffState::Removed, before)
}

pub fn single_blueprint_table(
diff_state: BpDiffState,
config: &ClickhouseClusterConfig,
) -> Self {
let rows: Vec<_> = [
(GENERATION, after.generation.to_string()),
(GENERATION, config.generation.to_string()),
(
CLICKHOUSE_MAX_USED_SERVER_ID,
after.max_used_server_id.to_string(),
config.max_used_server_id.to_string(),
),
(
CLICKHOUSE_MAX_USED_KEEPER_ID,
after.max_used_keeper_id.to_string(),
config.max_used_keeper_id.to_string(),
),
(CLICKHOUSE_CLUSTER_NAME, after.cluster_name.clone()),
(CLICKHOUSE_CLUSTER_SECRET, after.cluster_secret.clone()),
(CLICKHOUSE_CLUSTER_NAME, config.cluster_name.clone()),
(CLICKHOUSE_CLUSTER_SECRET, config.cluster_secret.clone()),
(
CLICKHOUSE_HIGHEST_SEEN_KEEPER_LEADER_COMMITTED_LOG_INDEX,
after
config
.highest_seen_keeper_leader_committed_log_index
.to_string(),
),
]
.into_iter()
.map(|(key, val)| KvPair::new(BpDiffState::Added, key, val))
.map(|(key, val)| KvPair::new(diff_state, key, val))
.collect();

let metadata =
KvListWithHeading::new(CLICKHOUSE_CLUSTER_CONFIG_HEADING, rows);

let keepers = BpSledSubtable::new(
BpClickhouseKeepersSubtableSchema {},
BpGeneration::Value(after.generation),
(after.generation, &after.keepers)
.rows(BpDiffState::Added)
.collect(),
BpGeneration::Value(config.generation),
(config.generation, &config.keepers).rows(diff_state).collect(),
);
let servers = Some(BpSledSubtable::new(
BpClickhouseServersSubtableSchema {},
BpGeneration::Value(after.generation),
(after.generation, &after.servers)
.rows(BpDiffState::Added)
.collect(),
BpGeneration::Value(config.generation),
(config.generation, &config.servers).rows(diff_state).collect(),
));

ClickhouseClusterConfigDiffTables { metadata, keepers, servers }
}

/// We are diffing two `Blueprint`s, but The latest bluerprint does not have
/// a `ClickhouseClusterConfig`.
pub fn removed_from_blueprint(before: &ClickhouseClusterConfig) -> Self {
todo!()
}
}

/// Wrapper to allow a [`BlueprintDiff`] to be displayed.
Expand Down

0 comments on commit 59996ac

Please sign in to comment.