Skip to content

Commit

Permalink
fix: Fix retry happend in seek's read ahead logic
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Feb 7, 2023
1 parent d2a52a3 commit bb9e076
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/raw/io/output/into_reader/by_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,23 @@ impl<A: Accessor> output::Read for RangeReader<A> {
let mut buf = ReadBuf::uninit(self.sink.spare_capacity_mut());
unsafe { buf.assume_init(consume) };

let n = ready!(Pin::new(r).poll_read(cx, buf.initialized_mut()))?;
assert!(n > 0, "consumed bytes must be valid");

self.cur += n as u64;
// Make sure the pos is absolute from start.
self.poll_seek(cx, SeekFrom::Start(seek_pos))
match ready!(Pin::new(r).poll_read(cx, buf.initialized_mut())) {
Ok(n) => {
assert!(n > 0, "consumed bytes must be valid");
self.cur += n as u64;
// Make sure the pos is absolute from start.
self.poll_seek(cx, SeekFrom::Start(seek_pos))
}
Err(_) => {
// If we are hitting errors while read ahead.
// It's better to drop this reader and seek to
// correct position directly.
self.state = State::Idle;
self.cur = seek_pos;
self.last_seek_pos = None;
Poll::Ready(Ok(self.cur))
}
}
} else {
// If we are trying to seek to far more away.
// Let's just drop the reader.
Expand Down

1 comment on commit bb9e076

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for opendal ready!

✅ Preview
https://opendal-3pikri5ui-databend.vercel.app
https://opendal-git-fix-s3-retry.vercel.app

Built with commit bb9e076.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.