-
Notifications
You must be signed in to change notification settings - Fork 124
Implement Strict Routing Semantics for Routing Rules #804
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
base: main
Are you sure you want to change the base?
Conversation
|
Just a few remarks:
|
+1 |
|
| List<ProxyBackendConfiguration> backends = gatewayBackendManager.getActiveBackends(routingGroup).stream() | ||
| .filter(backEnd -> isBackendHealthy(backEnd.getName())) | ||
| .toList(); | ||
| if (backends.isEmpty() && strictRouting) { |
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 may be a nitpick, but evaluating strictRouting first can short circuit the backends.isEmpty() one, in case it's false. A teeny performance optimization would be to re-order these so it's if (strictRouting && backends.isEmpty())
| .filter(backEnd -> isBackendHealthy(backEnd.getName())) | ||
| .toList(); | ||
| if (strictRouting && backends.isEmpty()) { | ||
| throw new WebApplicationException( |
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.
why WebApplicationException and not IllegalStateException like in IllegalStateException("Number of active backends found zero"))
or maybe a custom Explicit Exception inherited from RouterException?
felicity3786
left a comment
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.
Let's also update the official doc?
| .filter(backEnd -> isBackendHealthy(backEnd.getName())) | ||
| .toList(); | ||
| if (strictRouting && backends.isEmpty()) { | ||
| throw new WebApplicationException( |
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.
We can add a WARN or ERROR with context when the 404 is triggered? Also +1 on maybe making it a NoBackendAvailableException?
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.
It's ambiguous what you mean strictRouting.
There are two fallback logics in routing.
-
If
RoutingGroupSelectorfailed to select a routing group for a query, fallback todefaultRoutingGroup.trino-gateway/gateway-ha/src/main/java/io/trino/gateway/ha/handler/RoutingTargetHandler.java
Lines 97 to 99 in eb736ee
String routingGroup = !isNullOrEmpty(routingDestination.routingGroup()) ? routingDestination.routingGroup() : defaultRoutingGroup; -
If there are no available active healthy cluster for the selected routing group, fallback to
ActiveDefaultBackends(ie. active healthy cluster indefaultRoutingGroup).trino-gateway/gateway-ha/src/main/java/io/trino/gateway/ha/router/BaseRoutingManager.java
Line 121 in a4159fc
return selectBackend(backends, user).orElseGet(() -> provideDefaultBackendConfiguration(user));
It's not clear which fallback logic (or both) are disabled. If you decided to disable both (currently you only handled 2), please make sure the error messages are clearly distinguishable for these cases. Docs are also required to explain the exact affect of this config.
| .toList(); | ||
| if (strictRouting && backends.isEmpty()) { | ||
| throw new WebApplicationException( | ||
| Response.status(NOT_FOUND) |
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.
Client did nothing wrong and shouldn't receive a 4xx error. We should return a 5XX indicate a server side error, maybe 503 Service Unavailable.
Description
This PR adds
strictRoutingflag for routing as proposed in #797.Routing rules can now support
strictRouting: Trueto force pinning the query to the routing groupWhen
strictRouting = false (default), the routing behavior remains unchanged.When
strictRouting = true, the gateway would not fall back to default clusters if the pinned backend becomes unavailable. Instead, the query should fail immediately with a 404 error.Testing
mvn clean installTestStochasticRoutingManagerstrictRoutingflag works