Skip to content

Commit

Permalink
Fix incorrect failed shards count in APIs for current snapshots (#89534)
Browse files Browse the repository at this point in the history
The failed shards count approach is wrong, if we have an in-progress snapshot
the difference in counts does not work out to the failed shards count.
Since every failed shard has an entry in the failure list anyway we can just
return its size instead for the correct answer.
  • Loading branch information
original-brownbear committed Aug 23, 2022
1 parent ac71b52 commit 0cf3dc9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions 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: []
Expand Up @@ -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<SnapshotInfo> 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())
Expand Down
Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 0cf3dc9

Please sign in to comment.