Skip to content

Commit d2ed0a3

Browse files
author
Sandeep Kumawat
committed
addres comments
Signed-off-by: Sandeep Kumawat <skumwt@amazon.com>
1 parent c17b19d commit d2ed0a3

File tree

7 files changed

+15
-36
lines changed

7 files changed

+15
-36
lines changed

plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3BlobContainer.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,7 @@ public void readBlobAsync(String blobName, ActionListener<ReadContext> listener)
285285
);
286286
}
287287
}
288-
listener.onResponse(
289-
new ReadContext.Builder().blobSize(blobSize)
290-
.asyncPartStreams(blobPartInputStreamFutures)
291-
.blobChecksum(blobChecksum)
292-
.build()
293-
);
288+
listener.onResponse(new ReadContext.Builder(blobSize, blobPartInputStreamFutures).blobChecksum(blobChecksum).build());
294289
} catch (Exception ex) {
295290
listener.onFailure(ex);
296291
}

server/src/internalClusterTest/java/org/opensearch/remotestore/multipart/mocks/MockFsAsyncBlobContainer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void readBlobAsync(String blobName, ActionListener<ReadContext> listener)
131131
InputStreamContainer blobPartStream = new InputStreamContainer(readBlob(blobName, offset, partSize), partSize, offset);
132132
blobPartStreams.add(() -> CompletableFuture.completedFuture(blobPartStream));
133133
}
134-
ReadContext blobReadContext = new ReadContext.Builder().blobSize(contentLength).asyncPartStreams(blobPartStreams).build();
134+
ReadContext blobReadContext = new ReadContext.Builder(contentLength, blobPartStreams).build();
135135
listener.onResponse(blobReadContext);
136136
} catch (Exception e) {
137137
listener.onFailure(e);

server/src/main/java/org/opensearch/common/blobstore/BlobContainer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public interface BlobContainer {
8383
*
8484
* @param blobName
8585
* The name of the blob to get an {@link InputStream} for.
86-
* @return The {@code InputStream} to read the blob.
86+
* @return The {@link BlobDownloadResponse} of the blob.
8787
* @throws NoSuchFileException if the blob does not exist
8888
* @throws IOException if the blob can not be read.
8989
*/

server/src/main/java/org/opensearch/common/blobstore/stream/read/ReadContext.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public List<StreamPartCreator> getPartStreams() {
7272
@ExperimentalApi
7373
public interface StreamPartCreator extends Supplier<CompletableFuture<InputStreamContainer>> {
7474
/**
75-
* Kicks off a async process to start streaming.
75+
* Kicks off an async process to start streaming.
7676
*
7777
* @return When the returned future is completed, streaming has
7878
* just begun. Clients must fully consume the resulting stream.
@@ -87,19 +87,14 @@ public interface StreamPartCreator extends Supplier<CompletableFuture<InputStrea
8787
* @opensearch.experimental
8888
*/
8989
public static class Builder {
90-
private long blobSize;
91-
private List<StreamPartCreator> asyncPartStreams;
90+
private final long blobSize;
91+
private final List<StreamPartCreator> asyncPartStreams;
9292
private String blobChecksum;
9393
private Map<String, String> metadata;
9494

95-
public Builder blobSize(long blobSize) {
95+
public Builder(long blobSize, List<StreamPartCreator> asyncPartStreams) {
9696
this.blobSize = blobSize;
97-
return this;
98-
}
99-
100-
public Builder asyncPartStreams(List<StreamPartCreator> asyncPartStreams) {
10197
this.asyncPartStreams = asyncPartStreams;
102-
return this;
10398
}
10499

105100
public Builder blobChecksum(String blobChecksum) {

server/src/main/java/org/opensearch/common/blobstore/transfer/RemoteTransferContainer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class RemoteTransferContainer implements Closeable {
5656
private final OffsetRangeInputStreamSupplier offsetRangeInputStreamSupplier;
5757
private final boolean isRemoteDataIntegritySupported;
5858
private final AtomicBoolean readBlock = new AtomicBoolean();
59-
private Map<String, String> metadata = null;
59+
private final Map<String, String> metadata;
6060

6161
private static final Logger log = LogManager.getLogger(RemoteTransferContainer.class);
6262

@@ -90,6 +90,7 @@ public RemoteTransferContainer(
9090
this.offsetRangeInputStreamSupplier = offsetRangeInputStreamSupplier;
9191
this.expectedChecksum = expectedChecksum;
9292
this.isRemoteDataIntegritySupported = isRemoteDataIntegritySupported;
93+
this.metadata = null;
9394
}
9495

9596
/**

server/src/test/java/org/opensearch/common/blobstore/AsyncMultiStreamEncryptedBlobContainerTests.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public void testReadBlobAsync() throws Exception {
5757
final ListenerTestUtils.CountingCompletionListener<ReadContext> completionListener =
5858
new ListenerTestUtils.CountingCompletionListener<>();
5959
final CompletableFuture<InputStreamContainer> streamContainerFuture = CompletableFuture.completedFuture(inputStreamContainer);
60-
final ReadContext readContext = new ReadContext.Builder().blobSize(size)
61-
.asyncPartStreams(List.of(() -> streamContainerFuture))
62-
.build();
60+
final ReadContext readContext = new ReadContext.Builder(size, List.of(() -> streamContainerFuture)).build();
6361

6462
Mockito.doAnswer(invocation -> {
6563
ActionListener<ReadContext> readContextActionListener = invocation.getArgument(1);
@@ -105,9 +103,7 @@ public void testReadBlobAsyncException() throws Exception {
105103
final ListenerTestUtils.CountingCompletionListener<ReadContext> completionListener =
106104
new ListenerTestUtils.CountingCompletionListener<>();
107105
final CompletableFuture<InputStreamContainer> streamContainerFuture = CompletableFuture.completedFuture(inputStreamContainer);
108-
final ReadContext readContext = new ReadContext.Builder().blobSize(size)
109-
.asyncPartStreams(List.of(() -> streamContainerFuture))
110-
.build();
106+
final ReadContext readContext = new ReadContext.Builder(size, List.of(() -> streamContainerFuture)).build();
111107

112108
Mockito.doAnswer(invocation -> {
113109
ActionListener<ReadContext> readContextActionListener = invocation.getArgument(1);

server/src/test/java/org/opensearch/common/blobstore/stream/read/listener/ReadContextListenerTests.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ public void testReadContextListener() throws InterruptedException, IOException {
7878
UnaryOperator.identity(),
7979
MAX_CONCURRENT_STREAMS
8080
);
81-
ReadContext readContext = new ReadContext.Builder().blobSize((long) PART_SIZE * NUMBER_OF_PARTS)
82-
.asyncPartStreams(blobPartStreams)
83-
.build();
81+
ReadContext readContext = new ReadContext.Builder((long) PART_SIZE * NUMBER_OF_PARTS, blobPartStreams).build();
8482
readContextListener.onResponse(readContext);
8583

8684
countDownLatch.await();
@@ -127,9 +125,7 @@ public int available() {
127125
threadPool.generic()
128126
)
129127
);
130-
ReadContext readContext = new ReadContext.Builder().blobSize((long) (PART_SIZE + 1) * NUMBER_OF_PARTS)
131-
.asyncPartStreams(blobPartStreams)
132-
.build();
128+
ReadContext readContext = new ReadContext.Builder((long) (PART_SIZE + 1) * NUMBER_OF_PARTS, blobPartStreams).build();
133129
readContextListener.onResponse(readContext);
134130

135131
countDownLatch.await();
@@ -182,9 +178,7 @@ public int read(byte[] b) throws IOException {
182178
threadPool.generic()
183179
)
184180
);
185-
ReadContext readContext = new ReadContext.Builder().blobSize((long) (PART_SIZE + 1) * NUMBER_OF_PARTS + 1)
186-
.asyncPartStreams(blobPartStreams)
187-
.build();
181+
ReadContext readContext = new ReadContext.Builder((long) (PART_SIZE + 1) * NUMBER_OF_PARTS + 1, blobPartStreams).build();
188182
readContextListener.onResponse(readContext);
189183

190184
countDownLatch.await();
@@ -209,9 +203,7 @@ public void testWriteToTempFile_alreadyExists_replacesFile() throws Exception {
209203
UnaryOperator.identity(),
210204
MAX_CONCURRENT_STREAMS
211205
);
212-
ReadContext readContext = new ReadContext.Builder().blobSize((long) (PART_SIZE + 1) * NUMBER_OF_PARTS)
213-
.asyncPartStreams(blobPartStreams)
214-
.build();
206+
ReadContext readContext = new ReadContext.Builder((long) (PART_SIZE + 1) * NUMBER_OF_PARTS, blobPartStreams).build();
215207
readContextListener.onResponse(readContext);
216208

217209
countDownLatch.await();

0 commit comments

Comments
 (0)