-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Fix](python udf) isolate module caches across functions #67511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -567,29 +567,36 @@ Status UserFunctionCache::_check_and_return_default_java_udf_url(const std::stri | |
| return Status::OK(); | ||
| } | ||
|
|
||
| void UserFunctionCache::drop_function_cache(int64_t fid) { | ||
| Status UserFunctionCache::drop_function_cache(int64_t fid) { | ||
| std::shared_ptr<UserFunctionCacheEntry> entry = nullptr; | ||
| { | ||
| std::lock_guard<std::mutex> l(_cache_lock); | ||
| auto it = _entry_map.find(fid); | ||
| if (it == _entry_map.end()) { | ||
| return; | ||
| return Status::OK(); | ||
| } | ||
| entry = it->second; | ||
| _entry_map.erase(it); | ||
| } | ||
|
|
||
| // lib_file changes from the downloaded zip path to the extracted directory | ||
| // while an entry is loaded. Wait for that transition before clearing Python. | ||
| std::unique_lock<std::mutex> load_lock(entry->load_lock); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // For Python UDF, clear module cache in Python server before deleting files | ||
| if (entry->type == LibType::PY_ZIP && !entry->lib_file.empty()) { | ||
| auto status = PythonServerManager::instance().clear_module_cache(entry->lib_file); | ||
| if (!status.ok()) [[unlikely]] { | ||
| LOG(WARNING) << "drop_function_cache: failed to clear Python module cache for " | ||
| << entry->lib_file << ": " << status.to_string(); | ||
| } | ||
| RETURN_IF_ERROR(PythonServerManager::instance().clear_module_cache(entry->lib_file)); | ||
| } | ||
|
|
||
| { | ||
| std::lock_guard<std::mutex> l(_cache_lock); | ||
| auto it = _entry_map.find(fid); | ||
| if (it != _entry_map.end() && it->second == entry) { | ||
| _entry_map.erase(it); | ||
| } | ||
| } | ||
| // Mark for deletion, destructor will delete the files | ||
| entry->should_delete_library.store(true); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| } // namespace doris | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop_function_cacheintentionally keeps the entry/files whenclear_module_cachefails, but this callback only logs the error and returns from avoidworker task.DropFunctionCommandsubmitsCleanUDFCacheTaskonce, and the task pool has no retry/requeue or completion failure propagation, so a transiently dead Python process permanently leaks the cache entry and both files. Please add a deferred/bounded retry (or another recovery queue) and surface an unrecoverable failure instead of treating this task as handled.