@@ -1031,6 +1031,7 @@ impl DataStore {
1031
1031
nclickhouse_cluster_configs,
1032
1032
nclickhouse_keepers,
1033
1033
nclickhouse_servers,
1034
+ noximeter_policy,
1034
1035
) = self . transaction_retry_wrapper ( "blueprint_delete" )
1035
1036
. transaction ( & conn, |conn| {
1036
1037
let err = err. clone ( ) ;
@@ -1151,6 +1152,17 @@ impl DataStore {
1151
1152
. await ?
1152
1153
} ;
1153
1154
1155
+ let noximeter_policy = {
1156
+ use nexus_db_schema:: schema::
1157
+ bp_oximeter_read_policy:: dsl;
1158
+ diesel:: delete ( dsl:: bp_oximeter_read_policy
1159
+ . filter ( dsl:: blueprint_id. eq (
1160
+ to_db_typed_uuid ( blueprint_id) ) ) ,
1161
+ )
1162
+ . execute_async ( & conn)
1163
+ . await ?
1164
+ } ;
1165
+
1154
1166
Ok ( (
1155
1167
nblueprints,
1156
1168
nsled_metadata,
@@ -1161,6 +1173,7 @@ impl DataStore {
1161
1173
nclickhouse_cluster_configs,
1162
1174
nclickhouse_keepers,
1163
1175
nclickhouse_servers,
1176
+ noximeter_policy,
1164
1177
) )
1165
1178
}
1166
1179
} )
@@ -1180,7 +1193,8 @@ impl DataStore {
1180
1193
"nnics" => nnics,
1181
1194
"nclickhouse_cluster_configs" => nclickhouse_cluster_configs,
1182
1195
"nclickhouse_keepers" => nclickhouse_keepers,
1183
- "nclickhouse_servers" => nclickhouse_servers
1196
+ "nclickhouse_servers" => nclickhouse_servers,
1197
+ "noximeter_policy" => noximeter_policy,
1184
1198
) ;
1185
1199
1186
1200
Ok ( ( ) )
@@ -1951,6 +1965,7 @@ mod tests {
1951
1965
use rand:: Rng ;
1952
1966
use rand:: thread_rng;
1953
1967
use slog:: Logger ;
1968
+ use std:: collections:: BTreeSet ;
1954
1969
use std:: mem;
1955
1970
use std:: net:: IpAddr ;
1956
1971
use std:: net:: Ipv4Addr ;
@@ -1999,20 +2014,64 @@ mod tests {
1999
2014
} } ;
2000
2015
}
2001
2016
2017
+ // These tables start with `bp_` but do not represent the contents of a
2018
+ // specific blueprint. It should be uncommon to add things to this
2019
+ // list.
2020
+ let tables_ignored: BTreeSet < _ > = [ "bp_target" ] . into_iter ( ) . collect ( ) ;
2021
+
2022
+ let mut tables_checked = BTreeSet :: new ( ) ;
2002
2023
for ( table_name, result) in [
2003
2024
query_count ! ( blueprint, id) ,
2004
2025
query_count ! ( bp_sled_metadata, blueprint_id) ,
2005
2026
query_count ! ( bp_omicron_dataset, blueprint_id) ,
2006
2027
query_count ! ( bp_omicron_physical_disk, blueprint_id) ,
2007
2028
query_count ! ( bp_omicron_zone, blueprint_id) ,
2008
2029
query_count ! ( bp_omicron_zone_nic, blueprint_id) ,
2030
+ query_count ! ( bp_clickhouse_cluster_config, blueprint_id) ,
2031
+ query_count ! ( bp_clickhouse_keeper_zone_id_to_node_id, blueprint_id) ,
2032
+ query_count ! ( bp_clickhouse_server_zone_id_to_node_id, blueprint_id) ,
2033
+ query_count ! ( bp_oximeter_read_policy, blueprint_id) ,
2009
2034
] {
2010
2035
let count: i64 = result. unwrap ( ) ;
2011
2036
assert_eq ! (
2012
2037
count, 0 ,
2013
2038
"nonzero row count for blueprint \
2014
2039
{blueprint_id} in table {table_name}"
2015
2040
) ;
2041
+ tables_checked. insert ( table_name) ;
2042
+ }
2043
+
2044
+ // Look for likely blueprint-related tables that we didn't check.
2045
+ let mut query = QueryBuilder :: new ( ) ;
2046
+ query. sql (
2047
+ "SELECT table_name \
2048
+ FROM information_schema.tables \
2049
+ WHERE table_name LIKE 'bp\\ _%'",
2050
+ ) ;
2051
+ let tables_unchecked: Vec < String > = query
2052
+ . query :: < diesel:: sql_types:: Text > ( )
2053
+ . load_async ( & * conn)
2054
+ . await
2055
+ . expect ( "Failed to query information_schema for tables" )
2056
+ . into_iter ( )
2057
+ . filter ( |f : & String | {
2058
+ let t = f. as_str ( ) ;
2059
+ !tables_ignored. contains ( t) && !tables_checked. contains ( t)
2060
+ } )
2061
+ . collect ( ) ;
2062
+ if !tables_unchecked. is_empty ( ) {
2063
+ // If you see this message, you probably added a blueprint table
2064
+ // whose name started with `bp_*`. Add it to the block above so
2065
+ // that this function checks whether deleting a blueprint deletes
2066
+ // rows from that table. (You may also find you need to update
2067
+ // blueprint_delete() to actually delete said rows.)
2068
+ panic ! (
2069
+ "found table(s) that look related to blueprints, but \
2070
+ aren't covered by ensure_blueprint_fully_deleted(). \
2071
+ Please add them to that function!\n
2072
+ Found: {}" ,
2073
+ tables_unchecked. join( ", " )
2074
+ ) ;
2016
2075
}
2017
2076
}
2018
2077
0 commit comments