hello-stephen commented on code in PR #69255:
URL: https://github.com/apache/doris/pull/69255#discussion_r4765935599
##########
be/src/udf/python/python_server.cpp:
##########
@@ -719,104 +926,50 @@ void PythonServerManager::_refresh_memory_stats() {
}
}
-Status PythonServerManager::clear_module_cache(const std::string& location) {
- if (location.empty()) {
- return Status::InvalidArgument("Empty location for
clear_module_cache");
- }
-
- std::string body = fmt::format(R"({{"location": "{}"}})", location);
- return _broadcast_action_to_processes("clear_module_cache", body,
- fmt::format("location={}",
location));
-}
-
-void PythonServerManager::clear_udaf_state_cache(int64_t function_id) {
- std::string body = fmt::format(R"({{"function_id": {}}})", function_id);
- WARN_IF_ERROR(_broadcast_action_to_processes("clear_udaf_state_cache",
body,
- fmt::format("function_id={}",
function_id)),
- "failed to clear Python UDAF state cache");
-}
-
-Status PythonServerManager::_broadcast_action_to_processes(const std::string&
action_type,
- const std::string&
body,
- const std::string&
log_name) {
- int success_count = 0;
- int fail_count = 0;
- bool has_active_process = false;
-
- for (auto& [version, versioned_pool] : _snapshot_process_pools()) {
- std::lock_guard<std::mutex> lock(versioned_pool->mutex);
- auto& pool = versioned_pool->processes;
- for (auto& process : pool) {
- if (!process || !process->is_alive()) {
- continue;
- }
- has_active_process = true;
- try {
- auto loc_result =
arrow::flight::Location::Parse(process->get_uri());
- if (!loc_result.ok()) [[unlikely]] {
- fail_count++;
- continue;
- }
-
- auto client_result =
arrow::flight::FlightClient::Connect(*loc_result);
- if (!client_result.ok()) [[unlikely]] {
- fail_count++;
- continue;
- }
- auto client = std::move(*client_result);
-
- arrow::flight::Action action;
- action.type = action_type;
- action.body = arrow::Buffer::FromString(body);
-
- auto result_stream = client->DoAction(action);
- if (!result_stream.ok()) {
- fail_count++;
- continue;
- }
-
- auto result = (*result_stream)->Next();
- if (result.ok() && *result) {
- success_count++;
- } else {
- fail_count++;
- }
-
- } catch (...) {
- fail_count++;
- }
+void PythonServerManager::drop_function(int64_t function_id) {
+ std::shared_ptr<PythonFunctionRuntime> pool;
+ std::vector<ProcessPtr> processes;
+ {
+ std::scoped_lock map_lock(_pools_mutex);
+ auto iter = _process_pools.find(function_id);
+ if (iter == _process_pools.end()) {
+ return;
}
+ pool = std::move(iter->second);
+ // Stop init/repair -> detach processes -> erase pool -> unlock ->
release references.
+ const size_t freed = pool->stop(&processes, [idle_queue =
_idle_pool_queue, function_id]() {
+ idle_queue->remove(function_id);
+ });
+ if (freed > 0) {
+ _reserved_processes->fetch_sub(freed, std::memory_order_acq_rel);
Review Comment:
[P2] Keep retained live processes charged against the global limit
`stop()` detaches the pool's processes, but an active `PythonClient` keeps
its `ProcessPtr` until close. With `max_python_process_num=1` and
`pool_size=1`, let a query using `f1` keep running, then DROP `f1`: this
subtraction makes the reservation count zero while its Python child remains
alive. A query using a different, valid function `f2` can immediately reserve
that slot and start a second child. Repeating this with long-running queries
can exceed the configured total process ceiling and its intended resource
bound. This requires no late acquisition of the dropped ID. Keep detached
processes with active owners charged until they terminate, and cover
active-client DROP followed by another function's admission; the existing
retained-process tests check RSS, while the quota DROP test has no active
client.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]