File tree Expand file tree Collapse file tree 4 files changed +32
-35
lines changed
db-queries/src/db/datastore Expand file tree Collapse file tree 4 files changed +32
-35
lines changed Original file line number Diff line number Diff line change @@ -300,33 +300,18 @@ impl DatastoreSetupAction {
300
300
}
301
301
302
302
impl DataStore {
303
- // Returns the active Nexuses
304
- pub async fn get_active_db_metadata_nexus (
303
+ /// Returns [`DbMetadataNexus`] records in any of the supplied states.
304
+ pub async fn get_db_metadata_nexus_in_state (
305
305
& self ,
306
306
opctx : & OpContext ,
307
+ states : & [ DbMetadataNexusState ] ,
307
308
) -> Result < Vec < DbMetadataNexus > , Error > {
308
309
use nexus_db_schema:: schema:: db_metadata_nexus:: dsl;
309
310
310
311
opctx. authorize ( authz:: Action :: Read , & authz:: FLEET ) . await ?;
311
312
312
313
dsl:: db_metadata_nexus
313
- . filter ( dsl:: state. eq ( DbMetadataNexusState :: Active ) )
314
- . load_async ( & * self . pool_connection_authorized ( & opctx) . await ?)
315
- . await
316
- . map_err ( |e| public_error_from_diesel ( e, ErrorHandler :: Server ) )
317
- }
318
-
319
- // Returns the 'not yet' Nexuses
320
- pub async fn get_not_yet_db_metadata_nexus (
321
- & self ,
322
- opctx : & OpContext ,
323
- ) -> Result < Vec < DbMetadataNexus > , Error > {
324
- use nexus_db_schema:: schema:: db_metadata_nexus:: dsl;
325
-
326
- opctx. authorize ( authz:: Action :: Read , & authz:: FLEET ) . await ?;
327
-
328
- dsl:: db_metadata_nexus
329
- . filter ( dsl:: state. eq ( DbMetadataNexusState :: NotYet ) )
314
+ . filter ( dsl:: state. eq_any ( states. to_vec ( ) ) )
330
315
. load_async ( & * self . pool_connection_authorized ( & opctx) . await ?)
331
316
. await
332
317
. map_err ( |e| public_error_from_diesel ( e, ErrorHandler :: Server ) )
Original file line number Diff line number Diff line change 5
5
//! Manages deployment of records into the database.
6
6
7
7
use anyhow:: anyhow;
8
+ use nexus_db_model:: DbMetadataNexusState ;
8
9
use nexus_db_queries:: context:: OpContext ;
9
10
use nexus_db_queries:: db:: DataStore ;
10
11
use nexus_types:: deployment:: Blueprint ;
@@ -23,7 +24,7 @@ pub(crate) async fn deploy_db_metadata_nexus_records(
23
24
// can lag behind it if we are one of those Nexuses running after quiescing
24
25
// has started.
25
26
let active_nexus_zones = datastore
26
- . get_active_db_metadata_nexus ( opctx)
27
+ . get_db_metadata_nexus_in_state ( opctx, & [ DbMetadataNexusState :: Active ] )
27
28
. await ?
28
29
. into_iter ( )
29
30
. map ( |z| z. nexus_id ( ) )
Original file line number Diff line number Diff line change @@ -313,6 +313,7 @@ mod test {
313
313
use internal_dns_types:: names:: BOUNDARY_NTP_DNS_NAME ;
314
314
use internal_dns_types:: names:: DNS_ZONE ;
315
315
use internal_dns_types:: names:: ServiceName ;
316
+ use nexus_db_model:: DbMetadataNexusState ;
316
317
use nexus_db_model:: DnsGroup ;
317
318
use nexus_db_model:: Silo ;
318
319
use nexus_db_queries:: authn;
@@ -1503,7 +1504,10 @@ mod test {
1503
1504
let ip_pool_range_rows =
1504
1505
fetch_all_service_ip_pool_ranges ( & datastore, & opctx) . await ;
1505
1506
let active_nexus_zones = datastore
1506
- . get_active_db_metadata_nexus ( & opctx)
1507
+ . get_db_metadata_nexus_in_state (
1508
+ & opctx,
1509
+ & [ DbMetadataNexusState :: Active ] ,
1510
+ )
1507
1511
. await
1508
1512
. internal_context ( "fetching active nexuses" )
1509
1513
. unwrap ( )
Original file line number Diff line number Diff line change 6
6
7
7
use anyhow:: Context ;
8
8
use futures:: StreamExt ;
9
+ use nexus_db_model:: DbMetadataNexusState ;
9
10
use nexus_db_model:: DnsGroup ;
10
11
use nexus_db_model:: Generation ;
11
12
use nexus_db_queries:: context:: OpContext ;
@@ -204,20 +205,26 @@ impl PlanningInputFromDb<'_> {
204
205
. await
205
206
. internal_context ( "fetching oximeter read policy" ) ?;
206
207
207
- let active_nexus_zones = datastore
208
- . get_active_db_metadata_nexus ( opctx)
209
- . await
210
- . internal_context ( "fetching active nexuses" ) ?
211
- . into_iter ( )
212
- . map ( |z| z. nexus_id ( ) )
213
- . collect :: < Vec < _ > > ( ) ;
214
- let not_yet_nexus_zones = datastore
215
- . get_not_yet_db_metadata_nexus ( opctx)
216
- . await
217
- . internal_context ( "fetching 'not yet' nexuses" ) ?
218
- . into_iter ( )
219
- . map ( |z| z. nexus_id ( ) )
220
- . collect :: < Vec < _ > > ( ) ;
208
+ let ( active_nexus_zones, not_yet_nexus_zones) : ( Vec < _ > , Vec < _ > ) =
209
+ datastore
210
+ . get_db_metadata_nexus_in_state (
211
+ opctx,
212
+ & [
213
+ DbMetadataNexusState :: Active ,
214
+ DbMetadataNexusState :: NotYet ,
215
+ ] ,
216
+ )
217
+ . await
218
+ . internal_context ( "fetching db_metdata_nexus records" ) ?
219
+ . into_iter ( )
220
+ . partition ( |nexus| {
221
+ nexus. state ( ) == DbMetadataNexusState :: Active
222
+ } ) ;
223
+
224
+ let active_nexus_zones =
225
+ active_nexus_zones. into_iter ( ) . map ( |n| n. nexus_id ( ) ) . collect ( ) ;
226
+ let not_yet_nexus_zones =
227
+ not_yet_nexus_zones. into_iter ( ) . map ( |n| n. nexus_id ( ) ) . collect ( ) ;
221
228
222
229
let planning_input = PlanningInputFromDb {
223
230
sled_rows : & sled_rows,
You can’t perform that action at this time.
0 commit comments