Skip to content

Commit

Permalink
Fix GetSnapshots to not return non-existent snapshots with ignore_una…
Browse files Browse the repository at this point in the history
…vailable=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 8b34e5f)

Signed-off-by: Gao Binlong <gbinlong@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent c7e3b02 commit 266d879
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.5...2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ private List<SnapshotInfo> 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);
Expand Down

0 comments on commit 266d879

Please sign in to comment.