Skip to content

Commit

Permalink
Removed all bytes read method from RemoteDirectory for safety
Browse files Browse the repository at this point in the history
Signed-off-by: Vikas Bansal <43470111+vikasvb90@users.noreply.github.com>
  • Loading branch information
vikasvb90 committed Sep 4, 2023
1 parent b69fd94 commit 9ace55a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,14 @@ public void onFailure(Exception e) {
}

/**
* Reads entire content from remote file. This should be used to read small files as it loads entire content
* in memory.
* Returns stream emitted from by blob object. Should be used with a closeable block.
*
* @param fileName Name of file
* @return Content read
* @throws IOException if read fails with IO error
* @return Stream from the blob object
* @throws IOException if fetch of stream fails with IO error
*/
public byte[] readAllBytes(String fileName) throws IOException {
try (InputStream inputStream = blobContainer.readBlob(fileName)) {
return inputStream.readAllBytes();
}
public InputStream getBlobStream(String fileName) throws IOException {
return blobContainer.readBlob(fileName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.NoSuchFileException;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -190,8 +191,10 @@ public RemoteSegmentMetadata readLatestMetadataFile() throws IOException {
}

private RemoteSegmentMetadata readMetadataFile(String metadataFilename) throws IOException {
byte[] metadataBytes = remoteMetadataDirectory.readAllBytes(metadataFilename);
return metadataStreamWrapper.readStream(new ByteArrayIndexInput(metadataFilename, metadataBytes));
try (InputStream inputStream = remoteDataDirectory.getBlobStream(metadataFilename)) {
byte[] metadataBytes = inputStream.readAllBytes();
return metadataStreamWrapper.readStream(new ByteArrayIndexInput(metadataFilename, metadataBytes));
}
}

/**
Expand Down

0 comments on commit 9ace55a

Please sign in to comment.