Skip to content
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

Conversation

original-brownbear
Copy link
Member

@original-brownbear original-brownbear commented Jan 30, 2019

Inspired by @ywelsch 's work in https://github.com/ywelsch/elasticsearch/blob/snapshot-refactored/server/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java

  • Instead of replacing the shardSnapshots field, we mutate it, explicitly removing entries from it in only a single spot
  • Decreased the amount of indirection by moving all logic for starting a snapshot's newly discovered shard tasks into startNewShards (saves us two maps (keyed by snapshot) and iterations over them)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@ywelsch ywelsch assigned ywelsch and unassigned ywelsch Feb 1, 2019
@ywelsch
Copy link
Contributor

ywelsch commented Feb 1, 2019

@original-brownbear can you update this with #37686 and add me as reviewer once done?

@original-brownbear
Copy link
Member Author

@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);
Copy link
Contributor

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)?

Copy link
Member Author

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) {
Copy link
Contributor

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

Copy link
Member Author

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();
Copy link
Contributor

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<>();
Copy link
Contributor

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;
Copy link
Contributor

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

@original-brownbear original-brownbear merged commit 03a1d21 into elastic:master Feb 1, 2019
@original-brownbear original-brownbear deleted the snapshot-shards-service-simplifications branch February 1, 2019 19:46
@original-brownbear
Copy link
Member Author

@ywelsch thanks!

jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Feb 1, 2019
…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)
jasontedor added a commit to bleskes/elasticsearch that referenced this pull request Feb 1, 2019
* 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)
jasontedor added a commit to gwbrown/elasticsearch that referenced this pull request Feb 1, 2019
* 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)
  ...
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Feb 28, 2019
* Backport of various snapshot stability fixes from `master` to `6.7`
* Includes elastic#38368, elastic#38025 and elastic#37612
original-brownbear added a commit that referenced this pull request Mar 1, 2019
* Snapshot Stability Fixes

* Backport of various snapshot stability fixes from `master` to `6.7`
* Includes #38368, #38025 and #37612
original-brownbear added a commit that referenced this pull request Mar 4, 2019
* Backport of various snapshot stability fixes from `master` to `6.7` making the snapshot logic in `6.7` equivalent to that in `master` functionally
* Includes #38368, #38025 and #37612
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants