@@ -78,57 +78,52 @@ impl Host {
7878
7979 let ( tx_offset, durable_offset, json) = self
8080 . host_controller
81- . using_database (
82- database,
83- self . replica_id ,
84- move |db| -> axum:: response:: Result < _ , ( StatusCode , String ) > {
85- tracing:: info!( sql = body) ;
86-
87- // We need a header for query results
88- let mut header = vec ! [ ] ;
89-
90- let sql_start = std:: time:: Instant :: now ( ) ;
91- let sql_span =
92- tracing:: trace_span!( "execute_sql" , total_duration = tracing:: field:: Empty , ) . entered ( ) ;
93-
94- let result = sql:: execute:: run (
95- // Returns an empty result set for mutations
96- db,
97- & body,
98- auth,
99- Some ( & module_host. info ( ) . subscriptions ) ,
100- & mut header,
101- )
102- . map_err ( |e| {
103- log:: warn!( "{e}" ) ;
104- if let Some ( auth_err) = e. get_auth_error ( ) {
105- ( StatusCode :: UNAUTHORIZED , auth_err. to_string ( ) )
106- } else {
107- ( StatusCode :: BAD_REQUEST , e. to_string ( ) )
108- }
109- } ) ?;
110-
111- let total_duration = sql_start. elapsed ( ) ;
112- sql_span. record ( "total_duration" , tracing:: field:: debug ( total_duration) ) ;
113-
114- // Turn the header into a `ProductType`
115- let schema = header
116- . into_iter ( )
117- . map ( |( col_name, col_type) | ProductTypeElement :: new ( col_type, Some ( col_name) ) )
118- . collect ( ) ;
119-
120- Ok ( (
121- result. tx_offset ,
122- db. durable_tx_offset ( ) ,
123- vec ! [ SqlStmtResult {
124- schema,
125- rows: result. rows,
126- total_duration_micros: total_duration. as_micros( ) as u64 ,
127- stats: SqlStmtStats :: from_metrics( & result. metrics) ,
128- } ] ,
129- ) )
130- } ,
131- )
81+ . using_database ( database, self . replica_id , move |db| async move {
82+ tracing:: info!( sql = body) ;
83+ let mut header = vec ! [ ] ;
84+ let sql_start = std:: time:: Instant :: now ( ) ;
85+ let sql_span = tracing:: trace_span!( "execute_sql" , total_duration = tracing:: field:: Empty , ) ;
86+ let _guard = sql_span. enter ( ) ;
87+
88+ let result = sql:: execute:: run (
89+ & db,
90+ & body,
91+ auth,
92+ Some ( & module_host. info . subscriptions ) ,
93+ Some ( & module_host) ,
94+ auth. caller ,
95+ & mut header,
96+ )
97+ . await
98+ . map_err ( |e| {
99+ log:: warn!( "{e}" ) ;
100+ if let Some ( auth_err) = e. get_auth_error ( ) {
101+ ( StatusCode :: UNAUTHORIZED , auth_err. to_string ( ) )
102+ } else {
103+ ( StatusCode :: BAD_REQUEST , e. to_string ( ) )
104+ }
105+ } ) ?;
106+
107+ let total_duration = sql_start. elapsed ( ) ;
108+ drop ( _guard) ;
109+ sql_span. record ( "total_duration" , tracing:: field:: debug ( total_duration) ) ;
110+
111+ let schema = header
112+ . into_iter ( )
113+ . map ( |( col_name, col_type) | ProductTypeElement :: new ( col_type, Some ( col_name) ) )
114+ . collect ( ) ;
115+
116+ Ok :: < _ , ( StatusCode , String ) > ( (
117+ result. tx_offset ,
118+ db. durable_tx_offset ( ) ,
119+ vec ! [ SqlStmtResult {
120+ schema,
121+ rows: result. rows,
122+ total_duration_micros: total_duration. as_micros( ) as u64 ,
123+ stats: SqlStmtStats :: from_metrics( & result. metrics) ,
124+ } ] ,
125+ ) )
126+ } )
132127 . await
133128 . map_err ( log_and_500) ??;
134129
@@ -154,7 +149,6 @@ impl Host {
154149 . await
155150 }
156151}
157-
158152/// Parameters for publishing a database.
159153///
160154/// See [`ControlStateDelegate::publish_database`].
0 commit comments