File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -2449,6 +2449,9 @@ async fn test_subtransaction_failure_rolls_back_table_creation(
2449
2449
tx. rollback_subtransaction ( tokens) ?;
2450
2450
} ;
2451
2451
assert ! ( !TableModel :: new( & mut tx) . table_exists( TableNamespace :: test_user( ) , & table_name) ) ;
2452
+ // Regression test: take_stats used to panic.
2453
+ let stats = tx. take_stats ( ) ;
2454
+ assert ! ( stats. contains_key( & "_unknown" . parse( ) ?) ) ;
2452
2455
db. commit ( tx) . await ?;
2453
2456
let mut tx = db. begin ( Identity :: system ( ) ) . await ?;
2454
2457
assert ! ( !TableModel :: new( & mut tx) . table_exists( TableNamespace :: test_user( ) , & table_name) ) ;
Original file line number Diff line number Diff line change @@ -676,9 +676,22 @@ impl<RT: Runtime> Transaction<RT> {
676
676
. into_iter ( )
677
677
. map ( |( tablet, stats) | {
678
678
(
679
- self . table_mapping ( )
680
- . tablet_name ( tablet)
681
- . expect ( "tablet should exist" ) ,
679
+ match self . table_mapping ( ) . tablet_name ( tablet) {
680
+ Ok ( name) => name,
681
+ Err ( _) => {
682
+ // This is unusual, but possible if the tablet was created in a
683
+ // subtransaction that was rolled back. Such a tablet never gets
684
+ // created, but might still have usage stats.
685
+ tracing:: warn!( "Tablet {tablet} does not exist" ) ;
686
+ // It's fine to return "_unknown" here because nothing requires
687
+ // these to correspond to an actual table.
688
+ //
689
+ // We use "_unknown" to avoid colliding with valid user table names.
690
+ "_unknown"
691
+ . parse ( )
692
+ . expect ( "'_unknown' should be a valid table name" )
693
+ } ,
694
+ } ,
682
695
stats,
683
696
)
684
697
} )
You can’t perform that action at this time.
0 commit comments