[Feature request] CLI should support automatic reconnection when connection is lost during interactive session
还没有人认领这个 Issue。
评估
调研方向
从 iotdb-client/cli/src/main/java/org/apache/iotdb/cli/Cli.java 开始,重点查看 receiveCommands() 和 processCommand,然后阅读 iotdb-client/jdbc 下的 IoTDBConnection.reconnect() 和 IoTDBStatement.callWithRetryAndReconnect()。当连接相关的失败会在限定的重连尝试次数内进行重试,成功恢复后会在提供反馈的同时重试命令,并且恢复失败时会清晰地退出,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Search before asking
- I searched in the issues and found nothing similar.
Motivation
I am always frustrated when the IoTDB CLI exits as soon as the connection to the server is lost (e.g. server restart, network blip, or idle timeout). I have to reconnect manually, re-enter connection parameters, and lose my session context.
Other IoTDB clients already support reconnection: the Session API (Java), JDBC (via callWithRetryAndReconnect in IoTDBStatement), and the C++/Python clients all retry and reconnect on connection failure. The CLI is the only major client that does not—it holds a single connection for the entire interactive session and exits on any connection-related error. Adding automatic reconnection to the CLI would align its behaviour with the rest of the client stack and improve the experience for long-lived interactive sessions (e.g. over SSH or after server restarts).
Solution
Proposed behaviour
-
Detect connection loss
When a command fails with a connection-related error (e.g. SQLException caused by connection refused, timeout, or closed connection), do not exit immediately. -
Attempt reconnection
Try to establish a new connection using the same parameters (host, port, user, password, and options) that were used at login. Reuse the same logic as the initial connection (e.g. DriverManager.getConnection with the same URL and properties). -
Retry the command
After a successful reconnection, retry the same user command (the current line/statement that failed) with the new connection, with a bounded number of retries (e.g. 3) and optional backoff. -
User feedback
On successful reconnection, print a short message such as: "Connection lost. Reconnected. Retrying command." and continue the interactive loop with the new connection. -
Failure handling
If reconnection fails after all retries, exit with a clear error message, e.g. "Could not reconnect after N attempts. Please check that the server is running and try again."
Relevant code
-
iotdb-client/cli/src/main/java/org/apache/iotdb/cli/Cli.java:receiveCommands()opens one connection and runs awhile (true)loop; any SQLException is caught at the top level and the process exits (lines 215–217).- Change: catch connection-related failures inside the loop (or around
processCommand), attempt reconnection, then retry the command or continue with the new connection.
-
iotdb-client/jdbc:IoTDBConnection.reconnect()andIoTDBStatement.callWithRetryAndReconnect()can be used as reference for retry/reconnect behaviour.
Optional
- Make retry count and interval configurable (e.g. CLI options or environment variables) for consistency with Session/JDBC.
Alternatives
-
No retry, only reconnect
On connection loss, attempt reconnection and, on success, continue the session without retrying the failed command (user re-enters it). Simpler to implement but less convenient than retrying the last command. -
Prompt user
On connection loss, prompt: "Connection lost. Reconnect? (y/n)". If yes, reconnect and optionally retry the command. Gives control but adds friction for automated or scripted use. -
Leave as-is
Keep current behaviour (exit on connection loss). This preserves simplicity but leaves the CLI as the only client without reconnection support and worsens UX for long sessions and unstable networks.
Are you willing to submit a PR?
- I'm willing to submit a PR!
- 主要语言
- Java
- 星标
- 6.4k
- 派生
- 1.2k
- 平均合并
- 1 天 17 小时
- 30 天内合并 PR
- 152
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/iotdb 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
-
IoTDB Edge: stop-edge.sh does not stop its own process when IOTDB_HOME is set, and reports success 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 78/100
相似的 Issue
-
area-deployment area-integrations triage:bot-seen
难度 2/5 半天 新手友好度 86/100
-
难度 2/5 1-3 小时 新手友好度 75/100
apache/flink-agents#1156 ·
-
area/connectors autoteam community connectors/source/shopify needs-triage team/use type/bug
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 1/5 1 小时以内 新手友好度 85/100