-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change blocking pruning process to non-blocking channel (#1โฆ
โฆ6718) * save * fix: fix skip empty block * fix: ci test * fix: performance degrade * chore: change channel to a 1 sender - n receivers pattern * chore: catch up main * chore: remove useless path prefix * chore: apply review suggestion to avoid using globalIORuntime * chore: apply review suggestion to spawn in pipeline init stage * try to find problem * clippy
- Loading branch information
Showing
19 changed files
with
999 additions
and
796 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/query/storages/fuse/src/operations/read/block_partition_meta.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2021 Datafuse Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::fmt::Debug; | ||
use std::fmt::Formatter; | ||
|
||
use databend_common_catalog::plan::PartInfoPtr; | ||
use databend_common_expression::local_block_meta_serde; | ||
use databend_common_expression::BlockMetaInfo; | ||
use databend_common_expression::BlockMetaInfoPtr; | ||
|
||
pub struct BlockPartitionMeta { | ||
pub part_ptr: Vec<PartInfoPtr>, | ||
} | ||
|
||
impl BlockPartitionMeta { | ||
pub fn create(part_ptr: Vec<PartInfoPtr>) -> BlockMetaInfoPtr { | ||
Box::new(BlockPartitionMeta { part_ptr }) | ||
} | ||
} | ||
|
||
impl Debug for BlockPartitionMeta { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("BlockPartitionMeta") | ||
.field("part_ptr", &self.part_ptr) | ||
.finish() | ||
} | ||
} | ||
|
||
local_block_meta_serde!(BlockPartitionMeta); | ||
|
||
#[typetag::serde(name = "block_partition_meta")] | ||
impl BlockMetaInfo for BlockPartitionMeta {} |
66 changes: 66 additions & 0 deletions
66
src/query/storages/fuse/src/operations/read/block_partition_receiver_source.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2021 Datafuse Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::sync::Arc; | ||
|
||
use async_channel::Receiver; | ||
use databend_common_catalog::plan::PartInfoPtr; | ||
use databend_common_catalog::table_context::TableContext; | ||
use databend_common_exception::Result; | ||
use databend_common_expression::DataBlock; | ||
use databend_common_pipeline_core::processors::OutputPort; | ||
use databend_common_pipeline_core::processors::ProcessorPtr; | ||
use databend_common_pipeline_sources::AsyncSource; | ||
use databend_common_pipeline_sources::AsyncSourcer; | ||
|
||
use crate::operations::read::block_partition_meta::BlockPartitionMeta; | ||
|
||
pub struct BlockPartitionReceiverSource { | ||
pub meta_receiver: Receiver<Result<PartInfoPtr>>, | ||
} | ||
|
||
impl BlockPartitionReceiverSource { | ||
pub fn create( | ||
ctx: Arc<dyn TableContext>, | ||
receiver: Receiver<Result<PartInfoPtr>>, | ||
output_port: Arc<OutputPort>, | ||
) -> Result<ProcessorPtr> { | ||
AsyncSourcer::create(ctx, output_port, Self { | ||
meta_receiver: receiver, | ||
}) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncSource for BlockPartitionReceiverSource { | ||
const NAME: &'static str = "BlockPartitionReceiverSource"; | ||
const SKIP_EMPTY_DATA_BLOCK: bool = false; | ||
|
||
#[async_backtrace::framed] | ||
async fn generate(&mut self) -> Result<Option<DataBlock>> { | ||
match self.meta_receiver.recv().await { | ||
Ok(Ok(part)) => Ok(Some(DataBlock::empty_with_meta( | ||
BlockPartitionMeta::create(vec![part]), | ||
))), | ||
Ok(Err(e)) => Err( | ||
// The error is occurred in pruning process | ||
e, | ||
), | ||
Err(_) => { | ||
// The channel is closed, we should return None to stop generating | ||
Ok(None) | ||
} | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/query/storages/fuse/src/operations/read/block_partition_source.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2021 Datafuse Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::sync::Arc; | ||
|
||
use databend_common_catalog::plan::StealablePartitions; | ||
use databend_common_catalog::table_context::TableContext; | ||
use databend_common_expression::DataBlock; | ||
use databend_common_pipeline_core::processors::OutputPort; | ||
use databend_common_pipeline_core::processors::ProcessorPtr; | ||
use databend_common_pipeline_sources::SyncSource; | ||
use databend_common_pipeline_sources::SyncSourcer; | ||
|
||
use crate::operations::read::block_partition_meta::BlockPartitionMeta; | ||
|
||
pub struct BlockPartitionSource { | ||
id: usize, | ||
partitions: StealablePartitions, | ||
max_batch_size: usize, | ||
} | ||
|
||
impl BlockPartitionSource { | ||
pub fn create( | ||
id: usize, | ||
partitions: StealablePartitions, | ||
max_batch_size: usize, | ||
ctx: Arc<dyn TableContext>, | ||
output_port: Arc<OutputPort>, | ||
) -> databend_common_exception::Result<ProcessorPtr> { | ||
SyncSourcer::create(ctx, output_port, BlockPartitionSource { | ||
id, | ||
partitions, | ||
max_batch_size, | ||
}) | ||
} | ||
} | ||
|
||
impl SyncSource for BlockPartitionSource { | ||
const NAME: &'static str = "BlockPartitionSource"; | ||
|
||
fn generate(&mut self) -> databend_common_exception::Result<Option<DataBlock>> { | ||
match self.partitions.steal(self.id, self.max_batch_size) { | ||
None => Ok(None), | ||
Some(parts) => Ok(Some(DataBlock::empty_with_meta( | ||
BlockPartitionMeta::create(parts), | ||
))), | ||
} | ||
} | ||
} |
Oops, something went wrong.