github-actions[bot] commented on code in PR #62620:
URL: https://github.com/apache/doris/pull/62620#discussion_r3129789869
##########
regression-test/data/pythonudtf_p0/test_pythonudtf_drop.out:
##########
@@ -7,7 +7,11 @@
1 2
2 3
--- !py_udtf_drop_3 --
+-- !py_udtf_drop_4 --
Review Comment:
This replaces the existing `py_udtf_drop_3` block even though the suite
still executes `qt_py_udtf_drop_3` above. The regression framework will stop
there with `Missing output block for tag 'py_udtf_drop_3'`, so the new
reconnect case never runs. `py_udtf_drop_3` needs to stay, and `_4`/`_5` should
be appended after it.
##########
regression-test/data/pythonudf_p0/test_pythonudf_drop.out:
##########
@@ -8,3 +8,9 @@
-- !py_udf_drop_3 --
8
+-- !py_udf_drop_4--
Review Comment:
`OutputUtils` only treats lines ending with `" --"` as output-block headers.
Because this line is `-- !py_udf_drop_4--`, `qt_py_udf_drop_4` will fail with
`Missing output block for tag 'py_udf_drop_4'`.
```suggestion
-- !py_udf_drop_4 --
```
##########
be/src/udf/python/python_server.cpp:
##########
@@ -125,14 +125,53 @@ Status PythonServerManager::get_process(const
PythonVersion& version, ProcessPtr
version.to_string());
}
- // Find process with minimum load (use_count - 1 gives active client count)
- auto min_iter = std::min_element(
- pool.begin(), pool.end(),
- [](const ProcessPtr& a, const ProcessPtr& b) { return
a.use_count() < b.use_count(); });
+ // Prefer an already-alive process and only use load balancing inside that
alive subset.
+ // keep dead entries stay in the pool for the background health checker
+ // unless there is no alive process left for the current request.
+ auto min_alive_iter = std::min_element(pool.begin(), pool.end(),
+ [](const ProcessPtr& a, const
ProcessPtr& b) {
+ const bool a_alive = a &&
a->is_alive();
+ const bool b_alive = b &&
b->is_alive();
+ if (a_alive != b_alive) {
+ return a_alive > b_alive;
+ }
+ if (!a_alive) {
+ return false;
+ }
+ return a.use_count() <
b.use_count();
+ });
+
+ if (min_alive_iter != pool.end() && *min_alive_iter &&
(*min_alive_iter)->is_alive()) {
+ *process = *min_alive_iter;
+ return Status::OK();
+ }
- // Return process with minimum load
- *process = *min_iter;
- return Status::OK();
+ // Only reach here when the pool has no alive process at all. In that
fallback path we
+ // rebuild one process so the caller can still make progress instead of
waiting
+ // for the next health-check round.
+ for (size_t i = 0; i < pool.size(); ++i) {
+ auto& candidate = pool[i];
+ ProcessPtr replacement;
+ Status status = fork(version, &replacement);
Review Comment:
`fork()` is not a cheap helper here: it launches a child process and then
polls for the socket file for up to 5 seconds. Calling it while `_pools_mutex`
is held means one recovery request can block every other `get_process()`
caller, even for other Python versions, plus the health-check /
`clear_module_cache()` paths on the same global mutex. Can this pick a slot
under the lock, drop the lock while spawning, and then re-check before
publishing the replacement?
##########
regression-test/suites/pythonudf_p0/test_pythonudf_drop.groovy:
##########
@@ -88,9 +88,33 @@ suite("test_pythonudf_drop") {
sql """SELECT py_drop_a(1);"""
exception "Can not found function"
}
+
+ // Case 3: kill Python servers between two queries, next client
handshake should recover
+ sql """DROP FUNCTION IF EXISTS py_drop_reconnect(INT)"""
+ sql """
+ CREATE FUNCTION py_drop_reconnect(INT) RETURNS INT PROPERTIES (
+ "type" = "PYTHON_UDF",
+ "file" = "file://${zipA}",
+ "symbol" = "drop_udf.evaluate",
+ "runtime_version" = "${runtime_version}"
+ )
+ """
+
+ qt_py_udf_drop_4 """SELECT py_drop_reconnect(31);"""
+
Review Comment:
`backendId_to_backendIP` and `execOnBackend` are not defined anywhere in
this suite. Unlike the UDAF/UDTF variants, the new reconnect case jumps
straight into `backendId_to_backendIP.values().each { ... }`, so this script
will throw `MissingPropertyException` before it ever exercises the recovery
path.
--
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]