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.
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. - Use direct static import for isNullOrEmpty. - Change log level from warn to debug for empty queryId checks. - Standardize null/empty handling across all cache setters. - Add regression tests for null/empty external URL and query ID. Co-authored-by: Cursor <cursoragent@cursor.com>
7ff4fa9 to
3a874a9
Compare
|
@ebyhr done, please check now |
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.