Refactor routing logics and remove unused lookups - #923
Conversation
|
My Understanding of This PR (different cases i thought)
LGTM |
|
Looks like the caches - |
| public static Optional<String> extractQueryIdIfPresent( | ||
| HttpServletRequest request, | ||
| List<String> statementPaths, | ||
| boolean requestAnalyserClientsUseV2Format, |
There was a problem hiding this comment.
It looks like we used to use requestAnalyserClientsUseV2Format and requestAnalyserMaxBodySize to create TrinoQueryProprties class but since now we are storing it in request object we just never cleaned it up.
| // Query ID based routing | ||
| previousCluster = queryId.map(routingManager::findBackendForQueryId); | ||
| routingTargetResponse = previousCluster.map(cluster -> new RoutingTargetResponse( | ||
| new RoutingDestination(defaultRoutingGroup, cluster, buildUriWithNewCluster(cluster, request), cluster), |
There was a problem hiding this comment.
The whole point of these two seemingly unnecessary cache is to not use defaultRoutingGroup because it might not be the right routing group for subsequent queries.
For example:
first query: POST/ /v1/statement goes to cluster foo_cluster in routing group foo_routing_group with cluster url https://foo-cluster
second query: GET/ ..., instead of using foo_cluster it would use whatever value is set to defaultRoutingGroup as routing group.
It may not break the existing workflow as it doesn't use routing group to route. It's routed with cluster uri, but the information being carried around with subsequent GETs is wrong.
There was a problem hiding this comment.
second query: GET/ ...
I assume you're referring to the nextUri from the first request. The subsequent requests must route to the exact Trino cluster in order to process the query. Routing the subsequent requests to other Trino clusters in the same routing group doesn't make sense.
There was a problem hiding this comment.
yes I understand. This PR still routes the subsequent requests to the same Trino cluster as it's using clusterUri. However, routingDestination.routingGroup now points to defaultRoutingGroup instead of the actual routing group for the first POST request
For example, it would end up with
1st request: POST/ /v1/statement RoutingDestination class holds routingGroup = foo, clusterUri = foo.com
2nd request: GET/ /... RoutingDestination class holds routingGroup = <defaultRoutingGroup>, clusterUri = foo.com
it doesn't break the flow as it only uses clusterUri, but now routingGroup is wrong.
Please correct me if I'm wrong
There was a problem hiding this comment.
Instead of passing an unused defaultRoutingGroup around, I updated the code to use empty string to indicate it's not used.
|
CI error related to #966 |
f1c44fc to
a7a1ddc
Compare
andythsu
left a comment
There was a problem hiding this comment.
🚀 not the best solution, but the benefits outweighs having to maintain two caches just for this info
# Conflicts: # gateway-ha/src/main/java/io/trino/gateway/ha/handler/RoutingTargetHandler.java
7db2b6a to
d8fbd04
Compare
|
Rebase to latest main branch. |
|
@oneonestar can we push a ahead with this ? |
|
@oneonestar can you fix conflicts? |
|
This pull request has gone a while without any activity. Ask for help on #trino-gateway-dev on Trino slack. |
Description
Refactor the code to separate Query ID/Cookie-based routing from new query submission routing.
Remove the unnecessary
getExternalUrlForQueryIdandgetRoutingGroupForQueryIdmethods, along with their related DAOs and caches. TheexternalUrlandroutingGroupfields are stored for newly submitted queries as before.Additional context and related issues
getExternalUrlForQueryIdandgetRoutingGroupForQueryIdare only used when a Query ID exists. However, their results are never persisted back to the database. We only store query history for newly submitted queries:trino-gateway/gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyRequestHandler.java
Lines 190 to 196 in 5bf67f3
For newly submitted queries,
externalUrlandroutingGroupare stored here, so this refactoring won't affect the existing behavoir:trino-gateway/gateway-ha/src/main/java/io/trino/gateway/ha/handler/RoutingTargetHandler.java
Lines 94 to 114 in 5bf67f3
Release notes
(x) This is not user-visible or is docs only, and no release notes are required.