Skip to content

Commit

Permalink
Move clickhouse allocator construction into build
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Nov 7, 2024
1 parent c645e64 commit 3924cd1
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 53 deletions.
89 changes: 43 additions & 46 deletions nexus/reconfigurator/planning/src/blueprint_builder/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ pub struct BlueprintBuilder<'a> {
sled_ip_allocators: BTreeMap<SledUuid, IpAllocator>,
external_networking: OnceCell<BuilderExternalNetworking<'a>>,
internal_dns_subnets: OnceCell<DnsSubnetAllocator>,
clickhouse_allocator: Option<ClickhouseAllocator>,

// These fields will become part of the final blueprint. See the
// corresponding fields in `Blueprint`.
Expand Down Expand Up @@ -370,8 +369,6 @@ impl<'a> BlueprintBuilder<'a> {
"parent_id" => parent_blueprint.id.to_string(),
));

let mut rng = PlannerRng::new();

// Prefer the sled state from our parent blueprint for sleds
// that were in it; there may be new sleds in `input`, in which
// case we'll use their current state as our starting point.
Expand All @@ -397,46 +394,6 @@ impl<'a> BlueprintBuilder<'a> {
|| commissioned_sled_ids.contains(sled_id)
});

// If we have the clickhouse cluster setup enabled via policy and we
// don't yet have a `ClickhouseClusterConfiguration`, then we must create
// one and feed it to our `ClickhouseAllocator`.
let clickhouse_allocator = if input.clickhouse_cluster_enabled() {
let parent_config = parent_blueprint
.clickhouse_cluster_config
.clone()
.unwrap_or_else(|| {
info!(
log,
concat!(
"Clickhouse cluster enabled by policy: ",
"generating initial 'ClickhouseClusterConfig' ",
"and 'ClickhouseAllocator'"
)
);
ClickhouseClusterConfig::new(
OXIMETER_CLUSTER.to_string(),
rng.next_clickhouse().to_string(),
)
});
Some(ClickhouseAllocator::new(
log.clone(),
parent_config,
inventory.latest_clickhouse_keeper_membership(),
))
} else {
if parent_blueprint.clickhouse_cluster_config.is_some() {
info!(
log,
concat!(
"clickhouse cluster disabled via policy ",
"discarding existing 'ClickhouseAllocator' and ",
"the resulting generated 'ClickhouseClusterConfig"
)
);
}
None
};

Ok(BlueprintBuilder {
log,
parent_blueprint,
Expand All @@ -451,11 +408,10 @@ impl<'a> BlueprintBuilder<'a> {
sled_state,
cockroachdb_setting_preserve_downgrade: parent_blueprint
.cockroachdb_setting_preserve_downgrade,
clickhouse_allocator,
creator: creator.to_owned(),
operations: Vec::new(),
comments: Vec::new(),
rng,
rng: PlannerRng::new(),
})
}

Expand Down Expand Up @@ -536,9 +492,50 @@ impl<'a> BlueprintBuilder<'a> {
.datasets
.into_datasets_map(self.input.all_sled_ids(SledFilter::InService));

// If we have the clickhouse cluster setup enabled via policy and we
// don't yet have a `ClickhouseClusterConfiguration`, then we must create
// one and feed it to our `ClickhouseAllocator`.
let clickhouse_allocator = if self.input.clickhouse_cluster_enabled() {
let parent_config = self
.parent_blueprint
.clickhouse_cluster_config
.clone()
.unwrap_or_else(|| {
info!(
self.log,
concat!(
"Clickhouse cluster enabled by policy: ",
"generating initial 'ClickhouseClusterConfig' ",
"and 'ClickhouseAllocator'"
)
);
ClickhouseClusterConfig::new(
OXIMETER_CLUSTER.to_string(),
self.rng.next_clickhouse().to_string(),
)
});
Some(ClickhouseAllocator::new(
self.log.clone(),
parent_config,
self.collection.latest_clickhouse_keeper_membership(),
))
} else {
if self.parent_blueprint.clickhouse_cluster_config.is_some() {
info!(
self.log,
concat!(
"clickhouse cluster disabled via policy ",
"discarding existing 'ClickhouseAllocator' and ",
"the resulting generated 'ClickhouseClusterConfig"
)
);
}
None
};

// If we have an allocator, use it to generate a new config. If an error
// is returned then log it and carry over the parent_config.
let clickhouse_cluster_config = self.clickhouse_allocator.map(|a| {
let clickhouse_cluster_config = clickhouse_allocator.map(|a| {
match a.plan(&(&blueprint_zones).into()) {
Ok(config) => config,
Err(e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ to: blueprint 31ef2071-2ec9-49d9-8827-fd83b17a0e3d
+ max used server id::::::::::::::::::::::::::::: 2
+ max used keeper id::::::::::::::::::::::::::::: 3
+ cluster name::::::::::::::::::::::::::::::::::: oximeter_cluster
+ cluster secret::::::::::::::::::::::::::::::::: 1c3bd4f4-3b2a-45e1-ba9c-8c75bd32462d
+ cluster secret::::::::::::::::::::::::::::::::: 75ba7558-f7cf-431f-bba5-71c8e82fd4c1
+ highest seen keeper leader committed log index: 0

clickhouse keepers at generation 2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ to: blueprint 92fa943c-7dd4-48c3-9447-c9d0665744b6
max used server id::::::::::::::::::::::::::::: 2 (unchanged)
max used keeper id::::::::::::::::::::::::::::: 3 (unchanged)
cluster name::::::::::::::::::::::::::::::::::: oximeter_cluster (unchanged)
cluster secret::::::::::::::::::::::::::::::::: 1c3bd4f4-3b2a-45e1-ba9c-8c75bd32462d (unchanged)
cluster secret::::::::::::::::::::::::::::::::: 75ba7558-f7cf-431f-bba5-71c8e82fd4c1 (unchanged)
* highest seen keeper leader committed log index: 0 -> 1

clickhouse keepers at generation 2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ to: blueprint 2886dab5-61a2-46b4-87af-bc7aeb44cccb
max used server id::::::::::::::::::::::::::::: 2 (unchanged)
* max used keeper id::::::::::::::::::::::::::::: 3 -> 4
cluster name::::::::::::::::::::::::::::::::::: oximeter_cluster (unchanged)
cluster secret::::::::::::::::::::::::::::::::: 1c3bd4f4-3b2a-45e1-ba9c-8c75bd32462d (unchanged)
cluster secret::::::::::::::::::::::::::::::::: 75ba7558-f7cf-431f-bba5-71c8e82fd4c1 (unchanged)
highest seen keeper leader committed log index: 1 (unchanged)

clickhouse keepers generation 2 -> 3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ to: blueprint cb39be9d-5476-44fa-9edf-9938376219ef
max used server id::::::::::::::::::::::::::::: 2 (unchanged)
max used keeper id::::::::::::::::::::::::::::: 4 (unchanged)
cluster name::::::::::::::::::::::::::::::::::: oximeter_cluster (unchanged)
cluster secret::::::::::::::::::::::::::::::::: 1c3bd4f4-3b2a-45e1-ba9c-8c75bd32462d (unchanged)
cluster secret::::::::::::::::::::::::::::::::: 75ba7558-f7cf-431f-bba5-71c8e82fd4c1 (unchanged)
highest seen keeper leader committed log index: 1 (unchanged)

clickhouse keepers at generation 3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ to: blueprint 74f2e7fd-687e-4c9e-b5d8-e474a5bb8e7c
max used server id::::::::::::::::::::::::::::: 2 (unchanged)
max used keeper id::::::::::::::::::::::::::::: 3 (unchanged)
cluster name::::::::::::::::::::::::::::::::::: oximeter_cluster (unchanged)
cluster secret::::::::::::::::::::::::::::::::: 1d73a59c-d623-4d22-8e55-ba9031bdc7d5 (unchanged)
cluster secret::::::::::::::::::::::::::::::::: 9b56c0da-33d7-41a6-b411-6d00e71bea9b (unchanged)
highest seen keeper leader committed log index: 1 (unchanged)

clickhouse keepers generation 2 -> 3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ to: blueprint df68d4d4-5af4-4b56-95bb-1654a6957d4f
max used server id::::::::::::::::::::::::::::: 2 (unchanged)
* max used keeper id::::::::::::::::::::::::::::: 3 -> 4
cluster name::::::::::::::::::::::::::::::::::: oximeter_cluster (unchanged)
cluster secret::::::::::::::::::::::::::::::::: 1d73a59c-d623-4d22-8e55-ba9031bdc7d5 (unchanged)
cluster secret::::::::::::::::::::::::::::::::: 9b56c0da-33d7-41a6-b411-6d00e71bea9b (unchanged)
* highest seen keeper leader committed log index: 1 -> 3

clickhouse keepers generation 3 -> 4:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ to: blueprint d895ef50-9978-454c-bdfb-b8dbe2c9a918
- max used server id::::::::::::::::::::::::::::: 2
- max used keeper id::::::::::::::::::::::::::::: 3
- cluster name::::::::::::::::::::::::::::::::::: oximeter_cluster
- cluster secret::::::::::::::::::::::::::::::::: 3a94d30e-5c49-4000-af93-f0862038097b
- cluster secret::::::::::::::::::::::::::::::::: 7470cfb0-bfbf-49d0-b37b-13747463c865
- highest seen keeper leader committed log index: 0

clickhouse keepers at generation 2:
Expand Down

0 comments on commit 3924cd1

Please sign in to comment.