You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/11/16 10:04:21 UTC
[iotdb] 01/02: [IOTDB-4948] Optimize out-of-ttl error message
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch IoTDB_4948
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit c6624dc55c428a04e3a27192d51d6b1380365b2e
Author: HTHou <hh...@outlook.com>
AuthorDate: Wed Nov 16 17:57:03 2022 +0800
[IOTDB-4948] Optimize out-of-ttl error message
---
.../statemachine/visitor/DataExecutionVisitor.java | 35 +++++++++++++++++-----
.../iotdb/db/engine/storagegroup/DataRegion.java | 14 ++++-----
.../db/exception/query/OutOfTTLException.java | 6 ++--
3 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/consensus/statemachine/visitor/DataExecutionVisitor.java b/server/src/main/java/org/apache/iotdb/db/consensus/statemachine/visitor/DataExecutionVisitor.java
index 63d5b62c2c..1146d3a527 100644
--- a/server/src/main/java/org/apache/iotdb/db/consensus/statemachine/visitor/DataExecutionVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/consensus/statemachine/visitor/DataExecutionVisitor.java
@@ -25,6 +25,7 @@ import org.apache.iotdb.db.engine.storagegroup.DataRegion;
import org.apache.iotdb.db.exception.BatchProcessException;
import org.apache.iotdb.db.exception.TriggerExecutionException;
import org.apache.iotdb.db.exception.WriteProcessException;
+import org.apache.iotdb.db.exception.query.OutOfTTLException;
import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanNode;
import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanVisitor;
import org.apache.iotdb.db.mpp.plan.planner.plan.node.write.DeleteDataNode;
@@ -33,6 +34,8 @@ import org.apache.iotdb.db.mpp.plan.planner.plan.node.write.InsertRowNode;
import org.apache.iotdb.db.mpp.plan.planner.plan.node.write.InsertRowsNode;
import org.apache.iotdb.db.mpp.plan.planner.plan.node.write.InsertRowsOfOneDeviceNode;
import org.apache.iotdb.db.mpp.plan.planner.plan.node.write.InsertTabletNode;
+import org.apache.iotdb.rpc.RpcUtils;
+import org.apache.iotdb.rpc.TSStatusCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,9 +56,12 @@ public class DataExecutionVisitor extends PlanVisitor<TSStatus, DataRegion> {
try {
dataRegion.insert(node);
return StatusUtils.OK;
+ } catch (OutOfTTLException e) {
+ LOGGER.warn("Error in executing plan node: {}", node, e.getMessage());
+ return RpcUtils.getStatus(e.getErrorCode(), e.getMessage());
} catch (WriteProcessException | TriggerExecutionException e) {
LOGGER.error("Error in executing plan node: {}", node, e);
- return StatusUtils.EXECUTE_STATEMENT_ERROR;
+ return RpcUtils.getStatus(e.getErrorCode(), e.getMessage());
}
}
@@ -64,9 +70,12 @@ public class DataExecutionVisitor extends PlanVisitor<TSStatus, DataRegion> {
try {
dataRegion.insertTablet(node);
return StatusUtils.OK;
+ } catch (OutOfTTLException e) {
+ LOGGER.warn("Error in executing plan node: {}", node, e.getMessage());
+ return RpcUtils.getStatus(e.getErrorCode(), e.getMessage());
} catch (TriggerExecutionException | WriteProcessException e) {
LOGGER.error("Error in executing plan node: {}", node, e);
- return StatusUtils.EXECUTE_STATEMENT_ERROR;
+ return RpcUtils.getStatus(e.getErrorCode(), e.getMessage());
} catch (BatchProcessException e) {
LOGGER.warn(
"Batch failure in executing a InsertTabletNode. device: {}, startTime: {}, measurements: {}, failing status: {}",
@@ -74,7 +83,7 @@ public class DataExecutionVisitor extends PlanVisitor<TSStatus, DataRegion> {
node.getTimes()[0],
node.getMeasurements(),
e.getFailingStatus());
- return StatusUtils.EXECUTE_STATEMENT_ERROR;
+ return StatusUtils.getStatus(TSStatusCode.representOf(e.getErrorCode()));
}
}
@@ -85,9 +94,13 @@ public class DataExecutionVisitor extends PlanVisitor<TSStatus, DataRegion> {
return StatusUtils.OK;
} catch (BatchProcessException e) {
LOGGER.warn("Batch failure in executing a InsertRowsNode.");
+ TSStatus firstStatus = null;
// for each error
for (Map.Entry<Integer, TSStatus> failedEntry : node.getResults().entrySet()) {
InsertRowNode insertRowNode = node.getInsertRowNodeList().get(failedEntry.getKey());
+ if (firstStatus == null) {
+ firstStatus = failedEntry.getValue();
+ }
LOGGER.warn(
"Insert row failed. device: {}, time: {}, measurements: {}, failing status: {}",
insertRowNode.getDevicePath(),
@@ -95,7 +108,7 @@ public class DataExecutionVisitor extends PlanVisitor<TSStatus, DataRegion> {
insertRowNode.getMeasurements(),
failedEntry.getValue());
}
- return StatusUtils.EXECUTE_STATEMENT_ERROR;
+ return firstStatus;
}
}
@@ -106,9 +119,13 @@ public class DataExecutionVisitor extends PlanVisitor<TSStatus, DataRegion> {
return StatusUtils.OK;
} catch (BatchProcessException e) {
LOGGER.warn("Batch failure in executing a InsertMultiTabletsNode.");
+ TSStatus firstStatus = null;
for (Map.Entry<Integer, TSStatus> failedEntry : node.getResults().entrySet()) {
InsertTabletNode insertTabletNode =
node.getInsertTabletNodeList().get(failedEntry.getKey());
+ if (firstStatus == null) {
+ firstStatus = failedEntry.getValue();
+ }
LOGGER.warn(
"Insert tablet failed. device: {}, startTime: {}, measurements: {}, failing status: {}",
insertTabletNode.getDevicePath(),
@@ -116,7 +133,7 @@ public class DataExecutionVisitor extends PlanVisitor<TSStatus, DataRegion> {
insertTabletNode.getMeasurements(),
failedEntry.getValue());
}
- return StatusUtils.EXECUTE_STATEMENT_ERROR;
+ return firstStatus;
}
}
@@ -128,11 +145,15 @@ public class DataExecutionVisitor extends PlanVisitor<TSStatus, DataRegion> {
return StatusUtils.OK;
} catch (WriteProcessException | TriggerExecutionException e) {
LOGGER.error("Error in executing plan node: {}", node, e);
- return StatusUtils.EXECUTE_STATEMENT_ERROR;
+ return RpcUtils.getStatus(e.getErrorCode(), e.getMessage());
} catch (BatchProcessException e) {
LOGGER.warn("Batch failure in executing a InsertRowsOfOneDeviceNode.");
+ TSStatus firstStatus = null;
for (Map.Entry<Integer, TSStatus> failedEntry : node.getResults().entrySet()) {
InsertRowNode insertRowNode = node.getInsertRowNodeList().get(failedEntry.getKey());
+ if (firstStatus == null) {
+ firstStatus = failedEntry.getValue();
+ }
LOGGER.warn(
"Insert row failed. device: {}, time: {}, measurements: {}, failing status: {}",
insertRowNode.getDevicePath(),
@@ -140,7 +161,7 @@ public class DataExecutionVisitor extends PlanVisitor<TSStatus, DataRegion> {
insertRowNode.getMeasurements(),
failedEntry.getValue());
}
- return StatusUtils.EXECUTE_STATEMENT_ERROR;
+ return firstStatus;
}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegion.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegion.java
index 06a0525455..23542ed75a 100755
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegion.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegion.java
@@ -911,12 +911,8 @@ public class DataRegion {
return;
}
- // fire trigger before insertion
- // TriggerEngine.fire(TriggerEvent.BEFORE_INSERT, insertRowNode);
// insert to sequence or unSequence file
insertToTsFileProcessor(insertRowNode, isSequence, timePartitionId);
- // fire trigger after insertion
- // TriggerEngine.fire(TriggerEvent.AFTER_INSERT, insertRowNode);
} finally {
writeUnlock();
}
@@ -950,7 +946,11 @@ public class DataRegion {
results[loc] =
RpcUtils.getStatus(
TSStatusCode.OUT_OF_TTL_ERROR,
- "time " + currTime + " in current line is out of TTL: " + dataTTL);
+ String.format(
+ "Insertion time [%s] is less than ttl time bound [%s]",
+ DateTimeUtils.convertMillsecondToZonedDateTime(currTime),
+ DateTimeUtils.convertMillsecondToZonedDateTime(
+ DateTimeUtils.currentTime() - dataTTL)));
loc++;
noFailure = false;
} else {
@@ -3108,8 +3108,6 @@ public class DataRegion {
return;
}
- // fire trigger before insertion
- // TriggerEngine.fire(TriggerEvent.BEFORE_INSERT, plan);
// insert to sequence or unSequence file
try {
insertToTsFileProcessor(insertRowNode, isSequence, timePartitionId);
@@ -3118,8 +3116,6 @@ public class DataRegion {
.getResults()
.put(i, RpcUtils.getStatus(e.getErrorCode(), e.getMessage()));
}
- // fire trigger before insertion
- // TriggerEngine.fire(TriggerEvent.AFTER_INSERT, plan);
}
} finally {
writeUnlock();
diff --git a/server/src/main/java/org/apache/iotdb/db/exception/query/OutOfTTLException.java b/server/src/main/java/org/apache/iotdb/db/exception/query/OutOfTTLException.java
index 748f6c06e6..226442cf26 100644
--- a/server/src/main/java/org/apache/iotdb/db/exception/query/OutOfTTLException.java
+++ b/server/src/main/java/org/apache/iotdb/db/exception/query/OutOfTTLException.java
@@ -21,10 +21,9 @@
package org.apache.iotdb.db.exception.query;
import org.apache.iotdb.db.exception.WriteProcessException;
+import org.apache.iotdb.db.qp.utils.DateTimeUtils;
import org.apache.iotdb.rpc.TSStatusCode;
-import java.util.Date;
-
public class OutOfTTLException extends WriteProcessException {
private static final long serialVersionUID = -1197147887094603300L;
@@ -33,7 +32,8 @@ public class OutOfTTLException extends WriteProcessException {
super(
String.format(
"Insertion time [%s] is less than ttl time bound [%s]",
- new Date(insertionTime), new Date(timeLowerBound)),
+ DateTimeUtils.convertMillsecondToZonedDateTime(insertionTime),
+ DateTimeUtils.convertMillsecondToZonedDateTime(timeLowerBound)),
TSStatusCode.OUT_OF_TTL_ERROR.getStatusCode(),
true);
}