You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2022/11/16 15:04:07 UTC
[iotdb] branch master updated: [IOTDB-4948] Optimize out-of-ttl error message (#8013)
This is an automated email from the ASF dual-hosted git repository.
qiaojialin 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 b594531af6 [IOTDB-4948] Optimize out-of-ttl error message (#8013)
b594531af6 is described below
commit b594531af66f0c808b30da6fad795432e5e7f445
Author: Haonan <hh...@outlook.com>
AuthorDate: Wed Nov 16 23:03:58 2022 +0800
[IOTDB-4948] Optimize out-of-ttl error message (#8013)
---
.../java/org/apache/iotdb/db/it/IoTDBTtlIT.java | 7 +++--
.../statemachine/visitor/DataExecutionVisitor.java | 35 +++++++++++++++++-----
.../iotdb/db/engine/storagegroup/DataRegion.java | 14 ++++-----
.../db/exception/query/OutOfTTLException.java | 6 ++--
4 files changed, 40 insertions(+), 22 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBTtlIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBTtlIT.java
index 3cd84d6c4c..b96f4e24c6 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBTtlIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBTtlIT.java
@@ -23,6 +23,7 @@ package org.apache.iotdb.db.it;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.rpc.TSStatusCode;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -133,7 +134,7 @@ public class IoTDBTtlIT {
String.format(
"INSERT INTO root.TTL_SG1(timestamp, s1) VALUES (%d, %d)", now - 500000 + i, i));
} catch (SQLException e) {
- assertEquals(400, e.getErrorCode());
+ assertEquals(TSStatusCode.OUT_OF_TTL.getStatusCode(), e.getErrorCode());
}
}
@@ -221,7 +222,7 @@ public class IoTDBTtlIT {
"INSERT INTO root.sg.TTL_SG3(timestamp, s1) VALUES (%d, %d)",
now - 5000000 + i, i));
} catch (SQLException e) {
- assertEquals(400, e.getErrorCode());
+ assertEquals(TSStatusCode.OUT_OF_TTL.getStatusCode(), e.getErrorCode());
}
}
for (int i = 100; i < 200; i++) {
@@ -232,7 +233,7 @@ public class IoTDBTtlIT {
"INSERT INTO root.sg.TTL_SG4(timestamp, s1) VALUES (%d, %d)",
now - 5000000 + i, i));
} catch (SQLException e) {
- assertEquals(400, e.getErrorCode());
+ assertEquals(TSStatusCode.OUT_OF_TTL.getStatusCode(), e.getErrorCode());
}
}
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..bc7b8c15c5 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: {}, caused by {}", 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: {}, caused by {}", 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
old mode 100755
new mode 100644
index e265af1e13..f28627a720
--- 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,
- "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 d92edefa22..ed769e0c8d 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.getStatusCode(),
true);
}