peterxcli commented on code in PR #1488:
URL: https://github.com/apache/ratis/pull/1488#discussion_r3466713675
##########
ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStoreCommon.java:
##########
@@ -47,6 +51,15 @@ static ByteString toByteString(Path p) {
return ProtoUtils.toByteString(p.toString());
}
+ static ByteBuffer getReplyBuffer(DataStreamReply reply) {
Review Comment:
I'm thinking if we could make the `DataStreamInput#readAsync` to return:
```java
ReferenceCountedObject<DataStreamReadChunk>
interface DataStreamReadChunk {
long getOffset();
ByteBuffer[] nioBuffers();
}
```
no terminal reply bytebuffer handling logic anymore, user don't need to
aware the `DataStreamReplyByteBuf` and `DataStreamReplyByteBuffer`.
##########
ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileInfo.java:
##########
@@ -88,6 +89,34 @@ ByteString read(CheckedFunction<Path, Path, IOException>
resolver, long offset,
}
}
+ void streamRead(CheckedFunction<Path, Path, IOException> resolver, long
offset, long length,
+ WritableByteChannel stream) throws IOException {
+ if (offset + length > getWriteSize()) {
+ throw new IOException("Failed to read Wrote: offset (=" + offset
+ + " + length (=" + length + ") > size = " + getWriteSize()
+ + ", path=" + getRelativePath());
+ }
+
+ try (SeekableByteChannel in = Files.newByteChannel(
+ resolver.apply(getRelativePath()), StandardOpenOption.READ)) {
+ in.position(offset);
+ long remaining = length;
+ while (remaining > 0) {
+ final int chunkSize = FileStoreCommon.getChunkSize(remaining);
+ final ByteBuffer buffer = ByteBuffer.allocateDirect(chunkSize);
Review Comment:
Could we reuse the buffe?
```java
final ByteBuffer buffer =
ByteBuffer.allocateDirect(FileStoreCommon.getChunkSize(length));
while (remaining > 0) {
buffer.clear();
buffer.limit(FileStoreCommon.getChunkSize(remaining));
...
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]