@@ -20,6 +20,7 @@ use std::time::Instant;
2020use common_base:: base:: tokio;
2121use common_base:: base:: tokio:: sync:: Mutex as TokioMutex ;
2222use common_base:: base:: tokio:: sync:: RwLock ;
23+ use common_base:: runtime:: GlobalQueryRuntime ;
2324use common_base:: runtime:: TrySpawn ;
2425use common_catalog:: table_context:: StageAttachment ;
2526use common_exception:: ErrorCode ;
@@ -278,28 +279,37 @@ impl HttpQuery {
278279 let query_id_clone = id. clone ( ) ;
279280
280281 let schema = ExecuteState :: get_schema ( & sql, ctx. clone ( ) ) . await ?;
281- ctx. try_spawn ( async move {
282- let state = state_clone. clone ( ) ;
283- if let Err ( e) =
284- ExecuteState :: try_start_query ( state, & sql, session, ctx_clone. clone ( ) , block_sender)
285- . await
286- {
287- InterpreterQueryLog :: fail_to_start ( ctx_clone. clone ( ) , e. clone ( ) ) ;
288- let state = ExecuteStopped {
289- stats : Progresses :: default ( ) ,
290- reason : Err ( e. clone ( ) ) ,
291- stop_time : Instant :: now ( ) ,
292- affect : ctx_clone. get_affect ( ) ,
293- } ;
294- tracing:: info!(
295- "http query {}, change state to Stopped, fail to start {:?}" ,
296- & query_id,
297- e
298- ) ;
299- Executor :: start_to_stop ( & state_clone, ExecuteState :: Stopped ( Box :: new ( state) ) ) . await ;
300- block_sender_closer. close ( ) ;
301- }
302- } ) ?;
282+ let http_query_runtime_instance = GlobalQueryRuntime :: instance ( ) ;
283+ http_query_runtime_instance
284+ . runtime ( )
285+ . try_spawn ( async move {
286+ let state = state_clone. clone ( ) ;
287+ if let Err ( e) = ExecuteState :: try_start_query (
288+ state,
289+ & sql,
290+ session,
291+ ctx_clone. clone ( ) ,
292+ block_sender,
293+ )
294+ . await
295+ {
296+ InterpreterQueryLog :: fail_to_start ( ctx_clone. clone ( ) , e. clone ( ) ) ;
297+ let state = ExecuteStopped {
298+ stats : Progresses :: default ( ) ,
299+ reason : Err ( e. clone ( ) ) ,
300+ stop_time : Instant :: now ( ) ,
301+ affect : ctx_clone. get_affect ( ) ,
302+ } ;
303+ tracing:: info!(
304+ "http query {}, change state to Stopped, fail to start {:?}" ,
305+ & query_id,
306+ e
307+ ) ;
308+ Executor :: start_to_stop ( & state_clone, ExecuteState :: Stopped ( Box :: new ( state) ) )
309+ . await ;
310+ block_sender_closer. close ( ) ;
311+ }
312+ } ) ?;
303313
304314 let format_settings = ctx. get_format_settings ( ) ?;
305315 let data = Arc :: new ( TokioMutex :: new ( PageManager :: new (
@@ -319,6 +329,7 @@ impl HttpQuery {
319329 config,
320330 expire_state : Arc :: new ( TokioMutex :: new ( ExpireState :: Working ) ) ,
321331 } ;
332+
322333 Ok ( Arc :: new ( query) )
323334 }
324335
0 commit comments