Skip to content

Commit 4d3c22b

Browse files
committed
Fork post-snapshot-delete cleanup off master thread
We shouldn't run the post-snapshot-delete cleanup work on the master thread, since it can be quite expensive and need not block subsequent cluster state updates. This commit forks it onto a `SNAPSHOT` thread.
1 parent 8d4f034 commit 4d3c22b

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

server/src/main/java/org/elasticsearch/repositories/RepositoryData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.snapshots.SnapshotInfo;
3030
import org.elasticsearch.snapshots.SnapshotState;
3131
import org.elasticsearch.snapshots.SnapshotsService;
32+
import org.elasticsearch.threadpool.ThreadPool;
3233
import org.elasticsearch.xcontent.XContentBuilder;
3334
import org.elasticsearch.xcontent.XContentParser;
3435

@@ -377,6 +378,7 @@ private static boolean isIndexToUpdateAfterRemovingSnapshots(
377378
* @return map of index to index metadata blob id to delete
378379
*/
379380
public Map<IndexId, Collection<String>> indexMetaDataToRemoveAfterRemovingSnapshots(Collection<SnapshotId> snapshotIds) {
381+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.SNAPSHOT);
380382
Iterator<IndexId> indicesForSnapshot = indicesToUpdateAfterRemovingSnapshot(snapshotIds);
381383
final Set<String> allRemainingIdentifiers = indexMetaDataGenerations.lookup.entrySet()
382384
.stream()

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,14 +1134,20 @@ private void runWithUniqueShardMetadataNaming(ActionListener<RepositoryData> rep
11341134
);
11351135
})
11361136

1137-
.<RepositoryData>andThen((l, newRepositoryData) -> {
1138-
l.onResponse(newRepositoryData);
1139-
// Once we have updated the repository, run the unreferenced blobs cleanup in parallel to shard-level snapshot deletion
1140-
try (var refs = new RefCountingRunnable(onCompletion)) {
1141-
cleanupUnlinkedRootAndIndicesBlobs(newRepositoryData, refs.acquireListener());
1142-
cleanupUnlinkedShardLevelBlobs(refs.acquireListener());
1137+
.<RepositoryData>andThen(
1138+
// writeIndexGen finishes on master-service thread so must fork here.
1139+
snapshotExecutor,
1140+
threadPool.getThreadContext(),
1141+
(l, newRepositoryData) -> {
1142+
l.onResponse(newRepositoryData);
1143+
// Once we have updated the repository, run the unreferenced blobs cleanup in parallel to shard-level snapshot
1144+
// deletion
1145+
try (var refs = new RefCountingRunnable(onCompletion)) {
1146+
cleanupUnlinkedRootAndIndicesBlobs(newRepositoryData, refs.acquireListener());
1147+
cleanupUnlinkedShardLevelBlobs(refs.acquireListener());
1148+
}
11431149
}
1144-
})
1150+
)
11451151

11461152
.addListener(repositoryDataUpdateListener);
11471153
}

0 commit comments

Comments
 (0)