Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten Get Snapshots Response #74451

Conversation

original-brownbear
Copy link
Member

@original-brownbear original-brownbear commented Jun 22, 2021

This PR returns the get snapshots API to the 7.x format (and transport client behavior) and enhances it for requests that ask for multiple repositories.
The changes for requests that target multiple repositories are:

  • Add repository field to SnapshotInfo and REST response
  • Add failures map alongside snapshots list instead of returning just an exception response as done for single repo requests
  • Pagination now works across repositories instead of being per repository for multi-repository requests

closes #69108
closes #43462

@original-brownbear original-brownbear added >enhancement WIP :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs labels Jun 22, 2021
@original-brownbear
Copy link
Member Author

Jenkins run elasticsearch-ci/docs (git ssh timeout)

Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only been through the non-test file changes for now. Mainly one comment needs attention: error handling.

@@ -160,12 +172,12 @@ private void getMultipleReposSnapshotInfo(
size,
order,
groupedActionListener.delegateResponse((groupedListener, e) -> {
if (e instanceof ElasticsearchException) {
groupedListener.onResponse(GetSnapshotsResponse.Response.error(repoName, (ElasticsearchException) e));
if (isMultiRepoRequest && e instanceof ElasticsearchException) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this way of error handling is new compared to elsewhere. I wonder if you considered one of following options:

  • Respond with a failure if all repos failed (which would be the same as here in the single repo case). This is sort of similar to search.
  • Breakingly never respond failures, expect users to look into the failures map.
  • Have an option to fail the request or send back failures in response.

Do we have other similar cases in ES we can lean on in order to decide?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Respond with a failure if all repos failed (which would be the same as here in the single repo case). This is sort of similar to search.

That seems more complicated to work with than having the failures map? My thinking was to have the same behavior for all requests that target multiple repos. I'm somewhat indifferent here, making it look like search is nice, but in isolation I like this approach better I think.

Breakingly never respond failures, expect users to look into the failures map.

This is quite annoying to users perhaps (note that in 7.x we also have to think about the transport client behavior that would be changed by this). It may also be a troubling breaking change for Cloud? I'd rather not do this I think.

Have an option to fail the request or send back failures in response.

I don't think we have that kind of behavior anywhere else? Not sure it's worth the complexity for a very small number of use cases?

Do we have other similar cases in ES we can lean on in order to decide?

None come to mind for me that are similar enough but that doesn't mean there aren't any. I think I was in large part driven by not breaking the transport client API for users and cloud orchestration. In both cases changing the behavior for a single repo request seems risky?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this on another channel with following conclusion:

  1. We will merge this PR as is.
  2. We will follow-up with a PR to add the option to fail-fast or not, regardless of multi/single repo in regular breaking change style. The default in 7 will be fail fast, default in 8 will be always put it in array. Flag to be removed in 9.

@original-brownbear
Copy link
Member Author

Thanks @henningandersen all points addressed now I think :)

@sethmlarson sethmlarson added the Team:Clients Meta label for clients team label Jun 24, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/clients-team (Team:Clients)

Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments on the tests

assertThat(response.getSnapshots(), hasSize(2));
assertThat(response.getSnapshots().get(0).snapshotId().getName(), equalTo(snapshot1));
assertThat(response.getSnapshots().get(1).snapshotId().getName(), equalTo(snapshot2));
assertThat(response.getSnapshots().get(1).userMetadata(), equalTo(originalMetadata));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also validate that snapshot1 has repo1 and snapshot2 has repo2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes definitely, added that assertion :)

.peek(m -> logger.info("--> responses: {}", m))
.map(m -> (List<Map<String, Object>>) m.get("snapshots"))
.peek(allReposSnapshots -> logger.info("--> all repository's snapshots: {}", allReposSnapshots))
.filter(allReposSnapshots -> allReposSnapshots.stream().anyMatch(repoHasSnapshot))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repoHasSnapshot is now unused. I think it makes sense that this predicate is still validated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ removed it and checked the snapshot name prefix manually below

Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 2

@original-brownbear
Copy link
Member Author

Thanks so much Henning + Tanguy!

@original-brownbear original-brownbear merged commit cbf48e0 into elastic:master Jun 24, 2021
@original-brownbear original-brownbear deleted the flatten-get-snapshots-response branch June 24, 2021 14:58
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Jun 29, 2021
This PR returns the get snapshots API to the 7.x format (and transport client behavior) and enhances it for requests that ask for multiple repositories.
The changes for requests that target multiple repositories are:
* Add `repository` field to `SnapshotInfo` and REST response
* Add `failures` map alongside `snapshots` list instead of returning just an exception response as done for single repo requests
* Pagination now works across repositories instead of being per repository for multi-repository requests

closes elastic#69108
closes elastic#43462
original-brownbear added a commit that referenced this pull request Jun 29, 2021
)

Backport of the recently introduced snapshot pagination and scalability improvements listed below.
Merged as a single backport because the `7.x` and master snapshot status API logic had massively diverged between master and 7.x. With the work in the below PRs, the logic in master and 7.x once again has been aligned very closely again.

#72842
#73172
#73199
#73570 
#73952
#74236 
#74451 (this one is only partly applicable as it was mainly a change to master to align `master` and `7.x` branches)
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Jun 30, 2021
The group-by-repository response format is gone as a result of elastic#74451
=> cleaning up its last remnants from REST tests.
original-brownbear added a commit that referenced this pull request Jun 30, 2021
The group-by-repository response format is gone as a result of #74451
=> cleaning up its last remnants from REST tests.
@original-brownbear original-brownbear restored the flatten-get-snapshots-response branch April 18, 2023 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >enhancement Team:Clients Meta label for clients team Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v7.14.0 v8.0.0-alpha1
Projects
None yet
7 participants