@@ -42,6 +42,7 @@ use nexus_db_model::InvLastReconciliationDatasetResult;
42
42
use nexus_db_model:: InvLastReconciliationDiskResult ;
43
43
use nexus_db_model:: InvLastReconciliationOrphanedDataset ;
44
44
use nexus_db_model:: InvLastReconciliationZoneResult ;
45
+ use nexus_db_model:: InvNtpTimesync ;
45
46
use nexus_db_model:: InvNvmeDiskFirmware ;
46
47
use nexus_db_model:: InvOmicronSledConfig ;
47
48
use nexus_db_model:: InvOmicronSledConfigDataset ;
@@ -93,6 +94,7 @@ use nexus_types::inventory::CockroachStatus;
93
94
use nexus_types:: inventory:: Collection ;
94
95
use nexus_types:: inventory:: PhysicalDiskFirmware ;
95
96
use nexus_types:: inventory:: SledAgent ;
97
+ use nexus_types:: inventory:: TimeSync ;
96
98
use omicron_cockroach_metrics:: NodeId as CockroachNodeId ;
97
99
use omicron_common:: api:: external:: Error ;
98
100
use omicron_common:: api:: external:: InternalContext ;
@@ -385,6 +387,13 @@ impl DataStore {
385
387
. collect :: < Result < Vec < _ > , _ > > ( )
386
388
. map_err ( |e| Error :: internal_error ( & e. to_string ( ) ) ) ?;
387
389
390
+ let inv_ntp_timesync_records: Vec < InvNtpTimesync > = collection
391
+ . ntp_timesync
392
+ . iter ( )
393
+ . map ( |timesync| InvNtpTimesync :: new ( collection_id, timesync) )
394
+ . collect :: < Result < Vec < _ > , _ > > ( )
395
+ . map_err ( |e| Error :: internal_error ( & e. to_string ( ) ) ) ?;
396
+
388
397
// This implementation inserts all records associated with the
389
398
// collection in one transaction. This is primarily for simplicity. It
390
399
// means we don't have to worry about other readers seeing a
@@ -1424,6 +1433,14 @@ impl DataStore {
1424
1433
. await ?;
1425
1434
}
1426
1435
1436
+ // Insert the NTP info we've observed
1437
+ if !inv_ntp_timesync_records. is_empty ( ) {
1438
+ use nexus_db_schema:: schema:: inv_ntp_timesync:: dsl;
1439
+ diesel:: insert_into ( dsl:: inv_ntp_timesync)
1440
+ . values ( inv_ntp_timesync_records)
1441
+ . execute_async ( & conn)
1442
+ . await ?;
1443
+ }
1427
1444
1428
1445
// Finally, insert the list of errors.
1429
1446
{
@@ -1714,6 +1731,7 @@ impl DataStore {
1714
1731
nerrors : usize ,
1715
1732
nclickhouse_keeper_membership : usize ,
1716
1733
ncockroach_status : usize ,
1734
+ nntp_timesync : usize ,
1717
1735
}
1718
1736
1719
1737
let NumRowsDeleted {
@@ -1744,6 +1762,7 @@ impl DataStore {
1744
1762
nerrors,
1745
1763
nclickhouse_keeper_membership,
1746
1764
ncockroach_status,
1765
+ nntp_timesync,
1747
1766
} =
1748
1767
self . transaction_retry_wrapper ( "inventory_delete_collection" )
1749
1768
. transaction ( & conn, |conn| async move {
@@ -2000,6 +2019,17 @@ impl DataStore {
2000
2019
. execute_async ( & conn)
2001
2020
. await ?
2002
2021
} ;
2022
+ // Remove rows for NTP timesync
2023
+ let nntp_timesync = {
2024
+ use nexus_db_schema:: schema:: inv_ntp_timesync:: dsl;
2025
+ diesel:: delete (
2026
+ dsl:: inv_ntp_timesync. filter (
2027
+ dsl:: inv_collection_id. eq ( db_collection_id) ,
2028
+ ) ,
2029
+ )
2030
+ . execute_async ( & conn)
2031
+ . await ?
2032
+ } ;
2003
2033
2004
2034
Ok ( NumRowsDeleted {
2005
2035
ncollections,
@@ -2029,6 +2059,7 @@ impl DataStore {
2029
2059
nerrors,
2030
2060
nclickhouse_keeper_membership,
2031
2061
ncockroach_status,
2062
+ nntp_timesync,
2032
2063
} )
2033
2064
} )
2034
2065
. await
@@ -2069,6 +2100,7 @@ impl DataStore {
2069
2100
"nerrors" => nerrors,
2070
2101
"nclickhouse_keeper_membership" => nclickhouse_keeper_membership,
2071
2102
"ncockroach_status" => ncockroach_status,
2103
+ "nntp_timesync" => nntp_timesync,
2072
2104
) ;
2073
2105
2074
2106
Ok ( ( ) )
@@ -3435,6 +3467,25 @@ impl DataStore {
3435
3467
. collect :: < Result < BTreeMap < _ , _ > , Error > > ( ) ?
3436
3468
} ;
3437
3469
3470
+ // Load TimeSync statuses
3471
+ let ntp_timesync: IdOrdMap < TimeSync > = {
3472
+ use nexus_db_schema:: schema:: inv_ntp_timesync:: dsl;
3473
+
3474
+ let records: Vec < InvNtpTimesync > = dsl:: inv_ntp_timesync
3475
+ . filter ( dsl:: inv_collection_id. eq ( db_id) )
3476
+ . select ( InvNtpTimesync :: as_select ( ) )
3477
+ . load_async ( & * conn)
3478
+ . await
3479
+ . map_err ( |e| {
3480
+ public_error_from_diesel ( e, ErrorHandler :: Server )
3481
+ } ) ?;
3482
+
3483
+ records
3484
+ . into_iter ( )
3485
+ . map ( |record| TimeSync :: from ( record) )
3486
+ . collect :: < IdOrdMap < _ > > ( )
3487
+ } ;
3488
+
3438
3489
// Finally, build up the sled-agent map using the sled agent and
3439
3490
// omicron zone rows. A for loop is easier to understand than into_iter
3440
3491
// + filter_map + return Result + collect.
@@ -3681,6 +3732,7 @@ impl DataStore {
3681
3732
sled_agents,
3682
3733
clickhouse_keeper_cluster_membership,
3683
3734
cockroach_status,
3735
+ ntp_timesync,
3684
3736
} )
3685
3737
}
3686
3738
}
0 commit comments