Skip to content

Conversation

@original-brownbear
Copy link
Contributor

Add numeric offset parameter to this API.

Relates #74350

Add numeric offset parameter to this API.

Relates elastic#74350
@elasticmachine elasticmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Aug 9, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

);
}
return sortSnapshots(snapshotInfos, sortBy, after, size, order);
return sortSnapshots(snapshotInfos, sortBy, after, 0, GetSnapshotsRequest.NO_LIMIT, order);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now I just dropped the size and offset limits everywhere but before resolving the final listener.
There isn't really an easy way of implementing a numeric offset with the current approach otherwise and the memory savings from dropping a few elements from the stream earlier are probably trivial anyway. For now this seems good enough to me and once this is in and the search parameter PR has been merged we can start optimizing the code here I think.

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.


`offset`::
(Optional, integer)
Numeric offset to start pagination from. Using a non-zero value for this parameter is mutually exclusive with using the `after` parameter.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps worth clarifying the offset is evaluated after (name) filtering?

Also, I thought we had a case of needing to use both after and offset, but if not, I am fine with the restriction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps worth clarifying the offset is evaluated after (name) filtering?

Done

Also, I thought we had a case of needing to use both after and offset, but if not, I am fine with the restriction.

I don't think so, at least not today. I could see value in that if we were to open queries like "all snapshots after date so and so" to users, but as we don't have that right now and just use the after for iteration I don't think it's needed. But for now I think we're good here :)

final List<SnapshotInfo> subsetSorted = getSnapshotsResponse.getSnapshots();
assertEquals(subsetSorted, getSnapshotsResponseNumeric.getSnapshots());
assertEquals(subsetSorted, allSorted.subList(j + 1, j + i + 1));
assertEquals(allSnapshotNames.size(), getSnapshotsResponse.totalCount());
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 we should also verify the total count and remaining from the response obtained using offset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++ added assertions for that

out.writeEnum(sort);
out.writeVInt(size);
order.writeTo(out);
if (out.getVersion().onOrAfter(NUMERIC_PAGINATION_VERSION)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would we not want to fail if offset is non-zero when talking to a too old version? Just like 3 lines down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++ added handling for that thanks!

final List<SnapshotInfo> subsetSorted = getSnapshotsResponse.getSnapshots();
assertEquals(subsetSorted, getSnapshotsResponseNumeric.getSnapshots());
assertEquals(subsetSorted, allSorted.subList(j + 1, j + i + 1));
assertEquals(allSnapshotNames.size(), getSnapshotsResponse.totalCount());
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 we should also verify the total count and remaining from the response obtained using offset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++ added assertions for that

@original-brownbear
Copy link
Contributor Author

Thanks Henning!

@original-brownbear original-brownbear merged commit ffaa0f2 into elastic:master Aug 9, 2021
@original-brownbear original-brownbear deleted the allow-get-snapshots-by-numeric-offset branch August 9, 2021 14:23
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Aug 14, 2021
original-brownbear added a commit that referenced this pull request Aug 14, 2021
* Return Total Result Count and Remaining Count in Get Snapshots Response (#76150)

Add total result count and remaining count to get snapshots response.

* Implement Numeric Offset Parameter in Get Snapshots API (#76233)

Add numeric offset parameter to this API.

Relates #74350
@original-brownbear original-brownbear restored the allow-get-snapshots-by-numeric-offset branch April 18, 2023 21:01
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:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v7.15.0 v8.0.0-alpha1 v8.0.0-alpha2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants