Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: fetch concurrency by ConcurrentTasks
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Jul 27, 2025
commit ffdf53aa059d3a9c5e476150d6f90c27cf757ab3
3 changes: 0 additions & 3 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@
// Make sure all our public APIs have docs.
#![deny(missing_docs)]

// Private modules, they will not be accessed by users.
mod patches;

// Private module with public types, they will be accessed via `opendal::Xxxx`
mod types;
pub use types::*;
Expand Down
158 changes: 0 additions & 158 deletions core/src/patches/buffer_by_ordered.rs

This file was deleted.

19 changes: 0 additions & 19 deletions core/src/patches/mod.rs

This file was deleted.

34 changes: 0 additions & 34 deletions core/src/patches/stream.rs

This file was deleted.

35 changes: 28 additions & 7 deletions core/src/types/read/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use std::ops::RangeBounds;
use std::sync::Arc;

use bytes::BufMut;
use futures::stream;
use futures::TryStreamExt;

use crate::patches::stream::StreamExt;
use crate::raw::Access;
use crate::raw::ConcurrentTasks;
use crate::*;

/// Reader is designed to read data from given path in an asynchronous
Expand Down Expand Up @@ -146,11 +146,32 @@ impl Reader {
pub async fn fetch(&self, ranges: Vec<Range<u64>>) -> Result<Vec<Buffer>> {
let merged_ranges = self.merge_ranges(ranges.clone());

let merged_bufs: Vec<_> =
stream::iter(merged_ranges.clone().into_iter().map(|v| (self.read(v), 1)))
.buffer_by_ordered(self.ctx.options().concurrent())
.try_collect()
.await?;
#[derive(Clone)]
struct FetchInput {
reader: Reader,
range: Range<u64>,
}

let mut tasks = ConcurrentTasks::new(
self.ctx.accessor().info().executor(),
self.ctx.options().concurrent(),
|input: FetchInput| {
Box::pin(async move {
let FetchInput { range, reader } = input.clone();
(input, reader.read(range).await)
})
},
);

for range in merged_ranges.clone() {
let reader = self.clone();
tasks.create_task(FetchInput { reader, range });
}

let mut merged_bufs = vec![];
while let Some(b) = tasks.next().await {
merged_bufs.push(b?);
}

let mut bufs = Vec::with_capacity(ranges.len());
for range in ranges {
Expand Down
Loading