Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions docs/changelog/122047.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 122047
summary: Fork post-snapshot-delete cleanup off master thread
area: Snapshot/Restore
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.snapshots.SnapshotInfo;
import org.elasticsearch.snapshots.SnapshotState;
import org.elasticsearch.snapshots.SnapshotsService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;

Expand Down Expand Up @@ -377,6 +378,7 @@ private static boolean isIndexToUpdateAfterRemovingSnapshots(
* @return map of index to index metadata blob id to delete
*/
public Map<IndexId, Collection<String>> indexMetaDataToRemoveAfterRemovingSnapshots(Collection<SnapshotId> snapshotIds) {
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.SNAPSHOT);
Iterator<IndexId> indicesForSnapshot = indicesToUpdateAfterRemovingSnapshot(snapshotIds);
final Set<String> allRemainingIdentifiers = indexMetaDataGenerations.lookup.entrySet()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1134,14 +1134,20 @@ private void runWithUniqueShardMetadataNaming(ActionListener<RepositoryData> rep
);
})

.<RepositoryData>andThen((l, newRepositoryData) -> {
l.onResponse(newRepositoryData);
// Once we have updated the repository, run the unreferenced blobs cleanup in parallel to shard-level snapshot deletion
try (var refs = new RefCountingRunnable(onCompletion)) {
cleanupUnlinkedRootAndIndicesBlobs(newRepositoryData, refs.acquireListener());
cleanupUnlinkedShardLevelBlobs(refs.acquireListener());
.<RepositoryData>andThen(
// writeIndexGen finishes on master-service thread so must fork here.
snapshotExecutor,
threadPool.getThreadContext(),
(l, newRepositoryData) -> {
l.onResponse(newRepositoryData);
// Once we have updated the repository, run the unreferenced blobs cleanup in parallel to shard-level snapshot
// deletion
try (var refs = new RefCountingRunnable(onCompletion)) {
cleanupUnlinkedRootAndIndicesBlobs(newRepositoryData, refs.acquireListener());
cleanupUnlinkedShardLevelBlobs(refs.acquireListener());
}
}
})
)

.addListener(repositoryDataUpdateListener);
}
Expand Down