-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Move routing calculation #79394
Conversation
Pinging @elastic/es-distributed (Team:Distributed) |
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()); | ||
} |
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 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.
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 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.
run elasticsearch-ci/part-2 |
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.
LGTM, this makes it much nicer.
@@ -720,6 +721,11 @@ public boolean isRequireAlias() { | |||
return requireAlias; | |||
} | |||
|
|||
@Override | |||
public int route(IndexRouting indexRouting) { |
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.
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
?
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'd sort of been hoping to fold those two methods together. But that is a thing for another time.
…uting_from_source_clean_1
…uting_from_source_clean_1
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.
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.
This slightly moves the routing calculation out of a difficult to reason
about
switch
statement and into real OO method implementation. Its atiny tiny change but it makes me feel much better about it.