Skip to content

Commit

Permalink
Merge pull request #925 from drmingdrmer/45-fix-snapshot-chunk
Browse files Browse the repository at this point in the history
Fix: AsyncReadExt::read_buf() only reads at most 2MB per call
  • Loading branch information
drmingdrmer authored Nov 8, 2023
2 parents 503fa49 + ffae522 commit 872ef37
Showing 1 changed file with 11 additions and 4 deletions.
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

0 comments on commit 872ef37

Please sign in to comment.