Skip to content

Commit

Permalink
Fix Needless Warnings when Restoring over Closed Index (#75912) (#75926)
Browse files Browse the repository at this point in the history
We're trying to delete each file twice and will always warn on the second non-suppressing
delete method when there's files to delete.
  • Loading branch information
original-brownbear committed Aug 15, 2021
1 parent 6ee2546 commit f115524
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

package org.elasticsearch.snapshots;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
Expand All @@ -18,14 +21,17 @@
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.indices.InvalidIndexNameException;
import org.elasticsearch.repositories.RepositoriesService;
import org.elasticsearch.repositories.blobstore.FileRestoreContext;
import org.elasticsearch.repositories.fs.FsRepository;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.MockLogAppender;

import java.nio.file.Path;
import java.util.Arrays;
Expand Down Expand Up @@ -878,4 +884,34 @@ public void testFailOnAncientVersion() throws Exception {
)
);
}

public void testNoWarningsOnRestoreOverClosedIndex() throws IllegalAccessException {
final String repoName = "test-repo";
createRepository(repoName, FsRepository.TYPE);
final String indexName = "test-idx";
createIndexWithContent(indexName);
final String snapshotName = "test-snapshot";
createSnapshot(repoName, snapshotName, org.elasticsearch.core.List.of(indexName));
index(indexName, "_doc", "some_id", org.elasticsearch.core.Map.of("foo", "bar"));
assertAcked(admin().indices().prepareClose(indexName).get());
final MockLogAppender mockAppender = new MockLogAppender();
mockAppender.addExpectation(
new MockLogAppender.UnseenEventExpectation("no warnings", FileRestoreContext.class.getCanonicalName(), Level.WARN, "*")
);
mockAppender.start();
final Logger logger = LogManager.getLogger(FileRestoreContext.class);
Loggers.addAppender(logger, mockAppender);
try {
final RestoreSnapshotResponse restoreSnapshotResponse = clusterAdmin().prepareRestoreSnapshot(repoName, snapshotName)
.setIndices(indexName)
.setRestoreGlobalState(false)
.setWaitForCompletion(true)
.get();
assertEquals(0, restoreSnapshotResponse.getRestoreInfo().failedShards());
mockAppender.assertAllExpectationsMatched();
} finally {
Loggers.removeAppender(logger, mockAppender);
mockAppender.stop();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ public String toString() {

/**
* Returns true if the file is auto-generated by the store and shouldn't be deleted during cleanup.
* This includes write lock and checksum files
* This includes write lock files
*/
public static boolean isAutogenerated(String name) {
return IndexWriter.WRITE_LOCK_NAME.equals(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,9 @@ private void afterRestore(SnapshotFiles snapshotFiles, Store store, StoreFileMet
try {
for (String storeFile : store.directory().listAll()) {
if (Store.isAutogenerated(storeFile) || snapshotFiles.containPhysicalIndexFile(storeFile)) {
continue; // skip write.lock, checksum files and files that exist in the snapshot
continue; // skip write.lock and files that exist in the snapshot
}
try {
store.deleteQuiet("restore", storeFile);
store.directory().deleteFile(storeFile);
} catch (ImmutableDirectoryException e) {
// snapshots of immutable directories only contain an empty `segments_N` file since the data lives elsewhere, and if we
Expand Down

0 comments on commit f115524

Please sign in to comment.