Skip to content

Commit

Permalink
chore: apply suggestions from CR
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Dec 18, 2023
1 parent 13d7cdf commit 6400337
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions core/src/docs/rfcs/3734_buffered_reader.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ op.reader_with(path).buffer(32 * 1024 * 1024).await

This feature will be implemented in the `CompleteLayer`, with the addition of a `BufferReader` struct in `raw/oio/reader/buffer_reader.rs`.

The `BufferReader` employs` bytes::BytesMut` as the inner buffer and utilizes `(Option<usize>, Option<usize>)` to track the buffered range of the file.
The `BufferReader` employs a `tokio::io::ReadBuf` as the inner buffer and uses `offset: Option<u64>` to track the buffered range start of the file, the buffered data should always be `file[offset..offset + buf.len()]`.


```rust
Expand All @@ -45,7 +45,7 @@ The `BufferReader` employs` bytes::BytesMut` as the inner buffer and utilizes `(
...
```

A `buffer` field of type `Option<usize>` will be introduced to `OpRead`. If `buffer` is set to `None`, it functions with default behavior. However, if buffer is set to `Some(n)`, it denotes the maximum buffer capability that the `BufferReader` can utilize, and buffering behaviors introduced below.
A `buffer` field of type `Option<usize>` will be introduced to `OpRead`. If `buffer` is set to `None`, it functions with default behavior. However, if buffer is set to `Some(n)`, it denotes the maximum buffer capability that the `BufferReader` can utilize. The behavior is similar to [std::io::BufReader](https://doc.rust-lang.org/std/io/struct.BufReader.html), with the only difference being that our implementation always provides the seek_relative if it's available.

**Buffering**

Expand All @@ -57,11 +57,11 @@ Buffer
│ │
└───────┘
File
┌────────────┐
┌──────────────┐
└───▲───────▲──┘
│ │
│ │ 2. ReadToEnd(limit), The limit <= Cap(Buffer).
│ │ 2. Read(limit), The limit <= Cap(Buffer).
│ 1. SeekFromStart(128)
Expand All @@ -81,15 +81,15 @@ File

**Tailing Read**

If a read request attempts to read the trailing bytes of the file, it only reads and buffers the `Min(Max(Limit,Cap(Buffer)),FileEnd-Cursor)` bytes.
If a read request attempts to read the trailing bytes of the file, it only reads and **without** buffers the `Min(Max(Limit,Cap(Buffer)),FileEnd-Cursor)` bytes.

```
File
┌──────────────┐
│ │
└────────────▲─▲
│ │
│ │ 2. ReadToEnd(limit)
│ │ 2. Read(limit)
│ 1. SeekFromEnd(-8)
```
Expand All @@ -108,7 +108,7 @@ File
│*******│ │
└────▲──┴──▲───┘
│ │
│ │ 2. ReadToEnd(limit), The limit <= Cap(Buffer).
│ │ 2. Read(limit), The limit <= Cap(Buffer).
│ 1. SeekFromStart(128)
```
Expand Down Expand Up @@ -138,10 +138,10 @@ Buffer
└───────┘
File
┌───────────┬──┐
│ │**
│ │
└──▲──────▲─┴──┘
│ │
│ │ 2. ReadToEnd(limit), The limit > Cap(Buffer).
│ │ 2. Read(limit), The limit > Cap(Buffer).
│ 1. SeekFromStart(128)
```
Expand Down

0 comments on commit 6400337

Please sign in to comment.