diff --git a/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java b/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java index cac77f9996438..5f51dbbc2d0e5 100644 --- a/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java +++ b/server/src/main/java/org/opensearch/gateway/remote/ClusterMetadataManifest.java @@ -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; } diff --git a/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java b/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java index ecca24e18cb3e..1aba061ad857c 100644 --- a/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java +++ b/server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java @@ -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) { Set filesToKeep = new HashSet<>(); - BlobPath staleBlobPath = new BlobPath(); + List 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