Skip to content

Fix SnapshotStats toXContent()/fromXContent() round trip serialization #128928

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

Conversation

JeremyDahlgren
Copy link
Contributor

@JeremyDahlgren JeremyDahlgren commented Jun 4, 2025

toXContent() has a check to omit the "processed" sub-object if the processedFileCount equals the incrementalFileCount. In the scenario where they are equal and greater than zero, if you were to read the JSON back in with fromXContent(), the SnapshotStats object would not be the same as the original since processedFileCount is not parsed and set. You can break SnapshotStatsTests by forcing createTestInstance() to pass the incrementalFileCount value for processedFileCount when constructing the instance. This PR adds a fix and increases the probability of creating this scenario in createTestInstance().

Since fromXContent() is no longer called from production code, this PR also moves SnapshotStats.fromXContent() into SnapshotStatsTests.

For context, #29602 is the PR for reviewing when getProcessedFileCount() != getIncrementalFileCount() was added in SnapshotStats.toXContent(), and #31515 is the PR for reviewing when SnapshotStats.fromXContent() was added.

This issue was found while working on tests for #128399 and noticing XContent round trip serialization was not working as expected.

toXContent() has a check to omit the "processed" sub-object if the
processedFileCount equals the incrementalFileCount.  In the scenario
where they are equal and greater than zero, if you were to read the
JSON back in with fromXContent(), the SnapshotStats object would not
be the same as the original since processedFileCount is not parsed
and set.  This change adds a fix and a unit test for this scenario.
@JeremyDahlgren JeremyDahlgren added >bug :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Coordination Meta label for Distributed Coordination team v9.1.0 labels Jun 4, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @JeremyDahlgren, I've created a changelog YAML for you.

@JeremyDahlgren JeremyDahlgren added >test Issues or PRs that are addressing/adding tests and removed >bug labels Jun 4, 2025
@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@DaveCTurner DaveCTurner 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 523ba41 into elastic:main Jun 6, 2025
18 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 Team:Distributed Coordination Meta label for Distributed Coordination team >test Issues or PRs that are addressing/adding tests v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants