Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Needless Warnings when Restoring over Closed Index #75912

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -876,4 +882,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, List.of(indexName));
index(indexName, "some_id", 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 @@ -1116,7 +1116,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