diff --git a/CHANGELOG.md b/CHANGELOG.md index e4fe8736e8588..2720857e536b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -129,8 +129,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Added equals/hashcode for named DocValueFormat.DateTime inner class ([#6357](https://github.com/opensearch-project/OpenSearch/pull/6357)) - Fixed bug for searchable snapshot to take 'base_path' of blob into account ([#6558](https://github.com/opensearch-project/OpenSearch/pull/6558)) - Fix fuzziness validation ([#5805](https://github.com/opensearch-project/OpenSearch/pull/5805)) +- Fix GetSnapshots to not return non-existent snapshots with ignore_unavailable=true ([#6839](https://github.com/opensearch-project/OpenSearch/pull/6839)) ### Security [Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.x...HEAD -[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.5...2.x \ No newline at end of file +[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.5...2.x diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java index 69b947588bea0..ebde9f2ab4d1d 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java @@ -379,6 +379,17 @@ public void testGetSnapshotsRequest() throws Exception { .get(); assertEquals(1, getSnapshotsResponse.getSnapshots().size()); assertEquals("snap-on-empty-repo", getSnapshotsResponse.getSnapshots().get(0).snapshotId().getName()); + + // there is an in-progress snapshot, make sure we return empty result when getting a non-existing snapshot with setting + // ignore_unavailable to true + getSnapshotsResponse = client.admin() + .cluster() + .prepareGetSnapshots("test-repo") + .setIgnoreUnavailable(true) + .addSnapshots("non-existent-snapshot") + .get(); + assertEquals(0, getSnapshotsResponse.getSnapshots().size()); + unblockNode(repositoryName, initialBlockedNode); // unblock node admin().cluster().prepareDeleteSnapshot(repositoryName, "snap-on-empty-repo").get(); diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java index d05e62045a1a2..b5445bf544cc6 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java @@ -239,9 +239,11 @@ private List snapshots( repositoryName, snapshotIdsToIterate.stream().map(SnapshotId::getName).collect(Collectors.toList()) ); + // filter and incorporate the snapshots in progress for (SnapshotsInProgress.Entry entry : entries) { - snapshotSet.add(new SnapshotInfo(entry)); - snapshotIdsToIterate.remove(entry.snapshot().getSnapshotId()); + if (snapshotIdsToIterate.remove(entry.snapshot().getSnapshotId())) { + snapshotSet.add(new SnapshotInfo(entry)); + } } // then, look in the repository final Repository repository = repositoriesService.repository(repositoryName);