SnapshotShardsService Simplifications#38025
SnapshotShardsService Simplifications#38025original-brownbear merged 13 commits intoelastic:masterfrom original-brownbear:snapshot-shards-service-simplifications
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.
should this be an immutable map (i.e. wrapped in Collections.unmodifiableMap)?
There was a problem hiding this comment.
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 Map<ShardId, IndexShardSnapshotStatus> currentSnapshotShards(Snapshot sna | |||
| * @param event cluster state changed event | |||
| */ | |||
| private void processIndexShardSnapshots(ClusterChangedEvent event) { | |||
There was a problem hiding this comment.
perhaps only pass current cluster state to this method
There was a problem hiding this comment.
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.
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.
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.
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) ...
Inspired by @ywelsch 's work in https://github.com/ywelsch/elasticsearch/blob/snapshot-refactored/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java
shardSnapshotsfield, we mutate it, explicitly removing entries from it in only a single spotstartNewShards(saves us two maps (keyed by snapshot) and iterations over them)