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

Fix: AsyncReadExt::read_buf() only reads at most 2MB per call #925

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all 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
15 changes: 11 additions & 4 deletions openraft/src/replication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,20 @@ where

let mut offset = 0;
let end = snapshot.snapshot.seek(SeekFrom::End(0)).await.sto_res(err_x)?;
let mut buf = Vec::with_capacity(self.config.snapshot_max_chunk_size as usize);

loop {
// Build the RPC.
snapshot.snapshot.seek(SeekFrom::Start(offset)).await.sto_res(err_x)?;
let n_read = snapshot.snapshot.read_buf(&mut buf).await.sto_res(err_x)?;

let mut buf = Vec::with_capacity(self.config.snapshot_max_chunk_size as usize);
while buf.capacity() > buf.len() {
let n = snapshot.snapshot.read_buf(&mut buf).await.sto_res(err_x)?;
if n == 0 {
break;
}
}

let n_read = buf.len();

let leader_time = <C::AsyncRuntime as AsyncRuntime>::Instant::now();

Expand All @@ -659,10 +667,9 @@ where
vote: self.session_id.vote,
meta: snapshot.meta.clone(),
offset,
data: Vec::from(&buf[..n_read]),
data: buf,
done,
};
buf.clear();

// Send the RPC over to the target.
tracing::debug!(
Expand Down
Loading