File tree Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -621,6 +621,14 @@ impl Nexus {
621
621
}
622
622
}
623
623
624
+ // Waits for Nexus to determine whether sagas are supposed to be quiesced
625
+ //
626
+ // This is used by the test suite because most tests assume that sagas are
627
+ // operational as soon as they start.
628
+ pub ( crate ) async fn wait_for_saga_determination ( & self ) {
629
+ self . quiesce . sagas ( ) . wait_for_determination ( ) . await ;
630
+ }
631
+
624
632
pub ( crate ) async fn external_tls_config (
625
633
& self ,
626
634
tls_enabled : bool ,
Original file line number Diff line number Diff line change @@ -92,13 +92,13 @@ impl NexusQuiesceHandle {
92
92
}
93
93
} ) ;
94
94
95
+ // Immediately (synchronously) update the saga quiesce status. It's
96
+ // okay to do this even if there wasn't a change.
97
+ self . sagas . set_quiescing ( quiescing) ;
98
+
95
99
if changed && quiescing {
96
- // Immediately quiesce sagas.
97
- self . sagas . set_quiescing ( quiescing) ;
98
100
// Asynchronously complete the rest of the quiesce process.
99
- if quiescing {
100
- tokio:: spawn ( do_quiesce ( self . clone ( ) ) ) ;
101
- }
101
+ tokio:: spawn ( do_quiesce ( self . clone ( ) ) ) ;
102
102
}
103
103
}
104
104
}
Original file line number Diff line number Diff line change @@ -138,6 +138,15 @@ impl Server {
138
138
// the external server we're about to start.
139
139
apictx. context . nexus . await_ip_allowlist_plumbing ( ) . await ;
140
140
141
+ // Wait until Nexus has determined if sagas are supposed to be quiesced.
142
+ // This is not strictly necessary. The goal here is to prevent 503
143
+ // errors to clients that reach this Nexus while it's starting up and
144
+ // before it's figured out that it doesn't need to quiesce. The risk of
145
+ // doing this is that Nexus gets stuck here, but that should only happen
146
+ // if it's unable to load the current blueprint, in which case
147
+ // something's pretty wrong and it's likely pretty stuck anyway.
148
+ apictx. context . nexus . wait_for_saga_determination ( ) . await ;
149
+
141
150
// Launch the external server.
142
151
let tls_config = apictx
143
152
. context
@@ -332,6 +341,16 @@ impl nexus_test_interface::NexusServer for Server {
332
341
. await
333
342
. expect ( "Could not initialize rack" ) ;
334
343
344
+ // Now that we have a blueprint, determination of whether sagas are
345
+ // quiesced can complete. Wait for that so that tests can assume they
346
+ // can immediately kick off sagas.
347
+ internal_server
348
+ . apictx
349
+ . context
350
+ . nexus
351
+ . wait_for_saga_determination ( )
352
+ . await ;
353
+
335
354
// Start the Nexus external API.
336
355
Server :: start ( internal_server) . await . unwrap ( )
337
356
}
Original file line number Diff line number Diff line change @@ -218,6 +218,18 @@ impl SagaQuiesceHandle {
218
218
let _ = self . inner . subscribe ( ) . wait_for ( |q| q. is_fully_drained ( ) ) . await ;
219
219
}
220
220
221
+ /// Wait for the initial determination to be made about whether sagas are
222
+ /// allowed or not.
223
+ pub async fn wait_for_determination ( & self ) {
224
+ let _ = self
225
+ . inner
226
+ . subscribe ( )
227
+ . wait_for ( |q| {
228
+ q. new_sagas_allowed != SagasAllowed :: DisallowedUnknown
229
+ } )
230
+ . await ;
231
+ }
232
+
221
233
/// Returns information about running sagas (involves a clone)
222
234
pub fn sagas_pending ( & self ) -> IdOrdMap < PendingSagaInfo > {
223
235
self . inner . borrow ( ) . sagas_pending . clone ( )
You can’t perform that action at this time.
0 commit comments