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)

* Fix bug for Get Snapshot API to return correct response when getting a non-existing snapshot (#6820)

Signed-off-by: Gao Binlong <gbinlong@amazon.com>

* modify change log

Signed-off-by: Gao Binlong <gbinlong@amazon.com>

* Modify changelog

Signed-off-by: Gao Binlong <gbinlong@amazon.com>

---------

Signed-off-by: Gao Binlong <gbinlong@amazon.com>
  • Loading branch information
gaobinlong authored Apr 6, 2023
1 parent 0202de5 commit 8b34e5f
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 @@ -130,8 +130,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 8b34e5f

Please sign in to comment.