-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support to emit multiple streams for a file content each responsible …
…for processing a specific part of the file Signed-off-by: Raghuvansh Raj <[email protected]>
- Loading branch information
1 parent
53b128f
commit 29b6dca
Showing
22 changed files
with
1,223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common; | ||
|
||
import java.io.InputStream; | ||
|
||
/** | ||
* Model composed of an input stream, the total content length and offset | ||
*/ | ||
public class Stream { | ||
|
||
private final InputStream inputStream; | ||
private final long contentLength; | ||
private final long offset; | ||
|
||
/** | ||
* Construct a new stream object | ||
* | ||
* @param inputStream The input stream that is to be encapsulated | ||
* @param contentLength The total content length that is to be read from the stream | ||
* @param offset The offset pointer that this stream reads from in the file | ||
*/ | ||
public Stream(InputStream inputStream, long contentLength, long offset) { | ||
this.inputStream = inputStream; | ||
this.contentLength = contentLength; | ||
this.offset = offset; | ||
} | ||
|
||
/** | ||
* @return The input stream this object is reading from | ||
*/ | ||
public InputStream getInputStream() { | ||
return inputStream; | ||
} | ||
|
||
/** | ||
* @return The total length of the content that has to be read from this stream | ||
*/ | ||
public long getContentLength() { | ||
return contentLength; | ||
} | ||
|
||
/** | ||
* @return The offset pointer in the file that this stream is reading from | ||
*/ | ||
public long getOffset() { | ||
return offset; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
server/src/main/java/org/opensearch/common/StreamProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* StreamProvider is used to supply streams to vendor plugins using <code>StreamProvider#provideStream</code> | ||
*/ | ||
public class StreamProvider { | ||
|
||
private final TransferPartStreamSupplier streamSupplier; | ||
private final long partSize; | ||
private final long lastPartSize; | ||
private final int numOfParts; | ||
|
||
/** | ||
* Construct a new StreamProvider object | ||
* | ||
* @param streamSupplier An implementation of TransferPartStreamSupplier which will be called when provideStreams is called | ||
* @param partSize Size of all parts apart from the last one | ||
* @param lastPartSize Size of the last part | ||
* @param numOfParts Total number of parts | ||
*/ | ||
public StreamProvider(TransferPartStreamSupplier streamSupplier, long partSize, long lastPartSize, int numOfParts) { | ||
this.streamSupplier = streamSupplier; | ||
this.partSize = partSize; | ||
this.lastPartSize = lastPartSize; | ||
this.numOfParts = numOfParts; | ||
} | ||
|
||
/** | ||
* @param partNumber The index of the part | ||
* @return A stream reference to the part requested | ||
*/ | ||
public Stream provideStream(int partNumber) throws IOException { | ||
long position = partSize * partNumber; | ||
long size = (partNumber == numOfParts - 1) ? lastPartSize : partSize; | ||
return streamSupplier.supply(partNumber, size, position); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
server/src/main/java/org/opensearch/common/TransferPartStreamSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* TransferPartStreamSupplier is used to supply streams to specific parts of a file based on | ||
* the partNo, size and position (the offset in the file) | ||
*/ | ||
public interface TransferPartStreamSupplier { | ||
Stream supply(int partNo, long size, long position) throws IOException; | ||
} |
45 changes: 45 additions & 0 deletions
45
server/src/main/java/org/opensearch/common/blobstore/stream/StreamContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.blobstore.stream; | ||
|
||
import org.opensearch.common.StreamProvider; | ||
|
||
/** | ||
* StreamContext encapsulates all the data required for uploading multiple streams | ||
*/ | ||
public class StreamContext { | ||
|
||
private final StreamProvider streamProvider; | ||
private final int numberOfParts; | ||
|
||
/** | ||
* Construct a new StreamContext object | ||
* | ||
* @param streamProvider A stream provider to provide a stream for a given part number. | ||
* @param numberOfParts Number of parts of the content referenced by equivalent number of streams. | ||
*/ | ||
public StreamContext(StreamProvider streamProvider, int numberOfParts) { | ||
this.streamProvider = streamProvider; | ||
this.numberOfParts = numberOfParts; | ||
} | ||
|
||
/** | ||
* @return The stream iterable for the current upload | ||
*/ | ||
public StreamProvider getStreamProvider() { | ||
return streamProvider; | ||
} | ||
|
||
/** | ||
* @return The number of parts in current upload | ||
*/ | ||
public int getNumberOfParts() { | ||
return numberOfParts; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
server/src/main/java/org/opensearch/common/blobstore/stream/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/** Abstractions for stream based file transfers */ | ||
package org.opensearch.common.blobstore.stream; |
23 changes: 23 additions & 0 deletions
23
server/src/main/java/org/opensearch/common/blobstore/stream/write/StreamContextSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.blobstore.stream.write; | ||
|
||
import org.opensearch.common.blobstore.stream.StreamContext; | ||
|
||
/** | ||
* Will return the <code>StreamContext</code> to the caller given the part size | ||
*/ | ||
public interface StreamContextSupplier { | ||
|
||
/** | ||
* @param partSize The size of a single part to be uploaded | ||
* @return The <code>StreamContext</code> based on the part size provided | ||
*/ | ||
StreamContext supplyStreamContext(long partSize); | ||
} |
90 changes: 90 additions & 0 deletions
90
server/src/main/java/org/opensearch/common/blobstore/stream/write/WriteContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.blobstore.stream.write; | ||
|
||
import org.opensearch.common.blobstore.stream.StreamContext; | ||
import org.opensearch.common.blobstore.transfer.UploadFinalizer; | ||
|
||
/** | ||
* WriteContext is used to encapsulate all data needed by <code>BlobContainer#writeStreams</code> | ||
*/ | ||
public class WriteContext { | ||
|
||
private final String fileName; | ||
private final StreamContextSupplier streamContextSupplier; | ||
private final long fileSize; | ||
private final boolean failIfAlreadyExists; | ||
private final WritePriority writePriority; | ||
private final UploadFinalizer uploadFinalizer; | ||
|
||
/** | ||
* Construct a new WriteContext object | ||
* | ||
* @param fileName The name of the file being uploaded | ||
* @param streamContextSupplier A supplier that will provide StreamContext to the plugin | ||
* @param fileSize The total size of the file being uploaded | ||
* @param failIfAlreadyExists A boolean to fail the upload is the file exists | ||
* @param writePriority The <code>WritePriority</code> of this upload | ||
*/ | ||
public WriteContext( | ||
String fileName, | ||
StreamContextSupplier streamContextSupplier, | ||
long fileSize, | ||
boolean failIfAlreadyExists, | ||
WritePriority writePriority, | ||
UploadFinalizer uploadFinalizer | ||
) { | ||
this.fileName = fileName; | ||
this.streamContextSupplier = streamContextSupplier; | ||
this.fileSize = fileSize; | ||
this.failIfAlreadyExists = failIfAlreadyExists; | ||
this.writePriority = writePriority; | ||
this.uploadFinalizer = uploadFinalizer; | ||
} | ||
|
||
/** | ||
* @return The file name | ||
*/ | ||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
/** | ||
* @return The boolean representing whether to fail the file upload if it exists | ||
*/ | ||
public boolean isFailIfAlreadyExists() { | ||
return failIfAlreadyExists; | ||
} | ||
|
||
/** | ||
* @param partSize The size of a single part to be uploaded | ||
* @return The stream context which will be used by the plugin to initialize streams from the file | ||
*/ | ||
public StreamContext getStreamContext(long partSize) { | ||
return streamContextSupplier.supplyStreamContext(partSize); | ||
} | ||
|
||
/** | ||
* @return The total size of the file | ||
*/ | ||
public long getFileSize() { | ||
return fileSize; | ||
} | ||
|
||
/** | ||
* @return The <code>WritePriority</code> of the upload | ||
*/ | ||
public WritePriority getWritePriority() { | ||
return writePriority; | ||
} | ||
|
||
public UploadFinalizer getUploadFinalizer() { | ||
return uploadFinalizer; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
server/src/main/java/org/opensearch/common/blobstore/stream/write/WritePriority.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.blobstore.stream.write; | ||
|
||
/** | ||
* WritePriority for upload | ||
*/ | ||
public enum WritePriority { | ||
NORMAL, | ||
HIGH | ||
} |
10 changes: 10 additions & 0 deletions
10
server/src/main/java/org/opensearch/common/blobstore/stream/write/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/** Abstractions for stream based file writes */ | ||
package org.opensearch.common.blobstore.stream.write; |
Oops, something went wrong.