Skip to content

Test for cancelled task in TransportSnapshotsStatusAction.buildResponse() #126740

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

Merged
merged 7 commits into from
Apr 17, 2025

Conversation

JeremyDahlgren
Copy link
Contributor

Testing for cancellation in buildResponse() can avoid extra unnecessary processing in scenarios with many shards.

Closes ES-10981.

This PR adds a TransportSnapshotsStatusActionTests unit test file to test this new functionality directly versus trying to modifying a higher level test like SnapshotStatusApisIT. The test code added is minimal, just focusing on the changes introduced in this PR.

…se()

Testing for cancellation in buildResponse() avoids a lot of
unnecessary processing in scenarios with many shards.

Closes ES-10981.
@JeremyDahlgren JeremyDahlgren added >non-issue :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Coordination Meta label for Distributed Coordination team labels Apr 12, 2025
@JeremyDahlgren JeremyDahlgren marked this pull request as ready for review April 12, 2025 01:18
@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@DiannaHohensee DiannaHohensee left a comment

Choose a reason for hiding this comment

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

Looks good, I just have some superficial nits.

assertNotNull(rsp);
final var snapshotStatuses = rsp.getSnapshots();
assertNotNull(snapshotStatuses);
assertEquals(1, snapshotStatuses.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

For the assertEquals and assertTrue, could you add debug info strings with some more information? There are versions of the methods that take a string as the first parameter. It should help with debugability. Otherwise I think this line failing would tell us that 1 doesn't equal 2, say, but not what the extra snapshot statuses are.

Copy link
Contributor

@DiannaHohensee DiannaHohensee left a comment

Choose a reason for hiding this comment

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

It looks like we need some new toString methods in order for the debug strings to be useful.

assertEquals(expectedState, snapshotStatus.getState());
final var snapshotStatusShards = snapshotStatus.getShards();
assertNotNull(snapshotStatusShards);
assertEquals(1, snapshotStatusShards.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

Debug string pls.

final var snapshotStatusIndices = snapshotStatus.getIndices();
assertNotNull(snapshotStatusIndices);
assertEquals(
"expected a single entry in snapshotStatusIndices instead of " + snapshotStatusIndices,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I think I see a wrinkle I didn't anticipate. IIUC, SnapshotIndexStatus doesn't have a toString method defined, so it'll print out a class name + hash code? Not ideal.

SnapshotStatus has a toString method that takes advantage of the chunking interface, variations of which SnapshotIndexStatus and SnapshotIndexShardStatus also implement. So it might be easy to write something similar for them, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added toString() methods for the relevant classes. The Strings.toString() that takes a ChunkedToXContent is deprecated. This form is the one that SnapshotStatus is currently calling. In SnapshotStatusResponse I used Strings.toString(ChunkedToXContent.wrapAsToXContent(this), true, true) directly since the assumption is we are calling toString() in scenarios where it would be reasonable to fully serialize to a String. I also set the human parameter to true in all the new toString() methods since toString() is meant to be human readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@DiannaHohensee DiannaHohensee left a comment

Choose a reason for hiding this comment

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

LGTM!

@JeremyDahlgren JeremyDahlgren merged commit 512e868 into elastic:main Apr 17, 2025
17 checks passed
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 >non-issue Team:Distributed Coordination Meta label for Distributed Coordination team v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants