Skip to content

Commit

Permalink
Address PR review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Singh <[email protected]>
  • Loading branch information
ashking94 committed Nov 12, 2024
1 parent c172683 commit fb50398
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2565,28 +2565,27 @@ private void cleanupRedundantSnapshotShardPaths(Set<String> updatedShardPathsInd
Set<String> updatedIndexIds = updatedShardPathsIndexIds.stream()
.map(s -> getIndexId(s.split("\\" + SnapshotShardPaths.DELIMITER)[0]))
.collect(Collectors.toSet());
logger.debug(new ParameterizedMessage("updatedIndexIds={}", updatedIndexIds));
Set<String> indexIdShardPaths = getSnapshotShardPaths().keySet();
logger.debug(new ParameterizedMessage("indexIdShardPaths={}", indexIdShardPaths));
List<String> staleShardPaths = indexIdShardPaths.stream()
.filter(s -> updatedShardPathsIndexIds.contains(s) == false)
.filter(s -> {
String indexId = getIndexId(s.split("\\" + SnapshotShardPaths.DELIMITER)[0]);
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) {

Check warning on line 2580 in server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java#L2580

Added line #L2580 was not covered by tests
logger.warn(
new ParameterizedMessage(
"Repository [{}] Exception during snapshot stale index deletion for updatedIndexIds {}",
metadata.name(),
updatedShardPathsIndexIds
),
e
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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);
Expand Down

0 comments on commit fb50398

Please sign in to comment.