Skip to content

Commit

Permalink
Use pathTokens and add TODO for timing
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <[email protected]>
  • Loading branch information
soosinha committed Jun 5, 2024
1 parent 0dfe203 commit 6ab3918
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;

import static org.opensearch.gateway.remote.RemoteClusterStateUtils.PATH_DELIMITER;

/**
* Abstract class for a blob type storage
*
Expand Down Expand Up @@ -58,7 +55,7 @@ public void writeAsync(final U entity, final ActionListener<Void> listener) {
try (InputStream inputStream = entity.serialize()) {
BlobPath blobPath = getBlobPathForUpload(entity);
entity.setFullBlobName(blobPath);
// todo uncomment below logic after merging PR https://github.com/opensearch-project/OpenSearch/pull/13836
// TODO uncomment below logic after merging PR https://github.com/opensearch-project/OpenSearch/pull/13836
// transferService.uploadBlob(inputStream, getBlobPathForUpload(entity), entity.getBlobFileName(), WritePriority.URGENT,
// listener);
}
Expand All @@ -69,6 +66,7 @@ public void writeAsync(final U entity, final ActionListener<Void> listener) {

@Override
public U read(final U entity) throws IOException {
// TODO Add timing logs and tracing
assert entity.get() == null && entity.getFullBlobName() != null;
T object = entity.deserialize(transferService.downloadBlob(getBlobPathForDownload(entity), entity.getBlobFileName()));
entity.set(object);
Expand Down Expand Up @@ -98,16 +96,16 @@ private BlobPath getBlobPathForUpload(final AbstractRemoteWritableBlobEntity<T>
}

private BlobPath getBlobPathForDownload(final AbstractRemoteWritableBlobEntity<T> obj) {
String[] pathTokens = extractBlobPathTokens(obj.getFullBlobName());
String[] pathTokens = obj.getBlobPathTokens();
BlobPath blobPath = new BlobPath();
for (String token : pathTokens) {
blobPath = blobPath.add(token);
if (pathTokens == null || pathTokens.length < 1) {
return blobPath;
}
// Iterate till second last path token to get the blob folder
for (int i = 0; i < pathTokens.length - 1; i++) {
blobPath = blobPath.add(pathTokens[i]);
}
return blobPath;
}

private static String[] extractBlobPathTokens(final String blobName) {
String[] blobNameTokens = blobName.split(PATH_DELIMITER);
return Arrays.copyOfRange(blobNameTokens, 0, blobNameTokens.length - 1);
}
}

0 comments on commit 6ab3918

Please sign in to comment.