From 266d87916123c1d765160e39d2ca7c99aa265913 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 6 Apr 2023 17:19:04 -0400 Subject: [PATCH] Fix GetSnapshots to not return non-existent snapshots with ignore_unavailable=true (#6839) (#7029) * Fix bug for Get Snapshot API to return correct response when getting a non-existing snapshot (#6820) * modify change log * Modify changelog --------- (cherry picked from commit 8b34e5f724fe2b875731228795f51d523462599a) Signed-off-by: Gao Binlong Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- CHANGELOG.md | 3 ++- .../opensearch/snapshots/SnapshotStatusApisIT.java | 11 +++++++++++ .../snapshots/get/TransportGetSnapshotsAction.java | 6 ++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c3229d8a3e3f..14e8b83388217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,8 +54,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 b6fa4fbc2fc96..46547a7718927 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);