diff --git a/docs/changelog/89534.yaml b/docs/changelog/89534.yaml new file mode 100644 index 0000000000000..8fbb3089003eb --- /dev/null +++ b/docs/changelog/89534.yaml @@ -0,0 +1,5 @@ +pr: 89534 +summary: Fix incorrect failed shards count in APIs for current snapshots +area: Snapshot/Restore +type: bug +issues: [] diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/GetSnapshotsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/GetSnapshotsIT.java index caeceae57e524..f36e8e8e6e903 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/GetSnapshotsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/GetSnapshotsIT.java @@ -191,6 +191,13 @@ public void testSortAndPaginateWithInProgress() throws Exception { assertStablePagination(repos, allSnapshotNames, GetSnapshotsRequest.SortBy.START_TIME); assertStablePagination(repos, allSnapshotNames, GetSnapshotsRequest.SortBy.NAME); assertStablePagination(repos, allSnapshotNames, GetSnapshotsRequest.SortBy.INDICES); + final List currentSnapshots = clusterAdmin().prepareGetSnapshots(matchAllPattern()) + .setSnapshots(GetSnapshotsRequest.CURRENT_SNAPSHOT) + .get() + .getSnapshots(); + for (SnapshotInfo currentSnapshot : currentSnapshots) { + assertThat(currentSnapshot.toString(), currentSnapshot.failedShards(), is(0)); + } assertThat( clusterAdmin().prepareGetSnapshots(matchAllPattern()) diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java index d50d04bbb7299..32c1f96c03c66 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java @@ -627,13 +627,12 @@ public int totalShards() { } /** - * Number of failed shards; a value of {@code 0} will be returned if there were no - * failed shards, or if {@link #state()} returns {@code null}. + * Number of failed shards. * * @return number of failed shards */ public int failedShards() { - return totalShards - successfulShards; + return shardFailures.size(); } /**