Skip to content

Refactor routing logics and remove unused lookups#923

Open
oneonestar wants to merge 4 commits intotrinodb:mainfrom
oneonestar:ypoon/refactor_cache
Open

Refactor routing logics and remove unused lookups#923
oneonestar wants to merge 4 commits intotrinodb:mainfrom
oneonestar:ypoon/refactor_cache

Conversation

@oneonestar
Copy link
Member

Description

Refactor the code to separate Query ID/Cookie-based routing from new query submission routing.

Remove the unnecessary getExternalUrlForQueryId and getRoutingGroupForQueryId methods, along with their related DAOs and caches. The externalUrl and routingGroup fields are stored for newly submitted queries as before.

Additional context and related issues

getExternalUrlForQueryId and getRoutingGroupForQueryId are 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:

if (statementPaths.stream().anyMatch(request.getUri().getPath()::startsWith) && request.getMethod().equals(HttpMethod.POST)) {
Optional<String> username = ((TrinoRequestUser) servletRequest.getAttribute(TRINO_REQUEST_USER)).getUser();
future = future.transform(response -> recordBackendForQueryId(request, response, username, routingDestination), executor);
if (includeClusterInfoInResponse) {
cookieBuilder.add(new NewCookie.Builder("trinoClusterHost").value(remoteUri.getHost()).build());
}
}

For newly submitted queries, externalUrl and routingGroup are stored here, so this refactoring won't affect the existing behavoir:

private RoutingTargetResponse getRoutingTargetResponse(HttpServletRequest request)
{
RoutingSelectorResponse routingDestination = routingGroupSelector.findRoutingDestination(request);
String user = request.getHeader(USER_HEADER);
// This falls back on default routing group backend if there is no cluster found for the routing group.
String routingGroup = !isNullOrEmpty(routingDestination.routingGroup())
? routingDestination.routingGroup()
: defaultRoutingGroup;
ProxyBackendConfiguration backendConfiguration = routingManager.provideBackendConfiguration(routingGroup, user);
String clusterHost = backendConfiguration.getProxyTo();
String externalUrl = backendConfiguration.getExternalUrl();
// Apply headers from RoutingDestination if there are any
HttpServletRequest modifiedRequest = request;
if (!routingDestination.externalHeaders().isEmpty()) {
modifiedRequest = new HeaderModifyingRequestWrapper(request, routingDestination.externalHeaders());
}
return new RoutingTargetResponse(
new RoutingDestination(routingGroup, clusterHost, buildUriWithNewCluster(clusterHost, request), externalUrl),
modifiedRequest);
}

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant

Comments