Skip to content

Commit

Permalink
Correct the usage of BlobPath
Browse files Browse the repository at this point in the history
Signed-off-by: bansvaru <[email protected]>
  • Loading branch information
linuxpi committed Sep 5, 2023
1 parent 57b4ddb commit ec19e49
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,15 @@ public UploadedIndexMetadata(StreamInput in) throws IOException {
this.uploadedFilename = in.readString();
}

public String getUploadedFilename() {
public String getUploadedFilePath() {
return uploadedFilename;
}

public String getUploadedFilename() {
String[] splitPath = uploadedFilename.split("/");
return splitPath[splitPath.length - 1];
}

public String getIndexName() {
return indexName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,63 +525,64 @@ public void deleteClusterMetadataMarker(String clusterName, String clusterUUID,
"manifest",
Integer.MAX_VALUE,
new ActionListener<>() {
int checkedManifestCount = 1;
int evaluatedManifestCount = 1;

@Override
public void onResponse(List<BlobMetadata> blobMetadata) {
Set<String> filesToKeep = new HashSet<>();
BlobPath staleBlobPath = new BlobPath();
List<String> stalePaths = new ArrayList<>();
blobMetadata.forEach(manifestBlobMetadata -> {
ClusterMetadataManifest clusterMetadataManifest = fetchRemoteClusterMetadataManifest(
clusterName,
clusterUUID,
manifestBlobMetadata.name()
);
if (checkedManifestCount <= manifestsToRetain) {
if (evaluatedManifestCount <= manifestsToRetain) {
clusterMetadataManifest.getIndices()
.forEach(uploadedIndexMetadata -> filesToKeep.add(uploadedIndexMetadata.getUploadedFilename()));
} else {
staleBlobPath.add(
getManifestFolderPath(clusterName, clusterUUID).add(
getManifestFileNamePrefix(
clusterMetadataManifest.getClusterTerm(),
clusterMetadataManifest.getStateVersion()
)
).toString()
);
stalePaths.add(new BlobPath().add("manifest").add(manifestBlobMetadata.name()).buildAsString());
clusterMetadataManifest.getIndices().forEach(uploadedIndexMetadata -> {
if (filesToKeep.contains(uploadedIndexMetadata.getUploadedFilename()) == false) {
staleBlobPath.add(uploadedIndexMetadata.getUploadedFilename());
stalePaths.add(
new BlobPath().add("index").add(uploadedIndexMetadata.getUploadedFilename()).buildAsString()
);
}
});
}
checkedManifestCount += 1;
evaluatedManifestCount += 1;
});

logger.trace(String.format(Locale.ROOT, "Deleting stale files from remote - %s", staleBlobPath));
if (staleBlobPath.toArray().length == 0) {
logger.trace(String.format(Locale.ROOT, "Deleting stale files from remote - %s", stalePaths));

if (stalePaths.toArray().length == 0) {
logger.trace("No stale Remote Cluster Metadata files found");
return;
}

transferService.deleteAsync(ThreadPool.Names.REMOTE_PURGE, staleBlobPath, new ActionListener<>() {
@Override
public void onResponse(Void unused) {
logger.info(
String.format(Locale.ROOT, "Deleted [%s] stale Remote Cluster Metadata files", staleBlobPath.size())
);
}

@Override
public void onFailure(Exception e) {
logger.error(
new ParameterizedMessage(
"Exception occurred while deleting stale Remote Cluster Metadata files - {}",
staleBlobPath
)
);
transferService.deleteBlobsAsync(
ThreadPool.Names.REMOTE_PURGE,
getCusterMetadataBasePath(clusterName, clusterUUID),
stalePaths,
new ActionListener<>() {
@Override
public void onResponse(Void unused) {
logger.info(
String.format(Locale.ROOT, "Deleted [%s] stale Remote Cluster Metadata files", stalePaths.size())
);
}

@Override
public void onFailure(Exception e) {
logger.error(
new ParameterizedMessage(
"Exception occurred while deleting stale Remote Cluster Metadata files - {}",
stalePaths
)
);
}
}
});
);
}

@Override
Expand Down

0 comments on commit ec19e49

Please sign in to comment.