Skip to content

Use orElseGet for lazy evaluation in RoutingTargetHandler#921

Closed
zeckem19 wants to merge 1 commit intotrinodb:mainfrom
zeckem19:patch-1
Closed

Use orElseGet for lazy evaluation in RoutingTargetHandler#921
zeckem19 wants to merge 1 commit intotrinodb:mainfrom
zeckem19:patch-1

Conversation

@zeckem19
Copy link

@zeckem19 zeckem19 commented Feb 16, 2026

Fixes #920

Description

RoutingTargetHandler.resolveRouting() uses Optional.orElse(getRoutingTargetResponse(request)) which eagerly evaluates the fallback even when the query ID is found in the cache. If getRoutingTargetResponse() throws (e.g. no backends match the routing rules), the exception propagates and the request fails with a 500, despite the query ID being successfully resolved.

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
(X) Release notes are required, with the following suggested text:
Fix eager evaluation in RoutingTargetHandler

* Fix some things.

@cla-bot
Copy link

cla-bot bot commented Feb 16, 2026

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

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

Could you please submit CLA?

new RoutingDestination(routingGroup, cluster, buildUriWithNewCluster(cluster, request), externalUrl),
request);
}).orElse(getRoutingTargetResponse(request));
}).orElseGet(() -> getRoutingTargetResponse(request));
Copy link
Member

@ebyhr ebyhr Feb 16, 2026

Choose a reason for hiding this comment

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

Is it possible to add a test? Let me know if the test is too complicated.

@zeckem19
Copy link
Author

Superseded by #922 which includes the same fix plus a test case.

@zeckem19 zeckem19 closed this Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

infoUri broken likely due to eager evaluation failure on /ui/query.html

2 participants

Comments