-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
SnapshotShardsService Simplifications #38025
SnapshotShardsService Simplifications #38025
Conversation
…rvice-simplifications
…rvice-simplifications
Pinging @elastic/es-distributed |
…rvice-simplifications
@original-brownbear can you update this with #37686 and add me as reviewer once done? |
@ywelsch already did that, just forgot to update the PR description :D Thanks for the ping! => should be good for review now. |
return shardSnapshots.get(snapshot); | ||
synchronized (shardSnapshots) { | ||
final Map<ShardId, IndexShardSnapshotStatus> current = shardSnapshots.get(snapshot); | ||
return current == null ? null : new HashMap<>(current); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be an immutable map (i.e. wrapped in Collections.unmodifiableMap)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really have a strong opinion here, but that seems a little redundant.
But my subjective sense of aesthetics would say:
The caller is free to do whatever with that Map
since it's a copy already => just another needless level of indirection and more symbols when reading the code.
@@ -220,160 +209,133 @@ public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexSh | |||
* @param event cluster state changed event | |||
*/ | |||
private void processIndexShardSnapshots(ClusterChangedEvent event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps only pass current cluster state to this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, we can even just pass SnapshotsInProgress
since we have that in the caller already :) Will simplify.
Map<ShardId, IndexShardSnapshotStatus> startedShards = new HashMap<>(); | ||
final Snapshot snapshot = entry.snapshot(); | ||
Map<ShardId, IndexShardSnapshotStatus> snapshotShards = shardSnapshots.getOrDefault(snapshot, emptyMap()); | ||
final String localNodeId = clusterService.localNode().getId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
capture this outside of the loop
for (SnapshotsInProgress.Entry entry : snapshotsInProgress.entries()) { | ||
final State entryState = entry.state(); | ||
if (entryState == State.STARTED) { | ||
Map<ShardId, IndexShardSnapshotStatus> startedShards = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps create this lazily?
public void doRun() { | ||
final IndexShard indexShard = | ||
indicesService.indexServiceSafe(shardId.getIndex()).getShardOrNull(shardId.id()); | ||
assert indexId != null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this assert could be further up where we assign indexId
…rvice-simplifications
@ywelsch thanks! |
…ersion * elastic/master: SnapshotShardsService Simplifications (elastic#38025) Default include_type_name to false in the yml test harness. (elastic#38058) Disable bwc preparing to backport of#37977, elastic#37857 and elastic#37872 (elastic#38126) Adding ml_settings entry to HLRC and Docs for deprecation_info (elastic#38118)
* elastic/master: AwaitsFix testAbortedSnapshotDuringInitDoesNotStart (elastic#38227) Preserve ILM operation mode when creating new lifecycles (elastic#38134) Enable trace log in FollowerFailOverIT (elastic#38148) SnapshotShardsService Simplifications (elastic#38025) Default include_type_name to false in the yml test harness. (elastic#38058) Disable bwc preparing to backport of#37977, elastic#37857 and elastic#37872 (elastic#38126)
* elastic/master: (54 commits) Introduce retention leases versioning (elastic#37951) Correctly disable tests for FIPS JVMs (elastic#38214) AwaitsFix testAbortedSnapshotDuringInitDoesNotStart (elastic#38227) Preserve ILM operation mode when creating new lifecycles (elastic#38134) Enable trace log in FollowerFailOverIT (elastic#38148) SnapshotShardsService Simplifications (elastic#38025) Default include_type_name to false in the yml test harness. (elastic#38058) Disable bwc preparing to backport of#37977, elastic#37857 and elastic#37872 (elastic#38126) Adding ml_settings entry to HLRC and Docs for deprecation_info (elastic#38118) Replace awaitBusy with assertBusy in atLeastDocsIndexed (elastic#38190) Adjust SearchRequest version checks (elastic#38181) AwaitsFix testClientSucceedsWithVerificationDisabled (elastic#38213) Zen2ify RareClusterStateIT (elastic#38184) ML: Fix error race condition on stop _all datafeeds and close _all jobs (elastic#38113) AwaitsFix PUT mapping with _doc on an index that has types (elastic#38204) Allow built-in monitoring_user role to call GET _xpack API (elastic#38060) Update geo_shape docs to include unsupported features (elastic#38138) [ML] Remove "8" prefixes from file structure finder timestamp formats (elastic#38016) Disable bwc tests while backporting elastic#38104 (elastic#38182) Enable TLSv1.3 by default for JDKs with support (elastic#38103) ...
* Backport of various snapshot stability fixes from `master` to `6.7` * Includes elastic#38368, elastic#38025 and elastic#37612
Inspired by @ywelsch 's work in https://github.com/ywelsch/elasticsearch/blob/snapshot-refactored/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java
shardSnapshots
field, we mutate it, explicitly removing entries from it in only a single spotstartNewShards
(saves us two maps (keyed by snapshot) and iterations over them)