Skip to content

Commit

Permalink
Addressing PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Raghuvansh Raj <[email protected]>
  • Loading branch information
raghuvanshraj committed Jun 8, 2023
1 parent 6b2335c commit b6e902d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

package org.opensearch.common.blobstore.stream.write;

import org.opensearch.common.CheckedConsumer;
import org.opensearch.common.Nullable;
import org.opensearch.common.StreamContext;

import java.util.function.Consumer;
import java.io.IOException;

/**
* WriteContext is used to encapsulate all data needed by <code>BlobContainer#writeStreams</code>
Expand All @@ -25,7 +26,7 @@ public class WriteContext {
private final long fileSize;
private final boolean failIfAlreadyExists;
private final WritePriority writePriority;
private final Consumer<Boolean> uploadFinalizer;
private final CheckedConsumer<Boolean, IOException> uploadFinalizer;
private final boolean doRemoteDataIntegrityCheck;
private final Long expectedChecksum;

Expand All @@ -46,7 +47,7 @@ public WriteContext(
long fileSize,
boolean failIfAlreadyExists,
WritePriority writePriority,
Consumer<Boolean> uploadFinalizer,
CheckedConsumer<Boolean, IOException> uploadFinalizer,
boolean doRemoteDataIntegrityCheck,
@Nullable Long expectedChecksum
) {
Expand Down Expand Up @@ -99,7 +100,7 @@ public WritePriority getWritePriority() {
/**
* @return The <code>UploadFinalizer</code> for this upload
*/
public Consumer<Boolean> getUploadFinalizer() {
public CheckedConsumer<Boolean, IOException> getUploadFinalizer() {
return uploadFinalizer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,22 @@ private boolean isRemoteDataIntegrityCheckPossible() {
return isRemoteDataIntegritySupported;
}

private void finalizeUpload(boolean uploadSuccessful) {
private void finalizeUpload(boolean uploadSuccessful) throws IOException {
if (isRemoteDataIntegrityCheckPossible()) {
return;
}

if (uploadSuccessful) {
long actualChecksum = getActualChecksum();
if (actualChecksum != expectedChecksum) {
throw new RuntimeException(
new CorruptIndexException(
"Data integrity check done after upload for file "
+ fileName
+ " failed, actual checksum: "
+ actualChecksum
+ ", expected checksum: "
+ expectedChecksum,
fileName
)
throw new CorruptIndexException(
"Data integrity check done after upload for file "
+ fileName
+ " failed, actual checksum: "
+ actualChecksum
+ ", expected checksum: "
+ expectedChecksum,
fileName
);
}
}
Expand Down

0 comments on commit b6e902d

Please sign in to comment.