Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(query): only call once finish callback #17293

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/query/service/src/pipelines/pipeline_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ impl PipelineBuilder {
}

// unload spill metas
self.main_pipeline
.set_on_finished(always_callback(move |_info: &ExecutionInfo| {
self.ctx.unload_spill_meta();
Ok(())
}));
if !self.ctx.mark_unload_callbacked() {
self.main_pipeline
.set_on_finished(always_callback(move |_info: &ExecutionInfo| {
self.ctx.unload_spill_meta();
Ok(())
}));
}

Ok(PipelineBuildResult {
main_pipeline: self.main_pipeline,
Expand Down
9 changes: 9 additions & 0 deletions src/query/service/src/sessions/query_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ impl QueryContext {

pub fn update_init_query_id(&self, id: String) {
self.shared.spilled_files.write().clear();
self.shared
.unload_callbacked
.store(false, Ordering::Release);
self.shared.cluster_spill_progress.write().clear();
*self.shared.init_query_id.write() = id;
}
Expand Down Expand Up @@ -471,6 +474,12 @@ impl QueryContext {
Ok(table)
}

pub fn mark_unload_callbacked(&self) -> bool {
self.shared
.unload_callbacked
.fetch_or(true, Ordering::SeqCst)
}

pub fn unload_spill_meta(&self) {
const SPILL_META_SUFFIX: &str = ".list";
let r = self.shared.spilled_files.read();
Expand Down
3 changes: 3 additions & 0 deletions src/query/service/src/sessions/query_ctx_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::sync::Weak;
Expand Down Expand Up @@ -150,6 +151,7 @@ pub struct QueryContextShared {
pub(in crate::sessions) cluster_spill_progress: Arc<RwLock<HashMap<String, SpillProgress>>>,
pub(in crate::sessions) spilled_files:
Arc<RwLock<HashMap<crate::spillers::Location, crate::spillers::Layout>>>,
pub(in crate::sessions) unload_callbacked: AtomicBool,
}

impl QueryContextShared {
Expand Down Expand Up @@ -209,6 +211,7 @@ impl QueryContextShared {

cluster_spill_progress: Default::default(),
spilled_files: Default::default(),
unload_callbacked: AtomicBool::new(false),
warehouse_cache: Arc::new(RwLock::new(None)),
}))
}
Expand Down
Loading