ashishkumar50 commented on code in PR #9402:
URL: https://github.com/apache/ozone/pull/9402#discussion_r2601627538
##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/MultipartInputStream.java:
##########
@@ -245,36 +245,26 @@ public synchronized long skip(long n) throws IOException {
* @param allocate function to allocate ByteBuffer for each range
* @throws IOException if there is an error performing the reads
*/
- public void readVectored(List<? extends FileRange> ranges,
- IntFunction<ByteBuffer> allocate) throws
IOException {
+ public void readVectored(
+ List<? extends FileRange> ranges,
+ IntFunction<ByteBuffer> allocate
+ ) throws IOException {
checkOpen();
if (!initialized) {
initialize();
}
- // Perform vectored read using positioned read operations
- for (FileRange range : ranges) {
- CompletableFuture<ByteBuffer> result = range.getData();
- if (result == null) {
- result = new CompletableFuture<>();
- range.setData(result);
- }
+ // Save the initial position
+ final long initialPosition = getPos();
- final CompletableFuture<ByteBuffer> finalResult = result;
- final long offset = range.getOffset();
- final int rangeLength = range.getLength();
-
- // Submit async read task for this range
- CompletableFuture.runAsync(() -> {
- try {
- ByteBuffer buffer = allocate.apply(rangeLength);
- readRangeData(offset, buffer);
- buffer.flip();
- finalResult.complete(buffer);
- } catch (Exception e) {
- finalResult.completeExceptionally(e);
- }
- });
+ try {
+ VectoredReadUtils.performVectoredRead(ranges, allocate,
+ (offset, buffer) -> readRangeData(offset, buffer, initialPosition));
+ } finally {
+ // Restore position
+ synchronized (this) {
Review Comment:
Synchronized now to avoid race condition in same concurrent stream reads.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]