@@ -53,20 +53,20 @@ const HEADER_QUERY_ID: &str = "X-DATABEND-QUERY-ID";
53
53
const HEADER_QUERY_STATE : & str = "X-DATABEND-QUERY-STATE" ;
54
54
const HEADER_QUERY_PAGE_ROWS : & str = "X-DATABEND-QUERY-PAGE-ROWS" ;
55
55
56
- pub fn make_page_uri ( query_id : & str , page_no : usize ) -> String {
57
- format ! ( "/v1/query/{}/page/{}" , query_id, page_no)
56
+ pub fn make_page_uri ( query_id : & str , node_id : & str , page_no : usize ) -> String {
57
+ format ! ( "/v1/query/{}/{}/ page/{}" , query_id, node_id , page_no)
58
58
}
59
59
60
- pub fn make_state_uri ( query_id : & str ) -> String {
61
- format ! ( "/v1/query/{}" , query_id)
60
+ pub fn make_state_uri ( query_id : & str , node_id : & str ) -> String {
61
+ format ! ( "/v1/query/{}/{} " , query_id, node_id )
62
62
}
63
63
64
- pub fn make_final_uri ( query_id : & str ) -> String {
65
- format ! ( "/v1/query/{}/final" , query_id)
64
+ pub fn make_final_uri ( query_id : & str , node_id : & str ) -> String {
65
+ format ! ( "/v1/query/{}/{}/ final" , query_id, node_id )
66
66
}
67
67
68
- pub fn make_kill_uri ( query_id : & str ) -> String {
69
- format ! ( "/v1/query/{}/kill" , query_id)
68
+ pub fn make_kill_uri ( query_id : & str , node_id : & str ) -> String {
69
+ format ! ( "/v1/query/{}/{}/ kill" , query_id, node_id )
70
70
}
71
71
72
72
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
@@ -146,28 +146,31 @@ impl QueryResponse {
146
146
r : HttpQueryResponseInternal ,
147
147
is_final : bool ,
148
148
) -> impl IntoResponse {
149
+ let node_id = r. node_id . clone ( ) ;
149
150
let state = r. state . clone ( ) ;
150
151
let ( data, next_uri) = if is_final {
151
152
( JsonBlock :: empty ( ) , None )
152
153
} else {
153
154
match state. state {
154
155
ExecuteStateKind :: Running | ExecuteStateKind :: Starting => match r. data {
155
- None => ( JsonBlock :: empty ( ) , Some ( make_state_uri ( & id) ) ) ,
156
+ None => ( JsonBlock :: empty ( ) , Some ( make_state_uri ( & id, & r . node_id ) ) ) ,
156
157
Some ( d) => {
157
158
let uri = match d. next_page_no {
158
- Some ( n) => Some ( make_page_uri ( & id, n) ) ,
159
- None => Some ( make_state_uri ( & id) ) ,
159
+ Some ( n) => Some ( make_page_uri ( & id, & r . node_id , n) ) ,
160
+ None => Some ( make_state_uri ( & id, & r . node_id ) ) ,
160
161
} ;
161
162
( d. page . data , uri)
162
163
}
163
164
} ,
164
- ExecuteStateKind :: Failed => ( JsonBlock :: empty ( ) , Some ( make_final_uri ( & id) ) ) ,
165
+ ExecuteStateKind :: Failed => {
166
+ ( JsonBlock :: empty ( ) , Some ( make_final_uri ( & id, & r. node_id ) ) )
167
+ }
165
168
ExecuteStateKind :: Succeeded => match r. data {
166
- None => ( JsonBlock :: empty ( ) , Some ( make_final_uri ( & id) ) ) ,
169
+ None => ( JsonBlock :: empty ( ) , Some ( make_final_uri ( & id, & r . node_id ) ) ) ,
167
170
Some ( d) => {
168
171
let uri = match d. next_page_no {
169
- Some ( n) => Some ( make_page_uri ( & id, n) ) ,
170
- None => Some ( make_final_uri ( & id) ) ,
172
+ Some ( n) => Some ( make_page_uri ( & id, & r . node_id , n) ) ,
173
+ None => Some ( make_final_uri ( & id, & r . node_id ) ) ,
171
174
} ;
172
175
( d. page . data , uri)
173
176
}
@@ -198,9 +201,9 @@ impl QueryResponse {
198
201
warnings : r. state . warnings ,
199
202
id : id. clone ( ) ,
200
203
next_uri,
201
- stats_uri : Some ( make_state_uri ( & id) ) ,
202
- final_uri : Some ( make_final_uri ( & id) ) ,
203
- kill_uri : Some ( make_kill_uri ( & id) ) ,
204
+ stats_uri : Some ( make_state_uri ( & id, & node_id ) ) ,
205
+ final_uri : Some ( make_final_uri ( & id, & node_id ) ) ,
206
+ kill_uri : Some ( make_kill_uri ( & id, & node_id ) ) ,
204
207
error : r. state . error . map ( QueryError :: from_error_code) ,
205
208
has_result_set : r. state . has_result_set ,
206
209
} )
@@ -223,15 +226,16 @@ impl QueryResponse {
223
226
#[ poem:: handler]
224
227
async fn query_final_handler (
225
228
ctx : & HttpQueryContext ,
226
- Path ( query_id) : Path < String > ,
229
+ Path ( ( query_id, node_id ) ) : Path < ( String , String ) > ,
227
230
) -> PoemResult < impl IntoResponse > {
231
+ ctx. check_node_id ( & node_id, & query_id) ?;
228
232
let root = get_http_tracing_span ( full_name ! ( ) , ctx, & query_id) ;
229
233
let _t = SlowRequestLogTracker :: new ( ctx) ;
230
-
231
234
async {
232
235
info ! (
233
- "{}: got /v1/query/{}/final request, this query is going to be finally completed." ,
234
- query_id, query_id
236
+ "{}: got {} request, this query is going to be finally completed." ,
237
+ query_id,
238
+ make_final_uri( & query_id, & node_id)
235
239
) ;
236
240
let http_query_manager = HttpQueryManager :: instance ( ) ;
237
241
match http_query_manager
@@ -260,15 +264,16 @@ async fn query_final_handler(
260
264
#[ poem:: handler]
261
265
async fn query_cancel_handler (
262
266
ctx : & HttpQueryContext ,
263
- Path ( query_id) : Path < String > ,
267
+ Path ( ( query_id, node_id ) ) : Path < ( String , String ) > ,
264
268
) -> PoemResult < impl IntoResponse > {
269
+ ctx. check_node_id ( & node_id, & query_id) ?;
265
270
let root = get_http_tracing_span ( full_name ! ( ) , ctx, & query_id) ;
266
271
let _t = SlowRequestLogTracker :: new ( ctx) ;
267
-
268
272
async {
269
273
info ! (
270
- "{}: got /v1/query/{}/kill request, cancel the query" ,
271
- query_id, query_id
274
+ "{}: got {} request, cancel the query" ,
275
+ query_id,
276
+ make_kill_uri( & query_id, & node_id)
272
277
) ;
273
278
let http_query_manager = HttpQueryManager :: instance ( ) ;
274
279
match http_query_manager
@@ -290,10 +295,10 @@ async fn query_cancel_handler(
290
295
#[ poem:: handler]
291
296
async fn query_state_handler (
292
297
ctx : & HttpQueryContext ,
293
- Path ( query_id) : Path < String > ,
298
+ Path ( ( query_id, node_id ) ) : Path < ( String , String ) > ,
294
299
) -> PoemResult < impl IntoResponse > {
300
+ ctx. check_node_id ( & node_id, & query_id) ?;
295
301
let root = get_http_tracing_span ( full_name ! ( ) , ctx, & query_id) ;
296
-
297
302
async {
298
303
let http_query_manager = HttpQueryManager :: instance ( ) ;
299
304
match http_query_manager. get_query ( & query_id) {
@@ -315,11 +320,11 @@ async fn query_state_handler(
315
320
#[ poem:: handler]
316
321
async fn query_page_handler (
317
322
ctx : & HttpQueryContext ,
318
- Path ( ( query_id, page_no) ) : Path < ( String , usize ) > ,
323
+ Path ( ( query_id, node_id , page_no) ) : Path < ( String , String , usize ) > ,
319
324
) -> PoemResult < impl IntoResponse > {
325
+ ctx. check_node_id ( & node_id, & query_id) ?;
320
326
let root = get_http_tracing_span ( full_name ! ( ) , ctx, & query_id) ;
321
327
let _t = SlowRequestLogTracker :: new ( ctx) ;
322
-
323
328
async {
324
329
let http_query_manager = HttpQueryManager :: instance ( ) ;
325
330
match http_query_manager. get_query ( & query_id) {
@@ -352,7 +357,8 @@ pub(crate) async fn query_handler(
352
357
let _t = SlowRequestLogTracker :: new ( ctx) ;
353
358
354
359
async {
355
- info ! ( "http query new request: {:}" , mask_connection_info( & format!( "{:?}" , req) ) ) ;
360
+ let agent = ctx. user_agent . as_ref ( ) . map ( |s|( format ! ( "(from {s})" ) ) ) . unwrap_or ( "" . to_string ( ) ) ;
361
+ info ! ( "http query new request{}: {:}" , agent, mask_connection_info( & format!( "{:?}" , req) ) ) ;
356
362
let http_query_manager = HttpQueryManager :: instance ( ) ;
357
363
let sql = req. sql . clone ( ) ;
358
364
@@ -397,14 +403,14 @@ pub fn query_route() -> Route {
397
403
// Note: endpoints except /v1/query may change without notice, use uris in response instead
398
404
let rules = [
399
405
( "/" , post ( query_handler) ) ,
400
- ( "/:id " , get ( query_state_handler) ) ,
401
- ( "/:id /page/:page_no" , get ( query_page_handler) ) ,
406
+ ( "/:query_id/:node_id " , get ( query_state_handler) ) ,
407
+ ( "/:query_id/:node_id /page/:page_no" , get ( query_page_handler) ) ,
402
408
(
403
- "/:id /kill" ,
409
+ "/:query_id/:node_id /kill" ,
404
410
get ( query_cancel_handler) . post ( query_cancel_handler) ,
405
411
) ,
406
412
(
407
- "/:id /final" ,
413
+ "/:query_id/:node_id /final" ,
408
414
get ( query_final_handler) . post ( query_final_handler) ,
409
415
) ,
410
416
] ;
@@ -436,7 +442,7 @@ fn query_id_to_trace_id(query_id: &str) -> TraceId {
436
442
}
437
443
438
444
/// The HTTP query endpoints are expected to be responses within 60 seconds.
439
- /// If it exceeds far of 60 seconds, there might be something wrong, we should
445
+ /// If it exceeds far from 60 seconds, there might be something wrong, we should
440
446
/// log it.
441
447
struct SlowRequestLogTracker {
442
448
started_at : std:: time:: Instant ,
0 commit comments