Avoid null cache writes for query routing mappings - #963
Conversation
|
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 |
|
@ebyhr Hey, can you please check this pull request and also re run the cla action? i just got the mail that my cla is signed |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@ebyhr thank you so much for re running the cla bot, can you also review this pull request? |
|
@ebyhr Hey!! Please get a review on this? It would be great if you could please check this. |
|
@mosabua hello, can i please get a review on this? Pending since a long time, thank you so much! |
| @Override | ||
| public void setBackendForQueryId(String queryId, String backend) | ||
| { | ||
| if (Strings.isNullOrEmpty(queryId)) { |
There was a problem hiding this comment.
Let's import isNullOrEmpty directly.
| public void setBackendForQueryId(String queryId, String backend) | ||
| { | ||
| if (Strings.isNullOrEmpty(queryId)) { | ||
| log.warn("Skipping backend cache update for empty queryId"); |
There was a problem hiding this comment.
Why is the log level warning? What is the expected action when Trino Gateway admin sees this message?
Guard query-id cache writes in routing manager against null/empty values to prevent runtime failures when query history rows have been removed by retention.
The PR description indicates this is a normal scenario. The log level should be debug if so.
There was a problem hiding this comment.
makes sense, thanks for the review, made the changes @ebyhr
|
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 |
3bfc2be to
3ad9da9
Compare
|
@ebyhr can you please check this again? |
|
@mosabua can i please get a review here? Thanks much |
vishalya
left a comment
There was a problem hiding this comment.
My understanding of the flow is this: The trino-gateway first checks its in-memory cache for the query, then falls back to the query history. But if both caches have expired or don't contain the query id, the router would have to reach out directly to the actual clusters to discover where that query is currently executing. So I'm puzzled—how do we actually end up in a situation where both caches miss?
Could you explain why deleting the history would stop the search for the actual backend?
@vishalya |
|
I’m trying to trace the crash path and figure out whether we’re masking the real issue somewhere along the way. |
ebyhr
left a comment
There was a problem hiding this comment.
Please squash commits into one.
7ff4fa9 to
3a874a9
Compare
|
@ebyhr done, please check now |
|
@panjwanirahul Can you tell us how we can reproduce the situation? Steps that makes this NPE happen? |
|
This pull request has gone a while without any activity. Ask for help on #trino-gateway-dev on Trino slack. |
|
Closing this pull request, as it has been stale for six weeks. Feel free to re-open at any time. |
da96d75 to
d21403a
Compare
|
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 |
|
@Chaho12 Thanks for asking — here are reproducible steps. I also rebased this PR onto current main; the issue is still present. Why this happensCaffeine (and previously Guava) does not allow null cache values. When query-history retention has deleted the row, lookups can return null. Writing that null into the query-id caches throws NPE. To @vishalya’s earlier question: backend lookup has an extra fallback ( Minimal unit-test reproduction (current main)routingManager.setRoutingGroupForQueryId("20260315_query", null);
// throws NullPointerException from Caffeine put
routingManager.setExternalUrlForQueryId("20260315_query", null);
// throws NullPointerException from Caffeine putOn this branch those calls no longer throw; the cache entry is invalidated/skipped and later End-to-end reproduction
Local validation on latest main
Happy to address any further review comments. |
Guard query-id cache writes in routing manager against null/empty values to prevent runtime failures when query history rows have been removed by retention.
d21403a to
53019af
Compare
Guard query-id cache writes in routing manager against null/empty values to prevent runtime failures when query history rows have been removed by retention.
What changed
BaseRoutingManager:setBackendForQueryId(...): skip emptyqueryId; invalidate entry if backend is null/empty.setRoutingGroupForQueryId(...): skip emptyqueryId; invalidate entry if routing group is null/empty.setExternalUrlForQueryId(...): skip emptyqueryId; invalidate entry ifexternalUrlis null.TestRoutingManagerExternalUrlCache:testNullExternalUrlDoesNotThrowAndFallsBackToQueryHistorytestNullQueryIdDoesNotThrowForExternalUrlCacheSetWhy
When query history retention deletes older records, lookup for
externalUrlcan return null.The previous code attempted to cache that null value, which caused an NPE in the cache path.
The new behavior treats null/empty mappings as “not cacheable” and preserves normal fallback behavior.
Additional context and related issues
TestRoutingManagerExternalUrlCachepassed.TestRoutingManagerExternalUrlCache,TestRoutingGroupSelector,TestRoutingRulesManager,TestPathFilter,TestTrinoRequestUser,TestTrinoQueryProperties).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 a NullPointerException in query routing cache updates when retained query history entries are removed and external URL lookup returns null.