Skip to content

Commit

Permalink
Skip unreferenced files pruning after restore for searchable snapshot…
Browse files Browse the repository at this point in the history
…s 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.
  • Loading branch information
tlrx committed Feb 11, 2021
1 parent c8e10a5 commit ee0d2e2
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import static java.util.Collections.emptyMap;
import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;

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

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

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

0 comments on commit ee0d2e2

Please sign in to comment.