Skip to content

Commit 6cc81ce

Browse files
committed
move some types and break a circular dep
1 parent 91ba7c3 commit 6cc81ce

8 files changed

Lines changed: 135 additions & 132 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/bootstrap-agent-lockstep-client/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ progenitor::generate_api!(
4141
RouterLifetimeConfig = sled_agent_types::early_networking::RouterLifetimeConfig,
4242
RssStep = bootstrap_agent_lockstep_types::RssStep,
4343
ServiceIpPoolConfig = bootstrap_agent_lockstep_types::ServiceIpPoolConfig,
44+
SledAgentInfo = bootstrap_agent_lockstep_types::SledAgentInfo,
45+
StartSledAgentStatus = bootstrap_agent_lockstep_types::StartSledAgentStatus,
4446
SwitchSlot = sled_agent_types::early_networking::SwitchSlot,
4547
TxEqConfig = sled_agent_types::early_networking::TxEqConfig,
4648
UplinkAddressConfig = sled_agent_types::early_networking::UplinkAddressConfig,

sled-agent/bootstrap-agent-lockstep-api/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ dropshot.workspace = true
1212
bootstrap-agent-lockstep-types.workspace = true
1313
omicron-uuid-kinds.workspace = true
1414
omicron-workspace-hack.workspace = true
15-
sled-agent-multirack-join.workspace = true

sled-agent/bootstrap-agent-lockstep-api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
1212
use bootstrap_agent_lockstep_types::BaseboardIds;
1313
use bootstrap_agent_lockstep_types::MultirackJoinRequest;
14+
use bootstrap_agent_lockstep_types::MultirackJoinServiceState;
1415
use bootstrap_agent_lockstep_types::RackInitializeRequest;
1516
use bootstrap_agent_lockstep_types::RackOperationStatus;
1617
use bootstrap_agent_lockstep_types::ReplicatedNetworkConfig;
1718
use dropshot::{HttpError, HttpResponseOk, RequestContext, TypedBody};
1819
use omicron_uuid_kinds::MultirackJoinUuid;
1920
use omicron_uuid_kinds::RackInitUuid;
20-
use sled_agent_multirack_join::MultirackJoinServiceState;
2121

2222
#[dropshot::api_description]
2323
pub trait BootstrapAgentLockstepApi {

sled-agent/bootstrap-agent-lockstep-types/src/lib.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use anyhow::Context as _;
1313
use iddqd::IdOrdItem;
1414
use iddqd::IdOrdMap;
1515
use iddqd::id_upcast;
16+
use iddqd::{BiHashItem, BiHashMap, bi_upcast};
1617
use omicron_common::address::AZ_PREFIX_LENGTH;
1718
use omicron_common::address::IpRange;
1819
use omicron_common::address::IpVersion;
@@ -27,16 +28,23 @@ use omicron_common::api::external::UserId;
2728
use omicron_common::api::internal::nexus::Certificate;
2829
use omicron_uuid_kinds::MultirackJoinUuid;
2930
use omicron_uuid_kinds::RackInitUuid;
31+
use omicron_uuid_kinds::RackUuid;
32+
use omicron_uuid_kinds::SledUuid;
3033
use schemars::JsonSchema;
3134
use serde::{Deserialize, Serialize};
3235
use sled_agent_types::early_networking::RackNetworkConfig;
3336
use sled_hardware_types::BaseboardId;
37+
use std::collections::BTreeMap;
3438
use std::collections::BTreeSet;
3539
use std::net::IpAddr;
3640
use std::net::Ipv6Addr;
3741
use strum::EnumCount;
3842
use strum::EnumIter;
3943
use strum::IntoEnumIterator;
44+
use trust_quorum_types::messages::ReconfigureMsg as TqReconfigureMsg;
45+
use trust_quorum_types::status::CoordinatorStatus;
46+
use trust_quorum_types::types::Epoch;
47+
use trust_quorum_types::types::Threshold;
4048

4149
/// Configuration for the "rack setup service".
4250
///
@@ -532,3 +540,89 @@ impl IdOrdItem for BootstrapIpOfBaseboardId {
532540
pub struct BaseboardIds {
533541
pub data: IdOrdMap<BootstrapIpOfBaseboardId>,
534542
}
543+
544+
/// The state of the commit phase of the trust quorum protocol
545+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
546+
pub struct CommitState {
547+
pub rack_id: RackUuid,
548+
pub members: BTreeSet<BaseboardId>,
549+
pub epoch: Epoch,
550+
pub last_committed_epoch: Option<Epoch>,
551+
pub threshold: Threshold,
552+
pub commit_crash_tolerance: u8,
553+
pub acked: BTreeSet<BaseboardId>,
554+
pub fatal_errors: BTreeMap<BaseboardId, String>,
555+
pub transient_errors: BTreeMap<BaseboardId, String>,
556+
}
557+
558+
/// Status information for a given sled agent
559+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
560+
pub struct SledAgentInfo {
561+
pub baseboard_id: BaseboardId,
562+
pub sled_id: SledUuid,
563+
pub sled_subnet: Ipv6Subnet<SLED_PREFIX_LENGTH>,
564+
pub started: bool,
565+
pub fatal_error: Option<String>,
566+
}
567+
568+
impl BiHashItem for SledAgentInfo {
569+
type K1<'a> = &'a BaseboardId;
570+
type K2<'a> = &'a SledUuid;
571+
572+
fn key1(&self) -> Self::K1<'_> {
573+
&self.baseboard_id
574+
}
575+
576+
fn key2(&self) -> Self::K2<'_> {
577+
&self.sled_id
578+
}
579+
580+
bi_upcast!();
581+
}
582+
583+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
584+
pub struct StartSledAgentsStatus {
585+
pub sleds: BiHashMap<SledAgentInfo>,
586+
}
587+
588+
impl StartSledAgentsStatus {
589+
pub fn new(req: MultirackJoinRequest) -> Self {
590+
let rack_subnet = Ipv6Subnet::<RACK_PREFIX_LENGTH>::new(
591+
req.rack_network_config.rack_subnet.addr(),
592+
);
593+
let sleds = req
594+
.trust_quorum_peers
595+
.into_iter()
596+
.enumerate()
597+
.map(|(idx, baseboard_id)| SledAgentInfo {
598+
baseboard_id,
599+
sled_id: SledUuid::new_v4(),
600+
sled_subnet: get_64_subnet(
601+
rack_subnet,
602+
u8::try_from(idx + 1).expect("too many sleds"),
603+
),
604+
started: false,
605+
fatal_error: None,
606+
})
607+
.collect();
608+
609+
StartSledAgentsStatus { sleds }
610+
}
611+
}
612+
613+
/// The current state of the `MultirackJoinService` as retrieved from the
614+
/// `output_rx` watch channel.
615+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
616+
#[serde(rename_all = "snake_case", tag = "state")]
617+
pub enum MultirackJoinServiceState {
618+
Uninitialized,
619+
Requested,
620+
Starting,
621+
TrustQuorumReconfigure(TqReconfigureMsg),
622+
TrustQuorumPreparing(CoordinatorStatus),
623+
TrustQuorumCommitting(CommitState),
624+
StartSledAgents(StartSledAgentsStatus),
625+
Completed,
626+
Failed { message: String },
627+
TaskPanicked,
628+
}

sled-agent/multirack-join/src/lib.rs

Lines changed: 36 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,20 @@
1515
1616
#[macro_use]
1717
extern crate slog;
18-
use bootstrap_agent_lockstep_types::MultirackJoinRequest;
19-
use iddqd::{BiHashItem, BiHashMap, bi_upcast};
18+
use bootstrap_agent_lockstep_types::{
19+
CommitState, MultirackJoinRequest, MultirackJoinServiceState,
20+
SledAgentInfo, StartSledAgentsStatus,
21+
};
2022
use nexus_types::trust_quorum::TrustQuorumConfig;
2123
use omicron_common::address::BOOTSTRAP_AGENT_RACK_INIT_PORT;
22-
use omicron_common::address::Ipv6Subnet;
23-
use omicron_common::address::RACK_PREFIX_LENGTH;
24-
use omicron_common::address::SLED_PREFIX_LENGTH;
25-
use omicron_common::address::get_64_subnet;
26-
use omicron_uuid_kinds::{RackUuid, SledUuid};
27-
use schemars::JsonSchema;
28-
use serde::{Deserialize, Serialize};
24+
use omicron_uuid_kinds::RackUuid;
2925
use sled_agent_bootstrap_common::sprockets::{
3026
SprocketsClient, SprocketsClientError,
3127
};
3228
use sled_agent_bootstrap_common::{RssContext, RunRssError};
33-
use sled_agent_types::sled::StartSledAgentRequest;
34-
use sled_agent_types::sled::StartSledAgentRequestBody;
29+
use sled_agent_types::sled::{
30+
StartSledAgentRequest, StartSledAgentRequestBody,
31+
};
3532
use sled_hardware_types::BaseboardId;
3633
use slog::{Logger, error, info};
3734
use slog_error_chain::{InlineErrorChain, SlogInlineError};
@@ -48,9 +45,7 @@ use tokio::{
4845
};
4946
use trust_quorum::{NodeApiError, ProxyError};
5047
use trust_quorum_types::{
51-
messages::ReconfigureMsg as TqReconfigureMsg,
52-
status::CoordinatorStatus,
53-
types::{Epoch, Threshold},
48+
messages::ReconfigureMsg as TqReconfigureMsg, types::Epoch,
5449
};
5550

5651
const INITIAL_TRUST_QUORUM_EPOCH: Epoch = Epoch(1);
@@ -106,18 +101,23 @@ impl From<RunRssError> for MultirackJoinServiceError {
106101
}
107102
}
108103

109-
/// The state of the commit phase of the trust quorum protocol
110-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
111-
pub struct CommitState {
112-
rack_id: RackUuid,
113-
members: BTreeSet<BaseboardId>,
114-
epoch: Epoch,
115-
last_committed_epoch: Option<Epoch>,
116-
threshold: Threshold,
117-
commit_crash_tolerance: u8,
118-
acked: BTreeSet<BaseboardId>,
119-
fatal_errors: BTreeMap<BaseboardId, String>,
120-
transient_errors: BTreeMap<BaseboardId, String>,
104+
// The value returned from `MultirackJoinServiceTask::tq_prepare`
105+
enum TqPrepareResult {
106+
Prepared,
107+
ReconfigurationNeeded {
108+
new_members: BTreeSet<BaseboardId>,
109+
new_epoch: Epoch,
110+
},
111+
}
112+
113+
// The value returned from `MultirackJoinServiceTask::tq_commit`
114+
enum TqCommitResult {
115+
Committed,
116+
ReconfigurationNeeded {
117+
new_members: BTreeSet<BaseboardId>,
118+
new_epoch: Epoch,
119+
just_committed_epoch: Epoch,
120+
},
121121
}
122122

123123
/// All the information required to start a sled agent remotely over a sprockets
@@ -128,31 +128,21 @@ struct StartSledAgentInfo {
128128
req: StartSledAgentRequest,
129129
}
130130

131-
/// Status information for a given sled agent
132-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
133-
pub struct SledAgentInfo {
134-
pub baseboard_id: BaseboardId,
135-
pub sled_id: SledUuid,
136-
pub sled_subnet: Ipv6Subnet<SLED_PREFIX_LENGTH>,
137-
pub started: bool,
138-
pub fatal_error: Option<String>,
139-
}
140-
141-
impl SledAgentInfo {
142-
fn to_start_sled_agent_info(
143-
&self,
131+
impl StartSledAgentInfo {
132+
fn new(
144133
rack_id: RackUuid,
145134
bootstrap_ip: Ipv6Addr,
146-
) -> StartSledAgentInfo {
135+
info: SledAgentInfo,
136+
) -> Self {
147137
StartSledAgentInfo {
148-
baseboard_id: self.baseboard_id.clone(),
138+
baseboard_id: info.baseboard_id.clone(),
149139
bootstrap_ip,
150140
req: StartSledAgentRequest {
151141
generation: 0,
152142
schema_version: 1,
153143
body: StartSledAgentRequestBody {
154-
id: self.sled_id,
155-
subnet: self.sled_subnet,
144+
id: info.sled_id,
145+
subnet: info.sled_subnet,
156146
use_trust_quorum: true,
157147
is_lrtq_learner: false,
158148
rack_id,
@@ -162,87 +152,6 @@ impl SledAgentInfo {
162152
}
163153
}
164154

165-
impl BiHashItem for SledAgentInfo {
166-
type K1<'a> = &'a BaseboardId;
167-
type K2<'a> = &'a SledUuid;
168-
169-
fn key1(&self) -> Self::K1<'_> {
170-
&self.baseboard_id
171-
}
172-
173-
fn key2(&self) -> Self::K2<'_> {
174-
&self.sled_id
175-
}
176-
177-
bi_upcast!();
178-
}
179-
180-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
181-
pub struct StartSledAgentsStatus {
182-
pub sleds: BiHashMap<SledAgentInfo>,
183-
}
184-
185-
impl StartSledAgentsStatus {
186-
pub fn new(req: MultirackJoinRequest) -> Self {
187-
let rack_subnet = Ipv6Subnet::<RACK_PREFIX_LENGTH>::new(
188-
req.rack_network_config.rack_subnet.addr(),
189-
);
190-
let sleds = req
191-
.trust_quorum_peers
192-
.into_iter()
193-
.enumerate()
194-
.map(|(idx, baseboard_id)| SledAgentInfo {
195-
baseboard_id,
196-
sled_id: SledUuid::new_v4(),
197-
sled_subnet: get_64_subnet(
198-
rack_subnet,
199-
u8::try_from(idx + 1).expect("too many sleds"),
200-
),
201-
started: false,
202-
fatal_error: None,
203-
})
204-
.collect();
205-
206-
StartSledAgentsStatus { sleds }
207-
}
208-
}
209-
210-
/// The current state of the `MultirackJoinService` as retrieved from the
211-
/// `output_rx` watch channel.
212-
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
213-
#[serde(rename_all = "snake_case", tag = "state")]
214-
pub enum MultirackJoinServiceState {
215-
Uninitialized,
216-
Requested,
217-
Starting,
218-
TrustQuorumReconfigure(TqReconfigureMsg),
219-
TrustQuorumPreparing(CoordinatorStatus),
220-
TrustQuorumCommitting(CommitState),
221-
StartSledAgents(StartSledAgentsStatus),
222-
Completed,
223-
Failed { message: String },
224-
TaskPanicked,
225-
}
226-
227-
// The value returned from `MultirackJoinServiceTask::tq_prepare`
228-
enum TqPrepareResult {
229-
Prepared,
230-
ReconfigurationNeeded {
231-
new_members: BTreeSet<BaseboardId>,
232-
new_epoch: Epoch,
233-
},
234-
}
235-
236-
// The value returned from `MultirackJoinServiceTask::tq_commit`
237-
enum TqCommitResult {
238-
Committed,
239-
ReconfigurationNeeded {
240-
new_members: BTreeSet<BaseboardId>,
241-
new_epoch: Epoch,
242-
just_committed_epoch: Epoch,
243-
},
244-
}
245-
246155
/// The interface to the Multirack Join Service.
247156
pub struct MultirackJoinServiceHandle {
248157
pub join_handle:
@@ -347,13 +256,13 @@ impl MultirackJoinServiceTask {
347256

348257
// Attempt to start all our sled agents in parallel
349258
let mut set = JoinSet::new();
350-
for sled in status.sleds.iter().cloned() {
259+
for info in status.sleds.iter().cloned() {
351260
// Unwrap is safe, because we constructed both bootstrap_ips and
352261
// status from trust_quorum_peers.
353-
let bootstrap_ip = *bootstrap_ips.get(&sled.baseboard_id).unwrap();
262+
let bootstrap_ip = *bootstrap_ips.get(&info.baseboard_id).unwrap();
354263
self.spawn_start_sled_agent_task(
355264
&mut set,
356-
sled.to_start_sled_agent_info(rack_id, bootstrap_ip),
265+
StartSledAgentInfo::new(rack_id, bootstrap_ip, info),
357266
);
358267
}
359268

sled-agent/src/bootstrap/http_entrypoints_lockstep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use bootstrap_agent_lockstep_api::bootstrap_agent_lockstep_api_mod;
1919
use bootstrap_agent_lockstep_types::BaseboardIds;
2020
use bootstrap_agent_lockstep_types::BootstrapIpOfBaseboardId;
2121
use bootstrap_agent_lockstep_types::MultirackJoinRequest;
22+
use bootstrap_agent_lockstep_types::MultirackJoinServiceState;
2223
use bootstrap_agent_lockstep_types::RackInitializeRequest;
2324
use bootstrap_agent_lockstep_types::RackOperationStatus;
2425
use bootstrap_agent_lockstep_types::ReplicatedNetworkConfig;
@@ -32,7 +33,6 @@ use omicron_uuid_kinds::RackInitUuid;
3233
use sled_agent_bootstrap_common::RssContext;
3334
use sled_agent_config_reconciler::InternalDisksReceiver;
3435
use sled_agent_measurements::MeasurementsHandle;
35-
use sled_agent_multirack_join::MultirackJoinServiceState;
3636
use sled_agent_rack_setup::RackInitializeRequestParams;
3737
use slog::Logger;
3838
use sprockets_tls::keys::SprocketsConfig;

0 commit comments

Comments
 (0)