1515
1616#[ macro_use]
1717extern 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+ } ;
2022use nexus_types:: trust_quorum:: TrustQuorumConfig ;
2123use 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 ;
2925use sled_agent_bootstrap_common:: sprockets:: {
3026 SprocketsClient , SprocketsClientError ,
3127} ;
3228use 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+ } ;
3532use sled_hardware_types:: BaseboardId ;
3633use slog:: { Logger , error, info} ;
3734use slog_error_chain:: { InlineErrorChain , SlogInlineError } ;
@@ -48,9 +45,7 @@ use tokio::{
4845} ;
4946use trust_quorum:: { NodeApiError , ProxyError } ;
5047use trust_quorum_types:: {
51- messages:: ReconfigureMsg as TqReconfigureMsg ,
52- status:: CoordinatorStatus ,
53- types:: { Epoch , Threshold } ,
48+ messages:: ReconfigureMsg as TqReconfigureMsg , types:: Epoch ,
5449} ;
5550
5651const 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.
247156pub 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
0 commit comments