Skip to content

Commit c95e51c

Browse files
Fix Index Deletion during Snapshot Finalization (#50202) (#50228)
* Fix Index Deletion during Snapshot Finalization (#50202) With #45689 making it so that index metadata is written after all shards have been snapshotted we can't delete indices that are part of the upcoming snapshot finalization any longer and it is not sufficient to check if all shards of an index have been snapshotted before deciding that it is safe to delete it. This change forbids deleting any index that is in the process of being snapshot to avoid issues during snapshot finalization. Relates #50200 (doesn't fully fix yet because we're not fixing the `partial=true` snapshot case here
1 parent d50ac53 commit c95e51c

File tree

2 files changed

+129
-62
lines changed

2 files changed

+129
-62
lines changed

server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java

+4-15
Original file line numberDiff line numberDiff line change
@@ -1468,21 +1468,10 @@ public static Set<Index> snapshottingIndices(final ClusterState currentState, fi
14681468
final Set<Index> indices = new HashSet<>();
14691469
for (final SnapshotsInProgress.Entry entry : snapshots.entries()) {
14701470
if (entry.partial() == false) {
1471-
if (entry.state() == State.INIT) {
1472-
for (IndexId index : entry.indices()) {
1473-
IndexMetaData indexMetaData = currentState.metaData().index(index.getName());
1474-
if (indexMetaData != null && indicesToCheck.contains(indexMetaData.getIndex())) {
1475-
indices.add(indexMetaData.getIndex());
1476-
}
1477-
}
1478-
} else {
1479-
for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shard : entry.shards()) {
1480-
Index index = shard.key.getIndex();
1481-
if (indicesToCheck.contains(index)
1482-
&& shard.value.state().completed() == false
1483-
&& currentState.getMetaData().index(index) != null) {
1484-
indices.add(index);
1485-
}
1471+
for (IndexId index : entry.indices()) {
1472+
IndexMetaData indexMetaData = currentState.metaData().index(index.getName());
1473+
if (indexMetaData != null && indicesToCheck.contains(indexMetaData.getIndex())) {
1474+
indices.add(indexMetaData.getIndex());
14861475
}
14871476
}
14881477
}

0 commit comments

Comments
 (0)