@@ -40,6 +40,7 @@ use nexus_db_model::InvConfigReconcilerStatus;
4040use nexus_db_model:: InvConfigReconcilerStatusKind ;
4141use nexus_db_model:: InvDataset ;
4242use nexus_db_model:: InvHostPhase1FlashHash ;
43+ use nexus_db_model:: InvInternalDns ;
4344use nexus_db_model:: InvLastReconciliationDatasetResult ;
4445use nexus_db_model:: InvLastReconciliationDiskResult ;
4546use nexus_db_model:: InvLastReconciliationOrphanedDataset ;
@@ -96,6 +97,7 @@ use nexus_sled_agent_shared::inventory::ZoneManifestNonBootInventory;
9697use nexus_types:: inventory:: BaseboardId ;
9798use nexus_types:: inventory:: CockroachStatus ;
9899use nexus_types:: inventory:: Collection ;
100+ use nexus_types:: inventory:: InternalDnsGenerationStatus ;
99101use nexus_types:: inventory:: PhysicalDiskFirmware ;
100102use nexus_types:: inventory:: SledAgent ;
101103use nexus_types:: inventory:: TimeSync ;
@@ -398,6 +400,13 @@ impl DataStore {
398400 . collect :: < Result < Vec < _ > , _ > > ( )
399401 . map_err ( |e| Error :: internal_error ( & e. to_string ( ) ) ) ?;
400402
403+ let inv_internal_dns_records: Vec < InvInternalDns > = collection
404+ . internal_dns_generation_status
405+ . iter ( )
406+ . map ( |status| InvInternalDns :: new ( collection_id, status) )
407+ . collect :: < Result < Vec < _ > , _ > > ( )
408+ . map_err ( |e| Error :: internal_error ( & e. to_string ( ) ) ) ?;
409+
401410 // This implementation inserts all records associated with the
402411 // collection in one transaction. This is primarily for simplicity. It
403412 // means we don't have to worry about other readers seeing a
@@ -1516,6 +1525,15 @@ impl DataStore {
15161525 . await ?;
15171526 }
15181527
1528+ // Insert the internal DNS generation status we've observed
1529+ if !inv_internal_dns_records. is_empty ( ) {
1530+ use nexus_db_schema:: schema:: inv_internal_dns:: dsl;
1531+ diesel:: insert_into ( dsl:: inv_internal_dns)
1532+ . values ( inv_internal_dns_records)
1533+ . execute_async ( & conn)
1534+ . await ?;
1535+ }
1536+
15191537 // Finally, insert the list of errors.
15201538 {
15211539 use nexus_db_schema:: schema:: inv_collection_error:: dsl as errors_dsl;
@@ -1807,6 +1825,7 @@ impl DataStore {
18071825 nclickhouse_keeper_membership : usize ,
18081826 ncockroach_status : usize ,
18091827 nntp_timesync : usize ,
1828+ ninternal_dns : usize ,
18101829 }
18111830
18121831 let NumRowsDeleted {
@@ -1839,6 +1858,7 @@ impl DataStore {
18391858 nclickhouse_keeper_membership,
18401859 ncockroach_status,
18411860 nntp_timesync,
1861+ ninternal_dns,
18421862 } =
18431863 self . transaction_retry_wrapper ( "inventory_delete_collection" )
18441864 . transaction ( & conn, |conn| async move {
@@ -2117,6 +2137,18 @@ impl DataStore {
21172137 . await ?
21182138 } ;
21192139
2140+ // Remove rows for internal DNS
2141+ let ninternal_dns = {
2142+ use nexus_db_schema:: schema:: inv_internal_dns:: dsl;
2143+ diesel:: delete (
2144+ dsl:: inv_internal_dns. filter (
2145+ dsl:: inv_collection_id. eq ( db_collection_id) ,
2146+ ) ,
2147+ )
2148+ . execute_async ( & conn)
2149+ . await ?
2150+ } ;
2151+
21202152 Ok ( NumRowsDeleted {
21212153 ncollections,
21222154 nsps,
@@ -2147,6 +2179,7 @@ impl DataStore {
21472179 nclickhouse_keeper_membership,
21482180 ncockroach_status,
21492181 nntp_timesync,
2182+ ninternal_dns,
21502183 } )
21512184 } )
21522185 . await
@@ -2189,6 +2222,7 @@ impl DataStore {
21892222 "nclickhouse_keeper_membership" => nclickhouse_keeper_membership,
21902223 "ncockroach_status" => ncockroach_status,
21912224 "nntp_timesync" => nntp_timesync,
2225+ "ninternal_dns" => ninternal_dns,
21922226 ) ;
21932227
21942228 Ok ( ( ) )
@@ -3638,6 +3672,27 @@ impl DataStore {
36383672 . collect :: < IdOrdMap < _ > > ( )
36393673 } ;
36403674
3675+ // Load internal DNS generation status
3676+ let internal_dns_generation_status: IdOrdMap <
3677+ InternalDnsGenerationStatus ,
3678+ > = {
3679+ use nexus_db_schema:: schema:: inv_internal_dns:: dsl;
3680+
3681+ let records: Vec < InvInternalDns > = dsl:: inv_internal_dns
3682+ . filter ( dsl:: inv_collection_id. eq ( db_id) )
3683+ . select ( InvInternalDns :: as_select ( ) )
3684+ . load_async ( & * conn)
3685+ . await
3686+ . map_err ( |e| {
3687+ public_error_from_diesel ( e, ErrorHandler :: Server )
3688+ } ) ?;
3689+
3690+ records
3691+ . into_iter ( )
3692+ . map ( |record| InternalDnsGenerationStatus :: from ( record) )
3693+ . collect :: < IdOrdMap < _ > > ( )
3694+ } ;
3695+
36413696 // Finally, build up the sled-agent map using the sled agent and
36423697 // omicron zone rows. A for loop is easier to understand than into_iter
36433698 // + filter_map + return Result + collect.
@@ -3894,6 +3949,7 @@ impl DataStore {
38943949 clickhouse_keeper_cluster_membership,
38953950 cockroach_status,
38963951 ntp_timesync,
3952+ internal_dns_generation_status,
38973953 } )
38983954 }
38993955}
0 commit comments