@@ -83,45 +83,63 @@ const NUM_CONCURRENT_MGS_UPDATES: usize = 1;
83
83
/// The planner operates in distinct steps, and it is a compile-time error
84
84
/// to skip or reorder them; see `Planner::do_plan`.
85
85
trait PlannerStep {
86
+ type Next : PlannerStep ;
86
87
fn new ( ) -> Self ;
87
- fn into_next < Next : PlannerStep > ( self ) -> Next ;
88
+ fn into_next ( self ) -> Self :: Next ;
88
89
}
89
90
90
91
macro_rules! planner_step {
91
92
( $name: ident, $next: ident) => {
92
- /// Non-terminal step.
93
+ // Non-terminal step.
93
94
struct $name;
94
95
impl PlannerStep for $name {
96
+ type Next = $next;
97
+
98
+ fn new( ) -> Self {
99
+ Self
100
+ }
101
+
102
+ fn into_next( self ) -> Self :: Next {
103
+ Self :: Next :: new( )
104
+ }
105
+ }
106
+ } ;
107
+ ( $name: ident) => {
108
+ // Terminal step.
109
+ struct $name;
110
+ impl PlannerStep for $name {
111
+ type Next = Self ;
112
+
95
113
fn new( ) -> Self {
96
114
Self
97
115
}
98
116
99
- fn into_next<$next : PlannerStep > ( self ) -> $next {
100
- $next :: new ( )
117
+ fn into_next( self ) -> Self :: Next {
118
+ unreachable! ( "terminal step has no next" )
101
119
}
102
120
}
103
121
} ;
104
122
}
105
123
planner_step ! ( ExpungeStep , AddStep ) ;
106
124
planner_step ! ( AddStep , DecommissionStep ) ;
107
- planner_step ! ( DecommissionStep , MgsUpdateStep ) ;
125
+ planner_step ! ( DecommissionStep , MgsUpdatesStep ) ;
108
126
planner_step ! ( MgsUpdatesStep , UpdateZonesStep ) ;
109
127
planner_step ! ( UpdateZonesStep , CockroachDbSettingsStep ) ;
110
128
planner_step ! ( CockroachDbSettingsStep , TerminalStep ) ;
111
- planner_step ! ( TerminalStep , Never ) ;
129
+ planner_step ! ( TerminalStep ) ;
112
130
113
- enum UpdateStepResult < Next > {
114
- ContinueToNextStep ( Next ) ,
131
+ enum UpdateStepResult < Prev : PlannerStep > {
132
+ ContinueToNextStep ( Prev ) ,
115
133
PlanningComplete ( TerminalStep ) ,
116
134
Waiting ( Vec < WaitCondition > ) ,
117
135
}
118
136
119
- impl < Next : PlannerStep > UpdateStepResult < Next > {
120
- fn continue_to_next_step < Prev : PlannerStep > ( prev : Prev ) -> Self {
121
- Self :: ContinueToNextStep ( prev. into_next ( ) )
137
+ impl < Prev : PlannerStep > UpdateStepResult < Prev > {
138
+ fn continue_to_next_step ( prev : Prev ) -> Self {
139
+ Self :: ContinueToNextStep ( prev)
122
140
}
123
141
124
- fn planning_complete ( prev : UpdateZonesStep ) -> Self {
142
+ fn planning_complete ( prev : CockroachDbSettingsStep ) -> Self {
125
143
Self :: PlanningComplete ( prev. into_next ( ) )
126
144
}
127
145
@@ -212,18 +230,18 @@ impl<'a> Planner<'a> {
212
230
}
213
231
} } ;
214
232
}
215
- let next = step ! ( self . do_plan_expunge( ) ?) ;
216
- let next = step ! ( self . do_plan_add( next ) ?) ;
217
- let next = step ! ( self . do_plan_decommission( next ) ?) ;
218
- let next = step ! ( self . do_plan_mgs_updates( next ) ) ;
219
- let next = step ! ( self . do_plan_zone_updates( next ) ?) ;
220
- step ! ( self . do_plan_cockroachdb_settings( next ) ?) ;
233
+ let ready = step ! ( self . do_plan_expunge( ) ?) ;
234
+ let ready = step ! ( self . do_plan_add( ready . into_next ( ) ) ?) ;
235
+ let ready = step ! ( self . do_plan_decommission( ready . into_next ( ) ) ?) ;
236
+ let ready = step ! ( self . do_plan_mgs_updates( ready . into_next ( ) ) ) ;
237
+ let ready = step ! ( self . do_plan_zone_updates( ready . into_next ( ) ) ?) ;
238
+ step ! ( self . do_plan_cockroachdb_settings( ready . into_next ( ) ) ?) ;
221
239
unreachable ! ( "planning is complete!" ) ;
222
240
}
223
241
224
242
fn do_plan_decommission (
225
243
& mut self ,
226
- prev : AddStep ,
244
+ ready : DecommissionStep ,
227
245
) -> Result < UpdateStepResult < DecommissionStep > , Error > {
228
246
// Check for any sleds that are currently commissioned but can be
229
247
// decommissioned. Our gates for decommissioning are:
@@ -307,7 +325,7 @@ impl<'a> Planner<'a> {
307
325
}
308
326
}
309
327
310
- Ok ( UpdateStepResult :: continue_to_next_step ( prev ) )
328
+ Ok ( UpdateStepResult :: continue_to_next_step ( ready ) )
311
329
}
312
330
313
331
fn do_plan_decommission_expunged_disks_for_in_service_sled (
@@ -565,7 +583,7 @@ impl<'a> Planner<'a> {
565
583
566
584
fn do_plan_add (
567
585
& mut self ,
568
- prev : ExpungeStep ,
586
+ ready : AddStep ,
569
587
) -> Result < UpdateStepResult < AddStep > , Error > {
570
588
// Internal DNS is a prerequisite for bringing up all other zones. At
571
589
// this point, we assume that internal DNS (as a service) is already
@@ -753,7 +771,7 @@ impl<'a> Planner<'a> {
753
771
// ensure that all sleds have the datasets they need to have.
754
772
self . do_plan_datasets ( ) ?;
755
773
756
- Ok ( UpdateStepResult :: continue_to_next_step ( prev ) )
774
+ Ok ( UpdateStepResult :: continue_to_next_step ( ready ) )
757
775
}
758
776
759
777
fn do_plan_datasets ( & mut self ) -> Result < ( ) , Error > {
@@ -1014,7 +1032,7 @@ impl<'a> Planner<'a> {
1014
1032
/// date.
1015
1033
fn do_plan_mgs_updates (
1016
1034
& mut self ,
1017
- prev : DecommissionStep ,
1035
+ ready : MgsUpdatesStep ,
1018
1036
) -> UpdateStepResult < MgsUpdatesStep > {
1019
1037
// Determine which baseboards we will consider updating.
1020
1038
//
@@ -1063,7 +1081,7 @@ impl<'a> Planner<'a> {
1063
1081
// TODO This is not quite right. See oxidecomputer/omicron#8285.
1064
1082
self . blueprint . pending_mgs_updates_replace_all ( next. clone ( ) ) ;
1065
1083
if next. is_empty ( ) {
1066
- UpdateStepResult :: continue_to_next_step ( prev )
1084
+ UpdateStepResult :: continue_to_next_step ( ready )
1067
1085
} else {
1068
1086
UpdateStepResult :: waiting ( vec ! [ WaitCondition :: MgsUpdates {
1069
1087
pending: next. clone( ) ,
@@ -1074,7 +1092,7 @@ impl<'a> Planner<'a> {
1074
1092
/// Update at most one existing zone to use a new image source.
1075
1093
fn do_plan_zone_updates (
1076
1094
& mut self ,
1077
- prev : MgsUpdatesStep ,
1095
+ ready : UpdateZonesStep ,
1078
1096
) -> Result < UpdateStepResult < UpdateZonesStep > , Error > {
1079
1097
// We are only interested in non-decommissioned sleds.
1080
1098
let sleds = self
@@ -1133,7 +1151,7 @@ impl<'a> Planner<'a> {
1133
1151
}
1134
1152
1135
1153
info ! ( self . log, "all zones up-to-date" ) ;
1136
- Ok ( UpdateStepResult :: continue_to_next_step ( prev ) )
1154
+ Ok ( UpdateStepResult :: continue_to_next_step ( ready ) )
1137
1155
}
1138
1156
1139
1157
/// Update a zone to use a new image source, either in-place or by
@@ -1221,7 +1239,7 @@ impl<'a> Planner<'a> {
1221
1239
1222
1240
fn do_plan_cockroachdb_settings (
1223
1241
& mut self ,
1224
- prev : UpdateZonesStep ,
1242
+ ready : CockroachDbSettingsStep ,
1225
1243
) -> Result < UpdateStepResult < CockroachDbSettingsStep > , Error > {
1226
1244
// Figure out what we should set the CockroachDB "preserve downgrade
1227
1245
// option" setting to based on the planning input.
@@ -1315,7 +1333,7 @@ impl<'a> Planner<'a> {
1315
1333
//
1316
1334
// https://www.cockroachlabs.com/docs/stable/cluster-settings#change-a-cluster-setting
1317
1335
1318
- Ok ( UpdateStepResult :: planning_complete ( prev . into_next ( ) ) )
1336
+ Ok ( UpdateStepResult :: planning_complete ( ready ) )
1319
1337
}
1320
1338
}
1321
1339
0 commit comments