@@ -180,7 +180,6 @@ where
180180 pub fn new (
181181 cfg : PersistConfig ,
182182 metrics : Arc < Metrics > ,
183- write_schemas : Schemas < K , V > ,
184183 gc : GarbageCollector < K , V , T , D > ,
185184 ) -> Self {
186185 let ( compact_req_sender, mut compact_req_receiver) = mpsc:: channel :: < (
@@ -242,14 +241,12 @@ where
242241 . queued_seconds
243242 . inc_by ( enqueued. elapsed ( ) . as_secs_f64 ( ) ) ;
244243
245- let write_schemas = write_schemas. clone ( ) ;
246-
247244 let compact_span =
248245 debug_span ! ( parent: None , "compact::apply" , shard_id=%machine. shard_id( ) ) ;
249246 compact_span. follows_from ( & Span :: current ( ) ) ;
250247 let gc = gc. clone ( ) ;
251248 mz_ore:: task:: spawn ( || "PersistCompactionWorker" , async move {
252- let res = Self :: compact_and_apply ( & machine, req, write_schemas )
249+ let res = Self :: compact_and_apply ( & machine, req)
253250 . instrument ( compact_span)
254251 . await ;
255252 if let Ok ( maintenance) = res {
@@ -328,7 +325,6 @@ where
328325 pub ( crate ) async fn compact_and_apply (
329326 machine : & Machine < K , V , T , D > ,
330327 req : CompactReq < T > ,
331- write_schemas : Schemas < K , V > ,
332328 ) -> Result < RoutineMaintenance , anyhow:: Error > {
333329 let metrics = Arc :: clone ( & machine. applier . metrics ) ;
334330 metrics. compaction . started . inc ( ) ;
@@ -349,38 +345,38 @@ where
349345 ) ;
350346 // always use most recent schema from all the Runs we're compacting to prevent Compactors
351347 // created before the schema was evolved, from trying to "de-evolve" a Part.
352- let compaction_schema_id = req
348+ let Some ( compaction_schema_id) = req
353349 . inputs
354350 . iter ( )
355351 . flat_map ( |batch| batch. batch . run_meta . iter ( ) )
356352 . filter_map ( |run_meta| run_meta. schema )
357353 // It's an invariant that SchemaIds are ordered.
358- . max ( ) ;
359- let maybe_compaction_schema = match compaction_schema_id {
360- Some ( id) => machine
361- . get_schema ( id)
362- . map ( |( key_schema, val_schema) | ( id, key_schema, val_schema) ) ,
363- None => None ,
354+ . max ( )
355+ else {
356+ metrics. compaction . schema_selection . no_schema . inc ( ) ;
357+ metrics. compaction . failed . inc ( ) ;
358+ return Err ( anyhow ! (
359+ "compacting {shard_id} and spine ids {spine_ids}: could not determine schema id from inputs" ,
360+ shard_id = req. shard_id,
361+ spine_ids = mz_ore:: str :: separated( ", " , req. inputs. iter( ) . map( |i| i. id) )
362+ ) ) ;
364363 } ;
365- let use_most_recent_schema = COMPACTION_USE_MOST_RECENT_SCHEMA . get ( & machine. applier . cfg ) ;
366-
367- let compaction_schema = match maybe_compaction_schema {
368- Some ( ( id, key_schema, val_schema) ) if use_most_recent_schema => {
369- metrics. compaction . schema_selection . recent_schema . inc ( ) ;
370- Schemas {
371- id : Some ( id) ,
372- key : Arc :: new ( key_schema) ,
373- val : Arc :: new ( val_schema) ,
374- }
375- }
376- Some ( _) => {
377- metrics. compaction . schema_selection . disabled . inc ( ) ;
378- write_schemas
379- }
380- None => {
381- metrics. compaction . schema_selection . no_schema . inc ( ) ;
382- write_schemas
383- }
364+ let Some ( ( key_schema, val_schema) ) = machine. get_schema ( compaction_schema_id) else {
365+ metrics. compaction . schema_selection . no_schema . inc ( ) ;
366+ metrics. compaction . failed . inc ( ) ;
367+ return Err ( anyhow ! (
368+ "compacting {shard_id} and spine ids {spine_ids}: schema id {compaction_schema_id} not present in machine state" ,
369+ shard_id = req. shard_id,
370+ spine_ids = mz_ore:: str :: separated( ", " , req. inputs. iter( ) . map( |i| i. id) )
371+ ) ) ;
372+ } ;
373+
374+ metrics. compaction . schema_selection . recent_schema . inc ( ) ;
375+
376+ let compaction_schema = Schemas {
377+ id : Some ( compaction_schema_id) ,
378+ key : Arc :: new ( key_schema) ,
379+ val : Arc :: new ( val_schema) ,
384380 } ;
385381
386382 trace ! (
0 commit comments