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

rong pushed a commit to branch rc/1.3.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rc/1.3.3 by this push:
     new cc2764f7c71 Active Load: Refactoring the code for handling exception 
information after loading failure (#13880) (#13897)
cc2764f7c71 is described below

commit cc2764f7c718473a06319cb103ce182644e77094
Author: YC27 <[email protected]>
AuthorDate: Fri Oct 25 10:30:52 2024 +0800

    Active Load: Refactoring the code for handling exception information after 
loading failure (#13880) (#13897)
    
    (cherry picked from commit f61db4875e141704f2d7e5986f3c73f50f0e3527)
---
 .../active/ActiveLoadFailedMessageHandler.java     | 116 +++++++++++++++++++++
 .../load/active/ActiveLoadTsFileLoader.java        |  27 +----
 2 files changed, 119 insertions(+), 24 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadFailedMessageHandler.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadFailedMessageHandler.java
new file mode 100644
index 00000000000..be66e591d5d
--- /dev/null
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadFailedMessageHandler.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.storageengine.load.active;
+
+import org.apache.iotdb.commons.conf.CommonDescriptor;
+
+import org.apache.tsfile.utils.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ActiveLoadFailedMessageHandler {
+
+  private static final Logger LOGGER =
+      LoggerFactory.getLogger(ActiveLoadFailedMessageHandler.class);
+
+  private static final Map<String, ExceptionMessageHandler> 
EXCEPTION_MESSAGE_HANDLER_MAP =
+      Collections.unmodifiableMap(
+          new HashMap<String, ExceptionMessageHandler>() {
+            {
+              // system is memory constrains
+              put(
+                  "memory",
+                  filePair ->
+                      LOGGER.info(
+                          "Rejecting auto load tsfile {} (isGeneratedByPipe = 
{}) due to memory constraints, will retry later.",
+                          filePair.getLeft(),
+                          filePair.getRight()));
+              // system is read only
+              put(
+                  "read only",
+                  filePair ->
+                      LOGGER.info(
+                          "Rejecting auto load tsfile {} (isGeneratedByPipe = 
{}) due to the system is read only, will retry later.",
+                          filePair.getLeft(),
+                          filePair.getRight()));
+              // Timed out to wait for procedure return. The procedure is 
still running.
+              put(
+                  "procedure return",
+                  filePair ->
+                      LOGGER.info(
+                          "Rejecting auto load tsfile {} (isGeneratedByPipe = 
{}) due to time out to wait for procedure return, will retry later.",
+                          filePair.getLeft(),
+                          filePair.getRight()));
+              // DataNode is not enough, please register more.
+              put(
+                  "not enough",
+                  filePair ->
+                      LOGGER.info(
+                          "Rejecting auto load tsfile {} (isGeneratedByPipe = 
{}) due to the datanode is not enough, will retry later.",
+                          filePair.getLeft(),
+                          filePair.getRight()));
+              // Fail to connect to any config node. Please check status of 
ConfigNodes or logs of
+              // connected DataNode.
+              put(
+                  "any config node",
+                  filePair ->
+                      LOGGER.info(
+                          "Rejecting auto load tsfile {} (isGeneratedByPipe = 
{}) due to fail to connect to any config node, will retry later.",
+                          filePair.getLeft(),
+                          filePair.getRight()));
+              // Current query is time out, query start time is 1729653161797, 
ddl is
+              // -3046040214706, current time is 1729653184210, please check 
your statement or
+              // modify timeout parameter
+              put(
+                  "query is time out",
+                  filePair ->
+                      LOGGER.info(
+                          "Rejecting auto load tsfile {} (isGeneratedByPipe = 
{}) due to current query is time out, will retry later.",
+                          filePair.getLeft(),
+                          filePair.getRight()));
+            }
+          });
+
+  @FunctionalInterface
+  private interface ExceptionMessageHandler {
+    void handle(final Pair<String, Boolean> filePair);
+  }
+
+  public static boolean isExceptionMessageShouldRetry(
+      final Pair<String, Boolean> filePair, final String message) {
+    if (CommonDescriptor.getInstance().getConfig().isReadOnly()) {
+      EXCEPTION_MESSAGE_HANDLER_MAP.get("read only").handle(filePair);
+      return true;
+    }
+
+    for (String key : EXCEPTION_MESSAGE_HANDLER_MAP.keySet()) {
+      if (message != null && message.contains(key)) {
+        EXCEPTION_MESSAGE_HANDLER_MAP.get(key).handle(filePair);
+        return true;
+      }
+    }
+
+    return false;
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadTsFileLoader.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadTsFileLoader.java
index 731dba5652e..2ab0c1ae64e 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadTsFileLoader.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadTsFileLoader.java
@@ -211,18 +211,8 @@ public class ActiveLoadTsFileLoader {
   }
 
   private void handleLoadFailure(final Pair<String, Boolean> filePair, final 
TSStatus status) {
-    if (status.getMessage() != null && status.getMessage().contains("memory")) 
{
-      LOGGER.info(
-          "Rejecting auto load tsfile {} (isGeneratedByPipe = {}) due to 
memory constraints, will retry later.",
-          filePair.getLeft(),
-          filePair.getRight());
-    } else if (CommonDescriptor.getInstance().getConfig().isReadOnly()
-        || (status.getMessage() != null && status.getMessage().contains("read 
only"))) {
-      LOGGER.info(
-          "Rejecting auto load tsfile {} (isGeneratedByPipe = {}) due to the 
system is read only, will retry later.",
-          filePair.getLeft(),
-          filePair.getRight());
-    } else {
+    if (!ActiveLoadFailedMessageHandler.isExceptionMessageShouldRetry(
+        filePair, status.getMessage())) {
       LOGGER.warn(
           "Failed to auto load tsfile {} (isGeneratedByPipe = {}), status: {}. 
File will be moved to fail directory.",
           filePair.getLeft(),
@@ -241,18 +231,7 @@ public class ActiveLoadTsFileLoader {
   }
 
   private void handleOtherException(final Pair<String, Boolean> filePair, 
final Exception e) {
-    if (e.getMessage() != null && e.getMessage().contains("memory")) {
-      LOGGER.info(
-          "Rejecting auto load tsfile {} (isGeneratedByPipe = {}) due to 
memory constraints, will retry later.",
-          filePair.getLeft(),
-          filePair.getRight());
-    } else if (CommonDescriptor.getInstance().getConfig().isReadOnly()
-        || (e.getMessage() != null && e.getMessage().contains("read only"))) {
-      LOGGER.info(
-          "Rejecting auto load tsfile {} (isGeneratedByPipe = {}) due to the 
system is read only, will retry later.",
-          filePair.getLeft(),
-          filePair.getRight());
-    } else {
+    if 
(!ActiveLoadFailedMessageHandler.isExceptionMessageShouldRetry(filePair, 
e.getMessage())) {
       LOGGER.warn(
           "Failed to auto load tsfile {} (isGeneratedByPipe = {}) because of 
an unexpected exception. File will be moved to fail directory.",
           filePair.getLeft(),

Reply via email to