This is an automated email from the ASF dual-hosted git repository.

CritasWang pushed a commit to branch feat/schema-export-tags-attributes
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 09f87bc437248e7959918b1e7396def9e4db07c7
Author: CritasWang <[email protected]>
AuthorDate: Fri Nov 27 16:14:21 2026 +0800

    [Tools] Exit non-zero when import-schema connection retries are exhausted
    
    The connection failure was already reported to the console and the
    failed rows were written to the failed-record file, but writeScheme
    threw IllegalStateException after all of that work was done and the
    calling importSchemaFromCsvFile only caught IOException /
    IllegalPathException, so the exception was swallowed by the generic
    run() handler and importFromTargetPath returned CODE_OK (0).
    
    Add a connectionFailed flag in AbstractSchemaTool. The
    IllegalStateException that writeScheme raises on retry exhaustion is
    now caught separately in importSchemaFromCsvFile, which sets the flag
    instead of re-throwing. importFromTargetPath reads the flag after all
    files are processed and returns CODE_ERROR when it is set.
    
    Verified: import against an unreachable port now exits 1 for both
    aligned and non-aligned paths, the failed-record file is still
    written, and all 35 cli schema unit tests pass on both en and
    zh-locale compile.
---
 .../main/java/org/apache/iotdb/tool/schema/AbstractSchemaTool.java | 7 +++++++
 .../src/main/java/org/apache/iotdb/tool/schema/ImportSchema.java   | 5 +++++
 .../main/java/org/apache/iotdb/tool/schema/ImportSchemaTree.java   | 4 ++++
 3 files changed, 16 insertions(+)

diff --git 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/AbstractSchemaTool.java
 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/AbstractSchemaTool.java
index 27b15138ea8..5740cabd67f 100644
--- 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/AbstractSchemaTool.java
+++ 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/AbstractSchemaTool.java
@@ -82,6 +82,13 @@ public abstract class AbstractSchemaTool {
   protected static String targetFile = Constants.DUMP_FILE_NAME_DEFAULT;
   protected static final LongAdder loadFileSuccessfulNum = new LongAdder();
 
+  /**
+   * Set to {@code true} when a connection-retry failure is surfaced from an 
import file; checked by
+   * the entry point to produce a non-zero exit status even though the 
per-file reporting has
+   * already printed the failure and written the failed-record file.
+   */
+  protected static volatile boolean connectionFailed = false;
+
   private static final IoTPrinter ioTPrinter = new IoTPrinter(System.out);
   private static final Logger LOGGER = 
LoggerFactory.getLogger(AbstractSchemaTool.class);
 
diff --git 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ImportSchema.java 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ImportSchema.java
index eb446a9f705..c565e5dcfcb 100644
--- 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ImportSchema.java
+++ 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ImportSchema.java
@@ -161,6 +161,11 @@ public class ImportSchema extends AbstractSchemaTool {
       }
       importSchema.init();
       AbstractImportSchema.init(importSchema);
+      if (connectionFailed) {
+        ioTPrinter.println(
+            String.format(CliMessages.MESSAGE_IMPORT_SCHEMA_FAIL_ARG_609A6D30, 
"connection"));
+        return Constants.CODE_ERROR;
+      }
       return Constants.CODE_OK;
     } catch (InterruptedException e) {
       ioTPrinter.println(
diff --git 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ImportSchemaTree.java
 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ImportSchemaTree.java
index 429bbb618bb..8d51c052026 100644
--- 
a/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ImportSchemaTree.java
+++ 
b/iotdb-client/cli/src/main/java/org/apache/iotdb/tool/schema/ImportSchemaTree.java
@@ -125,6 +125,10 @@ public class ImportSchemaTree extends AbstractImportSchema 
{
       }
       writeScheme(file.getName(), headerNames, records, failedFilePath);
       processSuccessFile();
+    } catch (IllegalStateException e) {
+      // A connection-retry failure is already reported and the failed rows 
are already written;
+      // set the flag so the entry point can exit with a non-zero status code.
+      connectionFailed = true;
     } catch (IOException | IllegalPathException e) {
       ioTPrinter.println(
           String.format(

Reply via email to