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

Move routing calculation #79394

Merged

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Oct 18, 2021

This slightly moves the routing calculation out of a difficult to reason
about switch statement and into real OO method implementation. Its a
tiny tiny change but it makes me feel much better about it.

@nik9000 nik9000 added >non-issue :Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. v8.0.0 :StorageEngine/TSDB You know, for Metrics labels Oct 18, 2021
@elasticmachine elasticmachine added Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) labels Oct 18, 2021
@elasticmachine
Copy link
Collaborator

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

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (Team:Analytics)

This slightly moves the routing calculation out of a difficult to reason
about `switch` statement and into real OO method implementation. Its a
tiny tiny change but it makes me feel much better about it.
break;
case UPDATE:
TransportUpdateAction.resolveAndValidateRouting(metadata, concreteIndex.getName(),
(UpdateRequest) docWriteRequest);
shardId = indexRouting.updateShard(docWriteRequest.id(), docWriteRequest.routing());
break;
case DELETE:
docWriteRequest.routing(metadata.resolveWriteIndexRouting(docWriteRequest.routing(), docWriteRequest.index()));
// check if routing is required, if so, throw error if routing wasn't specified
if (docWriteRequest.routing() == null && metadata.routingRequired(concreteIndex.getName())) {
throw new RoutingMissingException(concreteIndex.getName(), docWriteRequest.id());
}
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 played around a little bit and most of this switch statement can be removed I think. But I want to do it bit by bit because its in an important bit of code.

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 opened #79472 which slices out a lot of the rest of this switch statement. I believe all that is left is the validation around data streams.

@nik9000
Copy link
Member Author

nik9000 commented Oct 18, 2021

run elasticsearch-ci/part-2

Copy link
Contributor

@henningandersen henningandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this makes it much nicer.

@@ -720,6 +721,11 @@ public boolean isRequireAlias() {
return requireAlias;
}

@Override
public int route(IndexRouting indexRouting) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add comment here that resolveRouting and process must be called prior to this.

Also I think we can cement parts of that by asserting that id != null?

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'd sort of been hoping to fold those two methods together. But that is a thing for another time.

@nik9000 nik9000 added auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) v8.1.0 and removed v8.0.0 labels Oct 27, 2021
@elasticsearchmachine elasticsearchmachine merged commit e686609 into elastic:master Oct 27, 2021
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Nov 10, 2021
Now that we have elastic#79394 and elastic#79472 the switch statement in
`TransportBulkAction` is mostly just assigning routing and doing some
stuff with INDEX and UPDATE requests. This pulls the routing stuff into
a single call and calls out the index-only stuff. Now, at least, it's
clearer that only INDEX and UPDATE are special.
nik9000 added a commit that referenced this pull request Nov 11, 2021
Now that we have #79394 and #79472 the switch statement in
`TransportBulkAction` is mostly just assigning routing and doing some
stuff with INDEX and UPDATE requests. This pulls the routing stuff into
a single call and calls out the index-only stuff. Now, at least, it's
clearer that only INDEX and UPDATE are special.
@wchaparro wchaparro assigned nik9000 and unassigned nik9000 Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. >non-issue :StorageEngine/TSDB You know, for Metrics Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants