-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Do not apply further shard snapshot status updates after shard snapshot is complete #127250
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
DiannaHohensee
merged 14 commits into
elastic:main
from
DiannaHohensee:2025/04/23/ES-11375-snapshot-update-fix
Apr 24, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aba1716
Do not apply further shard snapshot status updates after shard snapsh…
DiannaHohensee d97d047
Update docs/changelog/127250.yaml
DiannaHohensee 114411e
expect non-null builder entries
DiannaHohensee fe54ad4
Update server/src/test/java/org/elasticsearch/snapshots/SnapshotsServ…
DiannaHohensee f7332bd
randomize testing
DiannaHohensee 0c9b6fb
verify queued
DiannaHohensee dcd9807
Merge branch 'main' into 2025/04/23/ES-11375-snapshot-update-fix
DiannaHohensee ce684dc
randomize last entry
DiannaHohensee 25b1151
Merge branch 'main' into 2025/04/23/ES-11375-snapshot-update-fix
DiannaHohensee e28879d
[CI] Auto commit changes from spotless
ba7dded
undo version comment out
DiannaHohensee e02802d
another typo...
DiannaHohensee c7f2024
Merge branch 'main' into 2025/04/23/ES-11375-snapshot-update-fix
DiannaHohensee 0679c2d
Merge branch 'main' into 2025/04/23/ES-11375-snapshot-update-fix
DiannaHohensee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 127250 | ||
| summary: Do not apply further shard snapshot status updates after shard snapshot is | ||
| complete | ||
| area: Snapshot/Restore | ||
| type: bug | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3398,16 +3398,31 @@ private <T> void startShardOperation( | |
| startedCount++; | ||
| } | ||
|
|
||
| /** | ||
| * Applies a shard snapshot status update to an updated statuses builder, after a few sanity checks / filtering. | ||
| * | ||
| * @param existingShardSnapshotStatuses Maps shard ID to ShardSnapshotStatus | ||
| * @param newShardSnapshotStatusesSupplier Supplies a builder. Initially maps shard ID to existing ShardSnapshotStatus. As shard | ||
| * snapshot status updates are applied, the original status entries are replaced with | ||
| * updated ones. | ||
| * @param shardSnapshotStatusUpdate The update to apply to build a new updated ShardSnapshotStatus | ||
| * @param shardSnapshotId The shard snapshot ID of the shard being updated (for type reasons) | ||
| */ | ||
| private <T> void executeShardSnapshotUpdate( | ||
| Map<T, ShardSnapshotStatus> existingStates, | ||
| Supplier<ImmutableOpenMap.Builder<T, ShardSnapshotStatus>> newStates, | ||
| ShardSnapshotUpdate updateSnapshotState, | ||
| T updatedShard | ||
| Map<T, ShardSnapshotStatus> existingShardSnapshotStatuses, | ||
| Supplier<ImmutableOpenMap.Builder<T, ShardSnapshotStatus>> newShardSnapshotStatusesSupplier, | ||
| ShardSnapshotUpdate shardSnapshotStatusUpdate, | ||
| T shardSnapshotId | ||
| ) { | ||
| assert updateSnapshotState.snapshot.equals(entry.snapshot()); | ||
| final ShardSnapshotStatus existing = existingStates.get(updatedShard); | ||
| assert shardSnapshotStatusUpdate.snapshot.equals(entry.snapshot()); | ||
|
|
||
| final ShardSnapshotStatus existing = existingShardSnapshotStatuses.get(shardSnapshotId); | ||
| if (existing == null) { | ||
| logger.warn("Received shard snapshot status update [{}] but this shard is not tracked in [{}]", updatedShard, entry); | ||
| logger.error( | ||
| "Received shard snapshot status update [{}] but this shard is not tracked in [{}]", | ||
| shardSnapshotStatusUpdate, | ||
DaveCTurner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| entry | ||
| ); | ||
| assert false : "This should never happen, should only receive updates for expected shards"; | ||
| return; | ||
| } | ||
|
|
@@ -3418,34 +3433,49 @@ private <T> void executeShardSnapshotUpdate( | |
| return; | ||
| } | ||
|
|
||
| final ShardSnapshotStatus updatedState; | ||
| final var newShardSnapshotStatusesBuilder = newShardSnapshotStatusesSupplier.get(); | ||
| final var newShardSnapshotStatus = newShardSnapshotStatusesBuilder.get(shardSnapshotId); | ||
| assert newShardSnapshotStatus != null; // builder is seeded with all the original statuses. | ||
| if (newShardSnapshotStatus.state().completed()) { | ||
| // An out-of-order status update arrived. It should not be applied because the shard snapshot is already finished. | ||
| // For example, a delayed/retried PAUSED update should not override a completed shard snapshot. | ||
| iterator.remove(); | ||
| return; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actual bug fix |
||
|
|
||
| final ShardSnapshotStatus updatedShardSnapshotStatus; | ||
| if (existing.state() == ShardState.ABORTED | ||
| && updateSnapshotState.updatedState.state() == ShardState.PAUSED_FOR_NODE_REMOVAL) { | ||
| && shardSnapshotStatusUpdate.updatedState.state() == ShardState.PAUSED_FOR_NODE_REMOVAL) { | ||
| // concurrently pausing the shard snapshot due to node shutdown and aborting the snapshot - this shard is no longer | ||
| // actively snapshotting but we don't want it to resume, so mark it as FAILED since it didn't complete | ||
| updatedState = new ShardSnapshotStatus( | ||
| updateSnapshotState.updatedState.nodeId(), | ||
| updatedShardSnapshotStatus = new ShardSnapshotStatus( | ||
| shardSnapshotStatusUpdate.updatedState.nodeId(), | ||
| ShardState.FAILED, | ||
| updateSnapshotState.updatedState.generation(), | ||
| shardSnapshotStatusUpdate.updatedState.generation(), | ||
| "snapshot aborted" | ||
| ); | ||
| } else { | ||
| updatedState = updateSnapshotState.updatedState; | ||
| updatedShardSnapshotStatus = shardSnapshotStatusUpdate.updatedState; | ||
| } | ||
|
|
||
| if (updatedState.state() == ShardState.PAUSED_FOR_NODE_REMOVAL) { | ||
| if (updatedShardSnapshotStatus.state() == ShardState.PAUSED_FOR_NODE_REMOVAL) { | ||
| // leave subsequent entries for this shard alone until this one is unpaused | ||
| iterator.remove(); | ||
| } else { | ||
| // All other shard updates leave the shard in a complete state, which means we should leave this update in the list so | ||
| // it can fall through to later entries and start any waiting shard snapshots: | ||
| assert updatedState.isActive() == false : updatedState; | ||
| // that it can fall through to later entries and start any waiting shard snapshots: | ||
| assert updatedShardSnapshotStatus.isActive() == false : updatedShardSnapshotStatus; | ||
| } | ||
|
|
||
| logger.trace("[{}] Updating shard [{}] with status [{}]", updateSnapshotState.snapshot, updatedShard, updatedState.state()); | ||
| logger.trace( | ||
| "[{}] Updating shard [{}] with status [{}]", | ||
| shardSnapshotStatusUpdate.snapshot, | ||
| shardSnapshotId, | ||
| updatedShardSnapshotStatus.state() | ||
| ); | ||
| changedCount++; | ||
| newStates.get().put(updatedShard, updatedState); | ||
| executedUpdates.add(updateSnapshotState); | ||
| newShardSnapshotStatusesBuilder.put(shardSnapshotId, updatedShardSnapshotStatus); | ||
| executedUpdates.add(shardSnapshotStatusUpdate); | ||
| } | ||
|
|
||
| private void tryStartNextTaskAfterCloneUpdated(RepositoryShardId repoShardId, ShardSnapshotStatus updatedState) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.