Skip to content

Commit 0c2533f

Browse files
authored
fix(query): tracing was broken (#18376)
1 parent a9f55d3 commit 0c2533f

File tree

7 files changed

+68
-9
lines changed

7 files changed

+68
-9
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# Copyright 2022 The Databend Authors.
3+
# SPDX-License-Identifier: Apache-2.0.
4+
5+
set -e
6+
7+
SCRIPT_PATH="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
8+
cd "$SCRIPT_PATH/../../.." || exit
9+
BUILD_PROFILE=${BUILD_PROFILE:-debug}
10+
11+
killall databend-query || true
12+
killall databend-meta || true
13+
sleep 1
14+
15+
for bin in databend-query databend-meta; do
16+
if test -n "$(pgrep $bin)"; then
17+
echo "The $bin is not killed. force killing."
18+
killall -9 $bin || true
19+
fi
20+
done
21+
22+
# Wait for killed process to cleanup resources
23+
sleep 1
24+
25+
echo 'Start databend-meta...'
26+
nohup target/${BUILD_PROFILE}/databend-meta -c scripts/ci/deploy/config/databend-meta-node-1.toml &
27+
echo "Waiting on databend-meta 10 seconds..."
28+
python3 scripts/ci/wait_tcp.py --timeout 30 --port 9191
29+
30+
export RUST_BACKTRACE=1
31+
export LOG_TRACING_ON=true
32+
33+
echo 'Start databend-query node-1'
34+
nohup target/${BUILD_PROFILE}/databend-query -c scripts/ci/deploy/config/databend-query-node-1.toml --internal-enable-sandbox-tenant --log-tracing-level Warn,databend_=Debug,openraft=Info >./.databend/query-1.out 2>&1 &
35+
36+
echo "Waiting on node-1..."
37+
python3 scripts/ci/wait_tcp.py --timeout 30 --port 9091
38+
39+
echo 'Start databend-query node-2'
40+
nohup target/${BUILD_PROFILE}/databend-query -c scripts/ci/deploy/config/databend-query-node-2.toml --internal-enable-sandbox-tenant --log-tracing-level Warn,databend_=Debug,openraft=Info >./.databend/query-2.out 2>&1 &
41+
42+
echo "Waiting on node-2..."
43+
python3 scripts/ci/wait_tcp.py --timeout 30 --port 9092
44+
45+
echo 'Start databend-query node-3'
46+
nohup target/${BUILD_PROFILE}/databend-query -c scripts/ci/deploy/config/databend-query-node-3.toml --internal-enable-sandbox-tenant --log-tracing-level Warn,databend_=Debug,openraft=Info >./.databend/query-3.out 2>&1 &
47+
48+
echo "Waiting on node-3..."
49+
python3 scripts/ci/wait_tcp.py --timeout 30 --port 9093
50+
51+
echo "All done..."

src/query/expression/src/block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ impl BlockEntry {
146146
/// Calling this method with an out-of-bounds index is *[undefined behavior]*
147147
pub unsafe fn index_unchecked(&self, index: usize) -> ScalarRef {
148148
match self {
149-
BlockEntry::Const(scalar, _, n) => {
149+
BlockEntry::Const(scalar, _, _n) => {
150150
#[cfg(debug_assertions)]
151-
if index >= *n {
151+
if index >= *_n {
152152
panic!(
153153
"index out of bounds: the len is {:?} but the index is {}",
154-
n, index
154+
_n, index
155155
)
156156
}
157157

src/query/service/src/interpreters/interpreter_select.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl SelectInterpreter {
108108
DataSchemaRefExt::create(fields)
109109
}
110110

111-
#[inline]
111+
#[fastrace::trace(name = "SelectInterpreter::build_physical_plan")]
112112
#[async_backtrace::framed]
113113
pub async fn build_physical_plan(&self) -> Result<PhysicalPlan> {
114114
let mut builder = PhysicalPlanBuilder::new(self.metadata.clone(), self.ctx.clone(), false);
@@ -119,6 +119,7 @@ impl SelectInterpreter {
119119
.await
120120
}
121121

122+
#[fastrace::trace(name = "SelectInterpreter::build_pipeline")]
122123
#[async_backtrace::framed]
123124
pub async fn build_pipeline(
124125
&self,
@@ -275,7 +276,7 @@ impl Interpreter for SelectInterpreter {
275276

276277
/// This method will create a new pipeline
277278
/// The QueryPipelineBuilder will use the optimized plan to generate a Pipeline
278-
#[fastrace::trace]
279+
#[fastrace::trace(name = "SelectInterpreter::execute2")]
279280
#[async_backtrace::framed]
280281
async fn execute2(&self) -> Result<PipelineBuildResult> {
281282
self.attach_tables_to_ctx();

src/query/service/src/servers/http/v1/http_query_handlers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ async fn query_page_handler(
432432

433433
#[poem::handler]
434434
#[async_backtrace::framed]
435+
#[fastrace::trace]
435436
pub(crate) async fn query_handler(
436437
ctx: &HttpQueryContext,
437438
Json(mut req): Json<HttpQueryRequest>,

src/query/service/src/servers/http/v1/query/execute_state.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ impl Executor {
279279
let state = match &guard.state {
280280
Starting(s) => {
281281
info!(
282-
"[HTTP-QUERY] Query {} state transitioning from Starting to Stopped, reason: {:?}",
283-
&guard.query_id, reason
282+
query_id = guard.query_id, reason:? = reason;
283+
"[HTTP-QUERY] Query state transitioning from Starting to Stopped"
284284
);
285285
if let Err(e) = &reason {
286286
InterpreterQueryLog::log_finish(
@@ -347,6 +347,7 @@ impl Executor {
347347

348348
impl ExecuteState {
349349
#[async_backtrace::framed]
350+
#[fastrace::trace(name = "ExecuteState::try_start_query")]
350351
pub(crate) async fn try_start_query(
351352
executor: Arc<Mutex<Executor>>,
352353
sql: String,

src/query/service/src/servers/http/v1/query/http_query.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use databend_common_metrics::http::metrics_incr_http_response_errors_count;
3838
use databend_common_settings::ScopeLevel;
3939
use databend_storages_common_session::TempTblMgrRef;
4040
use databend_storages_common_session::TxnState;
41+
use fastrace::future::FutureExt;
4142
use http::StatusCode;
4243
use log::error;
4344
use log::info;
@@ -441,7 +442,7 @@ fn try_set_txn(
441442

442443
impl HttpQuery {
443444
#[async_backtrace::framed]
444-
#[fastrace::trace]
445+
#[fastrace::trace(name = "HttpQuery::try_create")]
445446
pub async fn try_create(
446447
http_ctx: &HttpQueryContext,
447448
req: HttpQueryRequest,
@@ -790,6 +791,7 @@ impl HttpQuery {
790791
}
791792

792793
pub async fn start_query(&mut self, sql: String) -> Result<()> {
794+
let span = fastrace::Span::enter_with_local_parent("HttpQuery::start_query");
793795
let (block_sender, query_context) = {
794796
let state = self.executor.lock();
795797
let ExecuteState::Starting(state) = &state.state else {
@@ -847,7 +849,8 @@ impl HttpQuery {
847849
Executor::start_to_stop(&query_state, ExecuteState::Stopped(Box::new(state)));
848850
block_sender.close();
849851
}
850-
},
852+
}
853+
.in_span(span),
851854
None,
852855
)?;
853856

src/query/service/src/spillers/spiller.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ impl Spiller {
162162
}
163163

164164
/// Spill some [`DataBlock`] to storage. These blocks will be concat into one.
165+
#[fastrace::trace(name = "Spiller::spill")]
165166
pub async fn spill(&self, data_block: Vec<DataBlock>) -> Result<Location> {
166167
let (location, layout, data_size) = self.spill_unmanage(data_block).await?;
167168

@@ -325,6 +326,7 @@ impl Spiller {
325326

326327
/// Read a certain file to a [`DataBlock`].
327328
/// We should guarantee that the file is managed by this spiller.
329+
#[fastrace::trace(name = "Spiller::read_spilled_file")]
328330
pub async fn read_spilled_file(&self, location: &Location) -> Result<DataBlock> {
329331
let layout = self.ctx.get_spill_layout(location).unwrap();
330332
self.read_unmanage_spilled_file(location, &layout).await

0 commit comments

Comments
 (0)