Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Nov 6, 2024
1 parent 437983b commit fcf3b2d
Showing 1 changed file with 144 additions and 3 deletions.
147 changes: 144 additions & 3 deletions nexus/types/src/deployment/blueprint_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
//! Types helpful for diffing blueprints.
use super::blueprint_display::{
constants::*, linear_table_modified, linear_table_unchanged, BpDiffState,
BpGeneration, BpOmicronZonesSubtableSchema, BpPhysicalDisksSubtableSchema,
constants::*, linear_table_modified, linear_table_unchanged,
BpClickhouseServersSubtableSchema, BpDiffState, BpGeneration,
BpOmicronZonesSubtableSchema, BpPhysicalDisksSubtableSchema,
BpSledSubtable, BpSledSubtableColumn, BpSledSubtableData,
BpSledSubtableRow, KvListWithHeading, KvPair,
};
Expand Down Expand Up @@ -709,7 +710,147 @@ impl ClickhouseClusterConfigDiffTables {
before: &clickhouse_admin_types::ClickhouseKeeperClusterMembership,
after: &ClickhouseClusterConfig,
) -> Self {
todo!()
let leader_committed_log_index = if before.leader_committed_log_index
== after.highest_seen_keeper_leader_committed_log_index
{
KvPair::new(
BpDiffState::Unchanged,
CLICKHOUSE_HIGHEST_SEEN_KEEPER_LEADER_COMMITTED_LOG_INDEX,
linear_table_unchanged(
&after.highest_seen_keeper_leader_committed_log_index,
),
)
} else {
KvPair::new(
BpDiffState::Modified,
CLICKHOUSE_HIGHEST_SEEN_KEEPER_LEADER_COMMITTED_LOG_INDEX,
linear_table_modified(
&before.leader_committed_log_index,
&after.highest_seen_keeper_leader_committed_log_index,
),
)
};
let metadata = KvListWithHeading::new(
CLICKHOUSE_CLUSTER_CONFIG_HEADING,
vec![
KvPair::new(
BpDiffState::Added,
GENERATION,
linear_table_modified(
&NOT_PRESENT_IN_COLLECTION_PARENS,
&after.generation,
),
),
KvPair::new(
BpDiffState::Added,
CLICKHOUSE_MAX_USED_SERVER_ID,
linear_table_modified(
&NOT_PRESENT_IN_COLLECTION_PARENS,
&after.max_used_server_id,
),
),
KvPair::new(
BpDiffState::Added,
CLICKHOUSE_MAX_USED_KEEPER_ID,
linear_table_modified(
&NOT_PRESENT_IN_COLLECTION_PARENS,
&after.max_used_keeper_id,
),
),
KvPair::new(
BpDiffState::Added,
CLICKHOUSE_CLUSTER_NAME,
linear_table_modified(
&NOT_PRESENT_IN_COLLECTION_PARENS,
&after.cluster_name,
),
),
KvPair::new(
BpDiffState::Added,
CLICKHOUSE_CLUSTER_SECRET,
linear_table_modified(
&NOT_PRESENT_IN_COLLECTION_PARENS,
&after.cluster_secret,
),
),
leader_committed_log_index,
],
);

// Build up our keeper table
let mut keeper_rows = vec![];
for (zone_id, keeper_id) in &after.keepers {
if before.raft_config.contains(keeper_id) {
// Unchanged keepers
keeper_rows.push(BpSledSubtableRow::new(
BpDiffState::Unchanged,
vec![
BpSledSubtableColumn::Value(zone_id.to_string()),
BpSledSubtableColumn::Value(keeper_id.to_string()),
],
));
} else {
// Added keepers
keeper_rows.push(BpSledSubtableRow::new(
BpDiffState::Added,
vec![
BpSledSubtableColumn::Value(zone_id.to_string()),
BpSledSubtableColumn::Value(keeper_id.to_string()),
],
));
}
}

let after_ids: BTreeSet<_> = after.keepers.values().clone().collect();
for keeper_id in &before.raft_config {
if !after_ids.contains(keeper_id) {
// Removed keepers
keeper_rows.push(BpSledSubtableRow::new(
BpDiffState::Removed,
vec![
BpSledSubtableColumn::Value(
NOT_PRESENT_IN_COLLECTION_PARENS.to_string(),
),
BpSledSubtableColumn::Value(keeper_id.to_string()),
],
));
}
}

let keepers = BpSledSubtable::new(
BpClickhouseKeepersSubtableSchema {},
BpGeneration::Diff { before: None, after: Some(after.generation) },
keeper_rows,
);

// Build up our server table
let server_rows: Vec<BpSledSubtableRow> = after
.servers
.iter()
.map(|(zone_id, server_id)| {
BpSledSubtableRow::new(
BpDiffState::Added,
vec![
BpSledSubtableColumn::diff(
NOT_PRESENT_IN_COLLECTION_PARENS.to_string(),
zone_id.to_string(),
),
BpSledSubtableColumn::diff(
NOT_PRESENT_IN_COLLECTION_PARENS.to_string(),
server_id.to_string(),
),
],
)
})
.collect();

let servers = Some(BpSledSubtable::new(
BpClickhouseServersSubtableSchema {},
BpGeneration::Diff { before: None, after: Some(after.generation) },
server_rows,
));

ClickhouseClusterConfigDiffTables { metadata, keepers, servers }
}

pub fn diff_blueprints(
Expand Down

0 comments on commit fcf3b2d

Please sign in to comment.