Skip to content

Commit ee0d2e2

Browse files
authored
Skip unreferenced files pruning after restore for searchable snapshots shards (#68821) (#68845)
When a shard is restored from a snapshot there is an after restore step during which files on disk that are not referenced anymore by the restored segments infos file are deleted from disk. The deletion is executed using the Lucene.pruneUnreferencedFiles() method which opens a new IndexWriter and closes it in order to kick off Lucene's internal index files deleter. This step is not necessary for searchable snapshot shards which use the snapshot store type because such shards report a list of files coming from a shard snapshot which never contain unreferenced files. Skipping this step avoids extra unnecessary work when mounting a searchable snapshot index.
1 parent c8e10a5 commit ee0d2e2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

server/src/main/java/org/elasticsearch/repositories/blobstore/FileRestoreContext.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import static java.util.Collections.emptyMap;
3434
import static java.util.Collections.unmodifiableMap;
35+
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
3536

3637
/**
3738
* This context will execute a file restore of the lucene files. It is primarily designed to be used to
@@ -164,11 +165,14 @@ public void restore(SnapshotFiles snapshotFiles, Store store, ActionListener<Voi
164165
}
165166

166167
private void afterRestore(SnapshotFiles snapshotFiles, Store store, StoreFileMetadata restoredSegmentsFile) {
167-
// read the snapshot data persisted
168168
try {
169-
Lucene.pruneUnreferencedFiles(restoredSegmentsFile.name(), store.directory());
169+
final String indexStoreType = INDEX_STORE_TYPE_SETTING.get(store.indexSettings().getSettings());
170+
if ("snapshot".equals(indexStoreType) == false) {
171+
Lucene.pruneUnreferencedFiles(restoredSegmentsFile.name(), store.directory());
172+
}
170173
} catch (IOException e) {
171-
throw new IndexShardRestoreFailedException(shardId, "Failed to fetch index version after copying it over", e);
174+
throw new IndexShardRestoreFailedException(shardId, "Failed to remove files not referenced in segment file ["
175+
+ restoredSegmentsFile.name() + "] after restore", e);
172176
}
173177

174178
/// now, go over and clean files that are in the store, but were not in the snapshot

0 commit comments

Comments
 (0)