Skip to content

branch-4.1: [Fix](udf) Key UDF class cache by function ID and enable cleanup in cloud mode (#67046) - #67314

Merged
yiguolei merged 1 commit into
apache:branch-4.1from
linrrzqqq:pick-67046-branch-4.1
Aug 31, 2026
Merged

branch-4.1: [Fix](udf) Key UDF class cache by function ID and enable cleanup in cloud mode (#67046)#67314
yiguolei merged 1 commit into
apache:branch-4.1from
linrrzqqq:pick-67046-branch-4.1

Conversation

@linrrzqqq

Copy link
Copy Markdown
Collaborator

pick: #67046

…loud mode (apache#67046)

Problem Summary:

UDF cache cleanup has two problems:

1. Cloud mode does not register a worker for `CLEAN_UDF_CACHE`, so `DROP
FUNCTION` cannot clean the cached UDF classloader.
2. UDF caches are cleaned by function signature. If a function is
dropped and recreated with the same signature, a delayed cleanup task
may delete the new cache, or the recreated function may reuse the stale
cache.

The FE removes the function metadata first and then submits
`CleanUDFCacheTask` asynchronously. It does not wait for the BE cache
cleanup result.

In addition, the cleanup task does not report a completion result back
to the FE. Therefore, even if the task cannot be submitted or the JNI
cache cleanup fails, `DROP FUNCTION` still returns success to the
client.

```sql
CREATE FUNCTION test_udf(INT) RETURNS INT ...; -- implementation V1
SELECT test_udf(1);                            -- cache V1

DROP FUNCTION test_udf(INT);                   -- cache cleanup fails or is delayed

CREATE FUNCTION test_udf(INT) RETURNS INT ...; -- implementation V2
SELECT test_udf(1);
````

Before this PR, the last query could reuse V1's cached classloader
because V1 and V2 had the same signature. A delayed cleanup task for V1
could also remove V2's cache.

- Register the CLEAN_UDF_CACHE worker in cloud mode.
- Use the function ID as the key for Java UDF cache lookup, insertion,
and cleanup.
= Fall back to signature-based cleanup when no valid function ID is
provided for compatibility with older FEs.

A recreated function receives a new function ID. Therefore, even if the
previous function's cache is not successfully removed, the recreated
function does not reuse it and can load and execute the correct
implementation. A delayed cleanup task also removes only the old
function's cache without affecting the recreated function.
@linrrzqqq
linrrzqqq requested a review from yiguolei as a code owner August 30, 2026 09:38
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (27/27) 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 9.09% (2/22) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 59.47% (25806/43394)
Line Coverage 44.05% (264773/601030)
Region Coverage 39.98% (209963/525233)
Branch Coverage 41.41% (96956/234135)

@yiguolei
yiguolei merged commit 827e388 into apache:branch-4.1 Aug 31, 2026
29 of 32 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by anyone and no changes requested.

@github-actions

Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Aug 31, 2026
@linrrzqqq
linrrzqqq deleted the pick-67046-branch-4.1 branch August 31, 2026 07:42
@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 81.82% (18/22) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.21% (31223/42073)
Line Coverage 58.31% (345681/592852)
Region Coverage 55.09% (288069/522875)
Branch Coverage 55.88% (129435/231628)

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

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants