From fb503986f37119a12437cff841a47d98ab504c71 Mon Sep 17 00:00:00 2001 From: Ashish Singh Date: Wed, 13 Nov 2024 00:33:12 +0530 Subject: [PATCH] Address PR review comments Signed-off-by: Ashish Singh --- .../blobstore/BlobStoreRepository.java | 27 +++++++++---------- .../snapshots/SnapshotShardPaths.java | 10 ++++--- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java b/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java index 21802e26072d1..3343bb735ab6e 100644 --- a/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java +++ b/server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java @@ -2565,7 +2565,9 @@ private void cleanupRedundantSnapshotShardPaths(Set updatedShardPathsInd Set updatedIndexIds = updatedShardPathsIndexIds.stream() .map(s -> getIndexId(s.split("\\" + SnapshotShardPaths.DELIMITER)[0])) .collect(Collectors.toSet()); + logger.debug(new ParameterizedMessage("updatedIndexIds={}", updatedIndexIds)); Set indexIdShardPaths = getSnapshotShardPaths().keySet(); + logger.debug(new ParameterizedMessage("indexIdShardPaths={}", indexIdShardPaths)); List staleShardPaths = indexIdShardPaths.stream() .filter(s -> updatedShardPathsIndexIds.contains(s) == false) .filter(s -> { @@ -2573,20 +2575,17 @@ private void cleanupRedundantSnapshotShardPaths(Set updatedShardPathsInd return updatedIndexIds.contains(indexId); }) .collect(Collectors.toList()); - try { - deleteFromContainer(snapshotShardPathBlobContainer(), staleShardPaths); - } catch (IOException e) { - logger.warn( - new ParameterizedMessage( - "Repository [{}] Exception during snapshot stale index deletion {}", - metadata.name(), - staleShardPaths - ), - e - ); - } - } catch (Exception ex) { - logger.error("Exception during cleanup of redundant snapshot shard paths", ex); + logger.debug(new ParameterizedMessage("staleShardPaths={}", staleShardPaths)); + deleteFromContainer(snapshotShardPathBlobContainer(), staleShardPaths); + } catch (Exception e) { + logger.warn( + new ParameterizedMessage( + "Repository [{}] Exception during snapshot stale index deletion for updatedIndexIds {}", + metadata.name(), + updatedShardPathsIndexIds + ), + e + ); } } diff --git a/server/src/main/java/org/opensearch/snapshots/SnapshotShardPaths.java b/server/src/main/java/org/opensearch/snapshots/SnapshotShardPaths.java index 64a308c1c2d4e..dd0b67ca9bfaa 100644 --- a/server/src/main/java/org/opensearch/snapshots/SnapshotShardPaths.java +++ b/server/src/main/java/org/opensearch/snapshots/SnapshotShardPaths.java @@ -92,7 +92,7 @@ public static SnapshotShardPaths fromXContent(XContentParser ignored) { * Parses a shard path string and extracts relevant shard information. * * @param shardPath The shard path string to parse. Expected format is: - * [index_id].[index_name].[shard_count].[path_type_code].[path_hash_algorithm_code] + * snapshot_path_[index_id].[index_name].[shard_count].[path_type_code].[path_hash_algorithm_code] * @return A {@link ShardInfo} object containing the parsed index ID and shard count. * @throws IllegalArgumentException if the shard path format is invalid or cannot be parsed. */ @@ -103,8 +103,12 @@ public static ShardInfo parseShardPath(String shardPath) { throw new IllegalArgumentException("Invalid shard path format: " + shardPath); } try { - // indexName is never used from within the ShardInfo returned - String indexName = len == 5 ? parts[1] : ""; + String indexName = shardPath.substring( + // First separator after index id + shardPath.indexOf(DELIMITER) + 1, + // Since we know there are exactly 3 fields at the end + shardPath.lastIndexOf(DELIMITER, shardPath.lastIndexOf(DELIMITER, shardPath.lastIndexOf(DELIMITER) - 1) - 1) + ); IndexId indexId = new IndexId(indexName, getIndexId(parts[0]), Integer.parseInt(parts[len - 2])); int shardCount = Integer.parseInt(parts[len - 3]); return new ShardInfo(indexId, shardCount);