You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by yo...@apache.org on 2025/12/16 05:58:47 UTC
(iotdb) 10/14: [AINode] Enable AINode start as background (-d) (#16762)
This is an automated email from the ASF dual-hosted git repository.
yongzao pushed a commit to branch cp-ain-to-206
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit d52bf55a6ce3b71c1cde44250c9688e000d3c661
Author: Yongzao <53...@qq.com>
AuthorDate: Sat Nov 15 16:56:32 2025 +0800
[AINode] Enable AINode start as background (-d) (#16762)
(cherry picked from commit 1ebb9515767eee492a908cfad38a478f1ec7bba0)
---
iotdb-core/ainode/iotdb/ainode/core/ai_node.py | 10 +++++++---
.../iotdb/ainode/core/inference/pool_controller.py | 2 +-
iotdb-core/ainode/iotdb/ainode/core/rpc/handler.py | 2 +-
iotdb-core/ainode/iotdb/ainode/core/rpc/service.py | 1 +
scripts/sbin/start-ainode.sh | 17 +++++++++++++----
scripts/sbin/windows/start-ainode.bat | 22 +++++++++++++++++-----
6 files changed, 40 insertions(+), 14 deletions(-)
diff --git a/iotdb-core/ainode/iotdb/ainode/core/ai_node.py b/iotdb-core/ainode/iotdb/ainode/core/ai_node.py
index b323818c155..13ff1f485d4 100644
--- a/iotdb-core/ainode/iotdb/ainode/core/ai_node.py
+++ b/iotdb-core/ainode/iotdb/ainode/core/ai_node.py
@@ -163,7 +163,11 @@ class AINode:
self._rpc_handler.stop()
if self._rpc_service:
self._rpc_service.stop()
- self._rpc_service.join(1)
- if self._rpc_service.is_alive():
- logger.warning("RPC service thread failed to stop in time.")
+ for retry in range(30):
+ self._rpc_service.join(2)
+ if not self._rpc_service.is_alive():
+ logger.warning(
+ "RPC service thread failed to stop in time, retrying..."
+ )
+ break
logger.info("IoTDB-AINode has successfully stopped.")
diff --git a/iotdb-core/ainode/iotdb/ainode/core/inference/pool_controller.py b/iotdb-core/ainode/iotdb/ainode/core/inference/pool_controller.py
index 00bb3b5568b..54580402ec2 100644
--- a/iotdb-core/ainode/iotdb/ainode/core/inference/pool_controller.py
+++ b/iotdb-core/ainode/iotdb/ainode/core/inference/pool_controller.py
@@ -504,7 +504,7 @@ class PoolController:
return pool_group.get_load(pool_id)
return -1
- def shutdown(self):
+ def stop(self):
self._stop_event.set()
# shutdown pool controller
diff --git a/iotdb-core/ainode/iotdb/ainode/core/rpc/handler.py b/iotdb-core/ainode/iotdb/ainode/core/rpc/handler.py
index ce7ce26abfc..eaad313903d 100644
--- a/iotdb-core/ainode/iotdb/ainode/core/rpc/handler.py
+++ b/iotdb-core/ainode/iotdb/ainode/core/rpc/handler.py
@@ -48,7 +48,7 @@ class AINodeRPCServiceHandler(IAINodeRPCService.Iface):
def stop(self) -> None:
logger.info("Stopping the RPC service handler of IoTDB-AINode...")
- self._inference_manager.shutdown()
+ self._inference_manager.stop()
def stopAINode(self) -> TSStatus:
self._ainode.stop()
diff --git a/iotdb-core/ainode/iotdb/ainode/core/rpc/service.py b/iotdb-core/ainode/iotdb/ainode/core/rpc/service.py
index 8642f62fc20..2282ae237d8 100644
--- a/iotdb-core/ainode/iotdb/ainode/core/rpc/service.py
+++ b/iotdb-core/ainode/iotdb/ainode/core/rpc/service.py
@@ -102,3 +102,4 @@ class AINodeRPCService(threading.Thread):
logger.info("Stopping the RPC service of IoTDB-AINode...")
self._stop_event.set()
self.__pool_server.stop()
+ self._handler.stop()
diff --git a/scripts/sbin/start-ainode.sh b/scripts/sbin/start-ainode.sh
index 671de54ba1a..454a0389c38 100644
--- a/scripts/sbin/start-ainode.sh
+++ b/scripts/sbin/start-ainode.sh
@@ -27,10 +27,14 @@ export IOTDB_AINODE_HOME
echo "IOTDB_AINODE_HOME: $IOTDB_AINODE_HOME"
# fetch parameters with names
-while getopts "i:rn" opt; do
+daemon_mode=false
+while getopts "i:rnd" opt; do
case $opt in
n)
;;
+ d)
+ daemon_mode=true
+ ;;
\?) echo "Invalid option -$OPTARG" >&2
exit 1
;;
@@ -41,6 +45,11 @@ ain_ainode_executable="$IOTDB_AINODE_HOME/lib/ainode"
echo Script got ainode executable: "$ain_ainode_executable"
-echo Starting AINode...
-
-$ain_ainode_executable start
+if [ "$daemon_mode" = true ]; then
+ echo Starting AINode in daemon mode...
+ nohup $ain_ainode_executable start > /dev/null 2>&1 &
+ echo AINode started in background
+else
+ echo Starting AINode...
+ $ain_ainode_executable start
+fi
diff --git a/scripts/sbin/windows/start-ainode.bat b/scripts/sbin/windows/start-ainode.bat
index 1d9a4306baf..09ce914f226 100644
--- a/scripts/sbin/windows/start-ainode.bat
+++ b/scripts/sbin/windows/start-ainode.bat
@@ -30,8 +30,20 @@ set ain_ainode_executable=%IOTDB_AINODE_HOME%\lib\ainode
echo Script got ainode executable: %ain_ainode_executable%
-echo Starting AINode...
-
-%$ain_ainode_executable% start
-
-pause
\ No newline at end of file
+set daemon_mode=false
+:parse_args
+if "%~1"=="" goto end_parse
+if /i "%~1"=="-d" set daemon_mode=true
+shift
+goto parse_args
+:end_parse
+
+if "%daemon_mode%"=="true" (
+ echo Starting AINode in daemon mode...
+ start /B "" %ain_ainode_executable% start
+ echo AINode started in background
+) else (
+ echo Starting AINode...
+ %ain_ainode_executable% start
+ pause
+)
\ No newline at end of file