This is an automated email from the ASF dual-hosted git repository.
CRZbulabula pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 4eebf87a79c Keep unrecoverable error status reasons on one line
(#19132)
4eebf87a79c is described below
commit 4eebf87a79cff704ba5a28a805c1aad2b9cd6a73
Author: d-wang-commit <[email protected]>
AuthorDate: Thu Nov 5 22:33:13 2026 +0800
Keep unrecoverable error status reasons on one line (#19132)
Normalize whitespace before truncating the exception message for read-only
status.
Mark omitted text with an ellipsis and preserve whole Unicode characters.
---
.../apache/iotdb/commons/conf/CommonConfig.java | 29 +++-----------------
.../commons/enums/HandleSystemErrorStrategy.java | 31 ++++++++++++++++++++--
.../iotdb/commons/conf/CommonConfigTest.java | 31 +++++++++++++---------
3 files changed, 52 insertions(+), 39 deletions(-)
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
index e9dddb4a853..dc5b6a1e8db 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonConfig.java
@@ -27,7 +27,6 @@ import
org.apache.iotdb.commons.enums.HandleSystemErrorStrategy;
import org.apache.iotdb.commons.enums.PipeRateAverage;
import org.apache.iotdb.commons.i18n.ConfigMessages;
import org.apache.iotdb.commons.pipe.config.PipeConfig;
-import org.apache.iotdb.commons.queryengine.utils.DateTimeUtils;
import org.apache.iotdb.commons.utils.FileUtils;
import org.apache.iotdb.commons.utils.KillPoint.KillPoint;
import org.apache.iotdb.rpc.RpcUtils;
@@ -179,15 +178,13 @@ public class CommonConfig {
private volatile NodeStatus status = NodeStatus.Running;
/**
- * Maximum length of the error message embedded in the UnrecoverableError
status reason, keeping
- * the reason bounded in heartbeats and SHOW results.
+ * Reason reported in heartbeats and SHOW results. For unrecoverable errors,
{@link
+ * HandleSystemErrorStrategy} formats the exception before setting this
field.
*/
- private static final int MAX_STATUS_REASON_LENGTH = 256;
+ private volatile String statusReason = null;
private volatile boolean isStopping = false;
- private volatile String statusReason = null;
-
// Only failed sources are retained. Directory initialization uses its
folder list as the key;
// a live FolderManager uses its identity so its health restrictions are
also checked.
private final Map<Object, BooleanSupplier> diskFullRecoveryChecks = new
HashMap<>();
@@ -798,26 +795,8 @@ public class CommonConfig {
this.handleSystemErrorStrategy = handleSystemErrorStrategy;
}
- /**
- * Handles an unrecoverable error with the given exception. The ReadOnly
status reason is
- * assembled here so that all call sites share one format:
"UnrecoverableError, <timestamp>,
- * <error message>". The error message is truncated to {@link
#MAX_STATUS_REASON_LENGTH}
- * characters so that the reason published in heartbeats and SHOW results
stays bounded.
- */
public void handleUnrecoverableError(Throwable e) {
- String errorMessage =
- e.getMessage() == null || e.getMessage().isEmpty()
- ? e.getClass().getSimpleName()
- : e.getMessage();
- if (errorMessage.length() > MAX_STATUS_REASON_LENGTH) {
- errorMessage = errorMessage.substring(0, MAX_STATUS_REASON_LENGTH) +
"...";
- }
- handleSystemErrorStrategy.handle(
- NodeStatus.UNRECOVERABLE_ERROR
- + ", "
- + DateTimeUtils.convertLongToDate(System.currentTimeMillis(), "ms")
- + ", "
- + errorMessage);
+ handleSystemErrorStrategy.handle(NodeStatus.UNRECOVERABLE_ERROR, e);
}
public double getDiskSpaceWarningThreshold() {
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/enums/HandleSystemErrorStrategy.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/enums/HandleSystemErrorStrategy.java
index 53da902872b..542bc075a77 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/enums/HandleSystemErrorStrategy.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/enums/HandleSystemErrorStrategy.java
@@ -21,7 +21,9 @@ package org.apache.iotdb.commons.enums;
import org.apache.iotdb.commons.cluster.NodeStatus;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.i18n.CommonMessages;
+import org.apache.iotdb.commons.queryengine.utils.DateTimeUtils;
+import com.google.common.base.CharMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,8 +34,11 @@ public enum HandleSystemErrorStrategy {
SHUTDOWN;
private static final Logger logger =
LoggerFactory.getLogger(HandleSystemErrorStrategy.class);
+ private static final int MAX_STATUS_REASON_LENGTH = 256;
+ private static final CharMatcher SEPARATORS =
+ CharMatcher.whitespace().or(CharMatcher.javaIsoControl());
- public void handle(String errorReason) {
+ public void handle(String errorReason, Throwable e) {
if (this == HandleSystemErrorStrategy.CHANGE_TO_READ_ONLY) {
logger.error(
CommonMessages
@@ -41,7 +46,13 @@ public enum HandleSystemErrorStrategy {
new RuntimeException(CommonMessages.SYSTEM_READ_ONLY));
CommonDescriptor.getInstance()
.getConfig()
- .setNodeStatusWithReason(NodeStatus.ReadOnly, errorReason);
+ .setNodeStatusWithReason(
+ NodeStatus.ReadOnly,
+ errorReason
+ + ", "
+ +
DateTimeUtils.convertLongToDate(System.currentTimeMillis(), "ms")
+ + ", "
+ + formatMessage(e));
} else if (this == HandleSystemErrorStrategy.SHUTDOWN) {
logger.error(
CommonMessages
@@ -50,4 +61,20 @@ public enum HandleSystemErrorStrategy {
System.exit(-1);
}
}
+
+ private static String formatMessage(Throwable e) {
+ String message = e.getMessage();
+ message = message == null ? "" : SEPARATORS.trimAndCollapseFrom(message, '
');
+ if (message.isEmpty()) {
+ message = e.getClass().getSimpleName();
+ }
+ if (message.length() <= MAX_STATUS_REASON_LENGTH) {
+ return message;
+ }
+ int end = MAX_STATUS_REASON_LENGTH;
+ if (Character.isHighSurrogate(message.charAt(end - 1))) {
+ end--;
+ }
+ return message.substring(0, end).stripTrailing() + "...";
+ }
}
diff --git
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/conf/CommonConfigTest.java
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/conf/CommonConfigTest.java
index 68a3a98cf49..494db7d94ed 100644
---
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/conf/CommonConfigTest.java
+++
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/conf/CommonConfigTest.java
@@ -294,10 +294,11 @@ public class CommonConfigTest {
String originalStatusReason = config.getStatusReason();
try {
config.setNodeStatus(NodeStatus.Running);
- config.handleUnrecoverableError(new IOException("disk broken"));
+ config.handleUnrecoverableError(
+ new IOException(" \r\n disk\t
broken\r\n\t|\u00a0page\u2028fault\u0085at\b42 \t"));
Assert.assertEquals(NodeStatus.ReadOnly, config.getNodeStatus());
Assert.assertTrue(config.getStatusReason().startsWith(NodeStatus.UNRECOVERABLE_ERROR
+ ", "));
- Assert.assertTrue(config.getStatusReason().contains("disk broken"));
+ Assert.assertTrue(config.getStatusReason().endsWith(", disk broken |
page fault at 42"));
} finally {
config.setNodeStatus(NodeStatus.Running);
config.setNodeStatusWithReason(originalStatus, originalStatusReason);
@@ -349,7 +350,10 @@ public class CommonConfigTest {
config.setNodeStatus(NodeStatus.Running);
config.handleUnrecoverableError(new RuntimeException());
Assert.assertEquals(NodeStatus.ReadOnly, config.getNodeStatus());
- Assert.assertTrue(config.getStatusReason().contains("RuntimeException"));
+ Assert.assertTrue(config.getStatusReason().endsWith(",
RuntimeException"));
+ config.setNodeStatus(NodeStatus.Running);
+ config.handleUnrecoverableError(new IOException("\t\r\n\u3000"));
+ Assert.assertTrue(config.getStatusReason().endsWith(", IOException"));
} finally {
config.setNodeStatus(NodeStatus.Running);
config.setNodeStatusWithReason(originalStatus, originalStatusReason);
@@ -363,15 +367,18 @@ public class CommonConfigTest {
String originalStatusReason = config.getStatusReason();
try {
config.setNodeStatus(NodeStatus.Running);
- StringBuilder longMessage = new StringBuilder();
- for (int i = 0; i < 300; i++) {
- longMessage.append('x');
- }
- config.handleUnrecoverableError(new IOException(longMessage.toString()));
- String statusReason = config.getStatusReason();
- Assert.assertTrue(statusReason.endsWith("..."));
- Assert.assertTrue(
- statusReason.substring(statusReason.lastIndexOf(", ") + 2).length()
<= 256 + 3);
+ String prefix = "x".repeat(254);
+ String exactFit = prefix + " y";
+ config.handleUnrecoverableError(new IOException(prefix +
"\t".repeat(300) + "y \n"));
+ Assert.assertTrue(config.getStatusReason().endsWith(", " + exactFit));
+
+ config.setNodeStatus(NodeStatus.Running);
+ config.handleUnrecoverableError(new IOException(exactFit + "z"));
+ Assert.assertTrue(config.getStatusReason().endsWith(", " + exactFit +
"..."));
+
+ config.setNodeStatus(NodeStatus.Running);
+ config.handleUnrecoverableError(new IOException(prefix +
"x\uD83D\uDE00"));
+ Assert.assertTrue(config.getStatusReason().endsWith(", " + prefix +
"x..."));
} finally {
config.setNodeStatus(NodeStatus.Running);
config.setNodeStatusWithReason(originalStatus, originalStatusReason);