Skip to content

Commit 853a8c5

Browse files
committed
fix(processor): try fix test failure
1 parent 6f76776 commit 853a8c5

File tree

6 files changed

+21
-58
lines changed

6 files changed

+21
-58
lines changed

src/query/catalog/src/table_context.rs

-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::sync::Arc;
1818

1919
use common_base::base::Progress;
2020
use common_base::base::ProgressValues;
21-
use common_base::base::Runtime;
2221
use common_config::Config;
2322
use common_contexts::DalContext;
2423
use common_contexts::DalMetrics;
@@ -66,10 +65,6 @@ pub trait TableContext: Send + Sync {
6665
fn get_write_progress_value(&self) -> ProgressValues;
6766
fn get_result_progress(&self) -> Arc<Progress>;
6867
fn get_result_progress_value(&self) -> ProgressValues;
69-
// Steal n partitions from the partition pool by the pipeline worker.
70-
// This also can steal the partitions from distributed node.
71-
fn try_get_partitions(&self, num: u64) -> Result<Partitions>;
72-
7368
fn try_get_part(&self) -> Option<PartInfoPtr>;
7469
// Update the context partition pool from the pipeline builder.
7570
fn try_set_partitions(&self, partitions: Partitions) -> Result<()>;
@@ -107,7 +102,4 @@ pub trait TableContext: Send + Sync {
107102
async fn get_table(&self, catalog: &str, database: &str, table: &str)
108103
-> Result<Arc<dyn Table>>;
109104
fn get_processes_info(&self) -> Vec<ProcessInfo>;
110-
fn get_runtime(&self) -> Result<Arc<Runtime>>;
111-
112-
fn clone_inner(&self) -> Arc<dyn TableContext>;
113105
}

src/query/service/src/api/rpc/exchange/exchange_manager.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@ impl FragmentCoordinator {
668668

669669
match &self.payload {
670670
FragmentPayload::PlanV2(plan) => {
671-
let pipeline_builder = PipelineBuilderV2::create(ctx);
671+
let new_ctx = QueryContext::create_from(ctx);
672+
let pipeline_builder = PipelineBuilderV2::create(new_ctx);
672673
self.pipeline_build_res = Some(pipeline_builder.finalize(plan)?);
673674
}
674675
};

src/query/service/src/sessions/query_ctx.rs

+2-32
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use chrono_tz::Tz;
2525
use common_base::base::tokio::task::JoinHandle;
2626
use common_base::base::Progress;
2727
use common_base::base::ProgressValues;
28-
use common_base::base::Runtime;
2928
use common_base::base::TrySpawn;
3029
use common_contexts::DalContext;
3130
use common_contexts::DalMetrics;
@@ -69,7 +68,6 @@ pub struct QueryContext {
6968
version: String,
7069
partition_queue: Arc<RwLock<VecDeque<PartInfoPtr>>>,
7170
shared: Arc<QueryContextShared>,
72-
precommit_blocks: Arc<RwLock<Vec<DataBlock>>>,
7371
fragment_id: Arc<AtomicUsize>,
7472
}
7573

@@ -85,7 +83,6 @@ impl QueryContext {
8583
partition_queue: Arc::new(RwLock::new(VecDeque::new())),
8684
version: format!("DatabendQuery {}", *crate::version::DATABEND_COMMIT_VERSION),
8785
shared,
88-
precommit_blocks: Arc::new(RwLock::new(Vec::new())),
8986
fragment_id: Arc::new(AtomicUsize::new(0)),
9087
})
9188
}
@@ -226,20 +223,6 @@ impl TableContext for QueryContext {
226223
fn get_result_progress_value(&self) -> ProgressValues {
227224
self.shared.result_progress.as_ref().get_values()
228225
}
229-
// Steal n partitions from the partition pool by the pipeline worker.
230-
// This also can steal the partitions from distributed node.
231-
fn try_get_partitions(&self, num: u64) -> Result<Partitions> {
232-
let mut partitions = vec![];
233-
for _ in 0..num {
234-
match self.partition_queue.write().pop_back() {
235-
None => break,
236-
Some(partition) => {
237-
partitions.push(partition);
238-
}
239-
}
240-
}
241-
Ok(partitions)
242-
}
243226

244227
fn try_get_part(&self) -> Option<PartInfoPtr> {
245228
self.partition_queue.write().pop_front()
@@ -334,15 +317,10 @@ impl TableContext for QueryContext {
334317
self.shared.dal_ctx.as_ref()
335318
}
336319
fn push_precommit_block(&self, block: DataBlock) {
337-
let mut blocks = self.precommit_blocks.write();
338-
blocks.push(block);
320+
self.shared.push_precommit_block(block)
339321
}
340322
fn consume_precommit_blocks(&self) -> Vec<DataBlock> {
341-
let mut blocks = self.precommit_blocks.write();
342-
343-
let mut swaped_precommit_blocks = vec![];
344-
std::mem::swap(&mut *blocks, &mut swaped_precommit_blocks);
345-
swaped_precommit_blocks
323+
self.shared.consume_precommit_blocks()
346324
}
347325
fn try_get_function_context(&self) -> Result<FunctionContext> {
348326
let tz = self.get_settings().get_timezone()?;
@@ -382,14 +360,6 @@ impl TableContext for QueryContext {
382360
fn get_processes_info(&self) -> Vec<ProcessInfo> {
383361
SessionManager::instance().processes_info()
384362
}
385-
386-
fn get_runtime(&self) -> Result<Arc<Runtime>> {
387-
self.shared.try_get_runtime()
388-
}
389-
390-
fn clone_inner(&self) -> Arc<dyn TableContext> {
391-
QueryContext::create_from_shared(self.shared.clone())
392-
}
393363
}
394364

395365
impl TrySpawn for QueryContext {

src/query/service/src/sessions/query_ctx_shared.rs

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::sync::Weak;
2222
use common_base::base::Progress;
2323
use common_base::base::Runtime;
2424
use common_contexts::DalContext;
25+
use common_datablocks::DataBlock;
2526
use common_exception::ErrorCode;
2627
use common_exception::Result;
2728
use common_meta_types::UserInfo;
@@ -79,6 +80,7 @@ pub struct QueryContextShared {
7980
pub(in crate::sessions) catalog_manager: Arc<CatalogManager>,
8081
pub(in crate::sessions) storage_operator: StorageOperator,
8182
pub(in crate::sessions) executor: Arc<RwLock<Weak<PipelineExecutor>>>,
83+
pub(in crate::sessions) precommit_blocks: Arc<RwLock<Vec<DataBlock>>>,
8284
}
8385

8486
impl QueryContextShared {
@@ -108,6 +110,7 @@ impl QueryContextShared {
108110
auth_manager: AuthMgr::create(config).await?,
109111
affect: Arc::new(Mutex::new(None)),
110112
executor: Arc::new(RwLock::new(Weak::new())),
113+
precommit_blocks: Arc::new(RwLock::new(vec![])),
111114
}))
112115
}
113116

@@ -297,4 +300,17 @@ impl QueryContextShared {
297300
let mut executor = self.executor.write();
298301
*executor = weak_ptr;
299302
}
303+
304+
pub fn push_precommit_block(&self, block: DataBlock) {
305+
let mut blocks = self.precommit_blocks.write();
306+
blocks.push(block);
307+
}
308+
309+
pub fn consume_precommit_blocks(&self) -> Vec<DataBlock> {
310+
let mut blocks = self.precommit_blocks.write();
311+
312+
let mut swaped_precommit_blocks = vec![];
313+
std::mem::swap(&mut *blocks, &mut swaped_precommit_blocks);
314+
swaped_precommit_blocks
315+
}
300316
}

src/query/storages/fuse/src/operations/read.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl FuseTable {
7474
#[inline]
7575
pub fn do_read2(
7676
&self,
77-
mut ctx: Arc<dyn TableContext>,
77+
ctx: Arc<dyn TableContext>,
7878
plan: &ReadDataSourcePlan,
7979
pipeline: &mut Pipeline,
8080
) -> Result<()> {
@@ -87,8 +87,6 @@ impl FuseTable {
8787
}
8888

8989
if !lazy_init_segments.is_empty() {
90-
ctx = ctx.clone_inner();
91-
9290
let table_info = self.table_info.clone();
9391
let push_downs = plan.push_downs.clone();
9492
let query_ctx = ctx.clone();

src/query/storages/fuse/src/operations/read_partitions.rs

-14
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,6 @@ impl FuseTable {
8585
}
8686
}
8787

88-
pub fn sync_prune_snapshot_blocks(
89-
ctx: Arc<dyn TableContext>,
90-
push_downs: Option<Extras>,
91-
table_info: TableInfo,
92-
segments_location: Vec<Location>,
93-
) -> Result<(Statistics, Partitions)> {
94-
let block_metas =
95-
BlockPruner::sync_prune(&ctx, table_info.schema(), &push_downs, segments_location)?
96-
.into_iter()
97-
.map(|(_, v)| v)
98-
.collect::<Vec<_>>();
99-
Self::read_partitions_with_metas(ctx, table_info.schema(), push_downs, block_metas, 0)
100-
}
101-
10288
pub async fn prune_snapshot_blocks(
10389
ctx: Arc<dyn TableContext>,
10490
push_downs: Option<Extras>,

0 commit comments

Comments
 (0)