Skip to content

Commit

Permalink
Adding changelog and applying gradle precommit
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Sarda <[email protected]>
  • Loading branch information
Vishalks committed Nov 4, 2022
1 parent e9f450a commit bf32979
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Data node side change([#4204](https://github.com/opensearch-project/OpenSearch/pull/4204))
- on-boarding of tasks([#4542](https://github.com/opensearch-project/OpenSearch/pull/4542))
- Integs ([4588](https://github.com/opensearch-project/OpenSearch/pull/4588))
- Prevent deletion of snapshots that are backing searchable snapshot indexes ([#5069](https://github.com/opensearch-project/OpenSearch/pull/5069))

### Dependencies
- Bumps `log4j-core` from 2.18.0 to 2.19.0
Expand Down
31 changes: 20 additions & 11 deletions server/src/main/java/org/opensearch/snapshots/SnapshotsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.opensearch.ExceptionsHelper;
import org.opensearch.OpenSearchStatusException;
import org.opensearch.Version;
import org.opensearch.action.ActionListener;
import org.opensearch.action.ActionRunnable;
Expand Down Expand Up @@ -92,8 +91,6 @@
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException;
import org.opensearch.http.HttpException;
import org.opensearch.index.Index;
import org.opensearch.index.IndexModule;
import org.opensearch.index.shard.ShardId;
Expand Down Expand Up @@ -1774,32 +1771,44 @@ public ClusterState execute(ClusterState currentState) throws Exception {
repoName
);
final List<SnapshotId> snapshotIdNotBackingIndex = filterSnapshotsBackingAnyIndex(currentState, snapshotIds);
deleteFromRepoTask = createDeleteStateUpdate(snapshotIdNotBackingIndex, repoName, repositoryData, Priority.NORMAL, listener);
deleteFromRepoTask = createDeleteStateUpdate(
snapshotIdNotBackingIndex,
repoName,
repositoryData,
Priority.NORMAL,
listener
);
return deleteFromRepoTask.execute(currentState);
}

private List<SnapshotId> filterSnapshotsBackingAnyIndex(ClusterState currentState, List<SnapshotId> snapshotIds){
private List<SnapshotId> filterSnapshotsBackingAnyIndex(ClusterState currentState, List<SnapshotId> snapshotIds) {
final Set<SnapshotId> snapshotsToBeDeleted = new HashSet<>();
final Set<String> snapshotsToBeNotDeleted = new HashSet<>();
ImmutableOpenMap<String, IndexMetadata> indicesMap = currentState.getMetadata().getIndices();
for(SnapshotId snapshotId: snapshotIds) {
for (SnapshotId snapshotId : snapshotIds) {
Boolean indexBackedBySnapshotFound = false;
for (Iterator<IndexMetadata> it = indicesMap.valuesIt(); it.hasNext(); ) {
for (Iterator<IndexMetadata> it = indicesMap.valuesIt(); it.hasNext();) {
IndexMetadata indexMetadata = it.next();
String storeType = indexMetadata.getSettings().get(IndexModule.INDEX_STORE_TYPE_SETTING.getKey());
if(storeType != null && storeType.equals(IndexModule.Type.REMOTE_SNAPSHOT.getSettingsKey()) && indexMetadata.getSettings().get("index.searchable_snapshot.snapshot_id.uuid").equals(snapshotId.getUUID())){
if (storeType != null
&& storeType.equals(IndexModule.Type.REMOTE_SNAPSHOT.getSettingsKey())
&& indexMetadata.getSettings().get("index.searchable_snapshot.snapshot_id.uuid").equals(snapshotId.getUUID())) {
indexBackedBySnapshotFound = true;
break;
}
}
if(indexBackedBySnapshotFound == false) {
if (indexBackedBySnapshotFound == false) {
snapshotsToBeDeleted.add(snapshotId);
} else {
snapshotsToBeNotDeleted.add(snapshotId.getName());
}
}
if(snapshotIds.size() != snapshotsToBeDeleted.size()) {
throw new SnapshotDeletionException(repoName, snapshotsToBeNotDeleted.toString(), "These remote snapshots are backing some indices and hence can't be deleted! No snapshots were deleted.");
if (snapshotIds.size() != snapshotsToBeDeleted.size()) {
throw new SnapshotDeletionException(
repoName,
snapshotsToBeNotDeleted.toString(),
"These remote snapshots are backing some indices and hence can't be deleted! No snapshots were deleted."
);
}
return List.copyOf(snapshotsToBeDeleted);
}
Expand Down

0 comments on commit bf32979

Please sign in to comment.