Skip to content

Commit

Permalink
Fix Spurious Warnings During Snapshot Delete (#75911) (#75919)
Browse files Browse the repository at this point in the history
We were trying to delete snapshots from index directories that they did not belong to
when bulk-deleting multiple snapshots that did not all contain the same set of indices.
This did not cause any further issues, except for confusing and needless warnings and
needlessly attempting deletes.
  • Loading branch information
original-brownbear authored Aug 5, 2021
1 parent e781441 commit 2e246d4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import com.carrotsearch.hppc.IntHashSet;
import com.carrotsearch.hppc.IntSet;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
Expand All @@ -33,6 +36,7 @@
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.CloseableChannel;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
Expand All @@ -59,6 +63,7 @@
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.MockLogAppender;
import org.elasticsearch.test.disruption.BusyMasterServiceDisruption;
import org.elasticsearch.test.disruption.ServiceDisruptionScheme;
import org.elasticsearch.test.rest.FakeRestRequest;
Expand Down Expand Up @@ -1305,6 +1310,38 @@ public void testConcurrentSnapshotAndRepoDelete() throws Exception {
}
}

public void testDeleteSnapshotsOfDifferentIndexSets() throws IllegalAccessException {
internalCluster().startMasterOnlyNodes(1);
internalCluster().startDataOnlyNode();
final String repoName = "test-repo";
createRepository(repoName, "fs");

final MockLogAppender mockAppender = new MockLogAppender();
mockAppender.addExpectation(
new MockLogAppender.UnseenEventExpectation("no warnings", BlobStoreRepository.class.getCanonicalName(), Level.WARN, "*")
);
mockAppender.start();
final Logger logger = LogManager.getLogger(BlobStoreRepository.class);
Loggers.addAppender(logger, mockAppender);
try {
final String index1 = "index-1";
final String index2 = "index-2";
createIndexWithContent("index-1");
createIndexWithContent("index-2");
createFullSnapshot(repoName, "full-snapshot");
final String snapshot1 = "index-1-snapshot";
final String snapshot2 = "index-2-snapshot";
createSnapshot(repoName, snapshot1, org.elasticsearch.core.List.of(index1));
createSnapshot(repoName, snapshot2, org.elasticsearch.core.List.of(index2));

clusterAdmin().prepareDeleteSnapshot(repoName, snapshot1, snapshot2).get();
mockAppender.assertAllExpectationsMatched();
} finally {
Loggers.removeAppender(logger, mockAppender);
mockAppender.stop();
}
}

private long calculateTotalFilesSize(List<Path> files) {
return files.stream().mapToLong(f -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1031,12 +1031,13 @@ private void writeUpdatedShardMetaDataAndComputeDeletes(
);

for (IndexId indexId : indices) {
final Set<SnapshotId> survivingSnapshots = oldRepositoryData.getSnapshots(indexId)
.stream()
final Set<SnapshotId> snapshotsWithIndex = org.elasticsearch.core.Set.copyOf(oldRepositoryData.getSnapshots(indexId));
final Set<SnapshotId> survivingSnapshots = snapshotsWithIndex.stream()
.filter(id -> snapshotIds.contains(id) == false)
.collect(Collectors.toSet());
final StepListener<Collection<Integer>> shardCountListener = new StepListener<>();
final Collection<String> indexMetaGenerations = snapshotIds.stream()
.filter(snapshotsWithIndex::contains)
.map(id -> oldRepositoryData.indexMetaDataGenerations().indexMetaBlobId(id, indexId))
.collect(Collectors.toSet());
final ActionListener<Integer> allShardCountsListener = new GroupedActionListener<>(
Expand Down

0 comments on commit 2e246d4

Please sign in to comment.