Skip to content

Commit 9f4e99d

Browse files
authored
Stop sorting indices in get-snapshots API (#94890)
Today the get-snapshots API sorts the index list by name for every completed snapshot that matches the requested name pattern. This is pretty time-consuming in a large cluster, and much of the work is wasted when using pagination options that will filter out the snapshot later on in the process. Moreover we only do this when `?verbose=false`, and we don't do this for ongoing snapshots. There's nothing in the docs about the index list being in sorted order either, so I think we can just skip this step and save a bunch of time.
1 parent 131da70 commit 9f4e99d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

docs/changelog/94890.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 94890
2+
summary: Stop sorting indices in get-snapshots API
3+
area: Snapshot/Restore
4+
type: bug
5+
issues: []

server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,8 +2238,7 @@ public void testIndexLatestFailuresIgnored() throws Exception {
22382238

22392239
private void verifySnapshotInfo(final GetSnapshotsResponse response, final Map<String, List<String>> indicesPerSnapshot) {
22402240
for (SnapshotInfo snapshotInfo : response.getSnapshots()) {
2241-
final List<String> expected = snapshotInfo.indices();
2242-
assertEquals(expected, indicesPerSnapshot.get(snapshotInfo.snapshotId().getName()));
2241+
assertEquals(Set.copyOf(indicesPerSnapshot.get(snapshotInfo.snapshotId().getName())), Set.copyOf(snapshotInfo.indices()));
22432242
assertEquals(SnapshotState.SUCCESS, snapshotInfo.state());
22442243
}
22452244
}

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
package org.elasticsearch.action.admin.cluster.snapshots.get;
1010

11-
import org.apache.lucene.util.CollectionUtil;
1211
import org.elasticsearch.ElasticsearchException;
1312
import org.elasticsearch.action.ActionListener;
1413
import org.elasticsearch.action.StepListener;
@@ -509,12 +508,10 @@ private static SnapshotsInRepo buildSimpleSnapshotInfos(
509508
}
510509
}
511510
for (Snapshot snapshot : toResolve) {
512-
final List<String> indices = snapshotsToIndices.getOrDefault(snapshot.getSnapshotId(), Collections.emptyList());
513-
CollectionUtil.timSort(indices);
514511
snapshotInfos.add(
515512
new SnapshotInfo(
516513
snapshot,
517-
indices,
514+
snapshotsToIndices.getOrDefault(snapshot.getSnapshotId(), Collections.emptyList()),
518515
Collections.emptyList(),
519516
Collections.emptyList(),
520517
repositoryData.getSnapshotState(snapshot.getSnapshotId())

0 commit comments

Comments
 (0)