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

haonan 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 adb1cbc  [IOTDB-1562] Fix incorrect exception processing in 
insertXXX() API (#3758)
adb1cbc is described below

commit adb1cbc4878fed6a061b461d0e5c55256de6cc61
Author: ShuanglinWu <[email protected]>
AuthorDate: Sun Sep 5 21:06:05 2021 +0800

    [IOTDB-1562] Fix incorrect exception processing in insertXXX() API (#3758)
---
 RELEASE_NOTES.md                                   |   2 +-
 .../java/org/apache/iotdb/db/conf/IoTDBConfig.java |   8 +-
 .../org/apache/iotdb/db/conf/OperationType.java    |  65 +++++
 .../org/apache/iotdb/db/service/TSServiceImpl.java | 146 ++++++++---
 .../aggregation/IoTDBAggregationSmallDataIT.java   |  17 +-
 .../apache/iotdb/session/IoTDBSessionSimpleIT.java | 284 ++++++++++++++++++++-
 .../.vuepress/public/img/contributor-avatar/cw.jpg | Bin 163226 -> 163225 bytes
 7 files changed, 472 insertions(+), 50 deletions(-)

diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index df16fb9..f9ac43e 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -718,4 +718,4 @@ If you use the previous unofficial version 0.7.0. It is 
incompatible with 0.8.0.
 * Import/export csv script bug
 * Log level and stack print in test
 * Bug in TsFile-Spark-Connector
-* A doc bug of QuickStart.md
\ No newline at end of file
+* A doc bug of QuickStart.md
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java 
b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index adff0c2..2e5de0a 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -803,14 +803,14 @@ public class IoTDBConfig {
     this.udfInitialByteArrayLengthForMemoryControl = 
udfInitialByteArrayLengthForMemoryControl;
   }
 
-  public int getConcurrentWritingTimePartition() {
-    return concurrentWritingTimePartition;
-  }
-
   void setConcurrentWritingTimePartition(int concurrentWritingTimePartition) {
     this.concurrentWritingTimePartition = concurrentWritingTimePartition;
   }
 
+  public int getConcurrentWritingTimePartition() {
+    return concurrentWritingTimePartition;
+  }
+
   public int getDefaultFillInterval() {
     return defaultFillInterval;
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/OperationType.java 
b/server/src/main/java/org/apache/iotdb/db/conf/OperationType.java
new file mode 100644
index 0000000..bcf6b24
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/conf/OperationType.java
@@ -0,0 +1,65 @@
+/*
+ * 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.conf;
+
+public enum OperationType {
+  CLOSE_OPERATION("closeOperation"),
+  FETCH_METADATA("fetchMetadata"),
+  EXECUTE_STATEMENT("executeStatement"),
+  EXECUTE_BATCH_STATEMENT("executeBatchStatement"),
+  EXECUTE_QUERY_STATEMENT("executeQueryStatement"),
+  EXECUTE_RAW_DATA_QUERY("executeRawDataQuery"),
+  EXECUTE_LAST_DATA_QUERY("lastDataQueryReqToPhysicalPlan"),
+  FETCH_RESULTS("fetchResults"),
+  EXECUTE_UPDATE_STATEMENT("executeUpdateStatement"),
+  GET_TIME_ZONE("getTimeZone"),
+  SET_TIME_ZONE("setTimeZone"),
+  INSERT_RECORDS("insertRecords"),
+  INSERT_RECORDS_OF_ONE_DEVICE("insertRecordsOfOneDevice"),
+  INSERT_STRING_RECORDS("insertStringRecords"),
+  INSERT_RECORD("insertRecord"),
+  INSERT_STRING_RECORD("insertStringRecord"),
+  DELETE_DATA("deleteData"),
+  INSERT_TABLET("insertTablet"),
+  INSERT_TABLETS("insertTablets"),
+  SET_STORAGE_GROUP("setStorageGroup"),
+  DELETE_STORAGE_GROUPS("deleteStorageGroup"),
+  CREATE_TIMESERIES("createTimeseries"),
+  CREATE_ALIGNED_TIMESERIES("createAlignedTimeseries"),
+  CREATE_MULTI_TIMESERIES("createMultiTimeseries"),
+  DELETE_TIMESERIES("deleteTimeseries"),
+  CREATE_SCHEMA_TEMPLATE("createSchemaTemplate"),
+  CHECK_AUTHORITY("checkAuthority"),
+  EXECUTE_NON_QUERY_PLAN("executeNonQueryPlan"),
+  ;
+  private final String name;
+
+  OperationType(String name) {
+    this.name = name;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  @Override
+  public String toString() {
+    return name;
+  }
+}
diff --git 
a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java 
b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 4ad3bd1..6f6e25c 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -25,6 +25,7 @@ import org.apache.iotdb.db.auth.authorizer.IAuthorizer;
 import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBConstant;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.conf.OperationType;
 import org.apache.iotdb.db.cost.statistic.Measurement;
 import org.apache.iotdb.db.cost.statistic.Operation;
 import org.apache.iotdb.db.engine.selectinto.InsertTabletPlansIterator;
@@ -325,7 +326,7 @@ public class TSServiceImpl implements TSIService.Iface {
       }
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "executing closeOperation", TSStatusCode.CLOSE_OPERATION_ERROR);
+          e, OperationType.CLOSE_OPERATION, 
TSStatusCode.CLOSE_OPERATION_ERROR);
     }
   }
 
@@ -371,7 +372,7 @@ public class TSServiceImpl implements TSIService.Iface {
     } catch (Exception e) {
       status =
           onNPEOrUnexpectedException(
-              e, "executing fetchMetadata", 
TSStatusCode.INTERNAL_SERVER_ERROR);
+              e, OperationType.FETCH_METADATA, 
TSStatusCode.INTERNAL_SERVER_ERROR);
     }
     return resp.setStatus(status);
   }
@@ -575,7 +576,9 @@ public class TSServiceImpl implements TSIService.Iface {
         } else {
           result.add(
               onNPEOrUnexpectedException(
-                  e, "executing " + statement, 
TSStatusCode.INTERNAL_SERVER_ERROR));
+                  e,
+                  "\"" + statement + "\". " + 
OperationType.EXECUTE_BATCH_STATEMENT,
+                  TSStatusCode.INTERNAL_SERVER_ERROR));
         }
       }
     }
@@ -617,10 +620,10 @@ public class TSServiceImpl implements TSIService.Iface {
       LOGGER.error(INFO_INTERRUPT_ERROR, req, e);
       Thread.currentThread().interrupt();
       return RpcUtils.getTSExecuteStatementResp(
-          onQueryException(e, "executing \"" + statement + "\""));
+          onQueryException(e, "\"" + statement + "\". " + 
OperationType.EXECUTE_STATEMENT));
     } catch (Exception e) {
       return RpcUtils.getTSExecuteStatementResp(
-          onQueryException(e, "executing \"" + statement + "\""));
+          onQueryException(e, "\"" + statement + "\". " + 
OperationType.EXECUTE_STATEMENT));
     }
   }
 
@@ -651,10 +654,12 @@ public class TSServiceImpl implements TSIService.Iface {
       LOGGER.error(INFO_INTERRUPT_ERROR, req, e);
       Thread.currentThread().interrupt();
       return RpcUtils.getTSExecuteStatementResp(
-          onQueryException(e, "executing executeQueryStatement"));
+          onQueryException(
+              e, "\"" + req.getStatement() + "\". " + 
OperationType.EXECUTE_QUERY_STATEMENT));
     } catch (Exception e) {
       return RpcUtils.getTSExecuteStatementResp(
-          onQueryException(e, "executing executeQueryStatement"));
+          onQueryException(
+              e, "\"" + req.getStatement() + "\". " + 
OperationType.EXECUTE_QUERY_STATEMENT));
     }
   }
 
@@ -683,10 +688,10 @@ public class TSServiceImpl implements TSIService.Iface {
       LOGGER.error(INFO_INTERRUPT_ERROR, req, e);
       Thread.currentThread().interrupt();
       return RpcUtils.getTSExecuteStatementResp(
-          onQueryException(e, "executing executeRawDataQuery"));
+          onQueryException(e, OperationType.EXECUTE_RAW_DATA_QUERY));
     } catch (Exception e) {
       return RpcUtils.getTSExecuteStatementResp(
-          onQueryException(e, "executing executeRawDataQuery"));
+          onQueryException(e, OperationType.EXECUTE_RAW_DATA_QUERY));
     }
   }
 
@@ -715,10 +720,10 @@ public class TSServiceImpl implements TSIService.Iface {
       LOGGER.error(INFO_INTERRUPT_ERROR, req, e);
       Thread.currentThread().interrupt();
       return RpcUtils.getTSExecuteStatementResp(
-          onQueryException(e, "executing lastDataQueryReqToPhysicalPlan"));
+          onQueryException(e, OperationType.EXECUTE_LAST_DATA_QUERY));
     } catch (Exception e) {
       return RpcUtils.getTSExecuteStatementResp(
-          onQueryException(e, "executing lastDataQueryReqToPhysicalPlan"));
+          onQueryException(e, OperationType.EXECUTE_LAST_DATA_QUERY));
     }
   }
 
@@ -1150,12 +1155,12 @@ public class TSServiceImpl implements TSIService.Iface {
       Thread.currentThread().interrupt();
       return RpcUtils.getTSFetchResultsResp(
           onNPEOrUnexpectedException(
-              e, "executing fetchResults", 
TSStatusCode.INTERNAL_SERVER_ERROR));
+              e, OperationType.FETCH_RESULTS, 
TSStatusCode.INTERNAL_SERVER_ERROR));
     } catch (Exception e) {
       sessionManager.releaseQueryResourceNoExceptions(req.queryId);
       return RpcUtils.getTSFetchResultsResp(
           onNPEOrUnexpectedException(
-              e, "executing fetchResults", 
TSStatusCode.INTERNAL_SERVER_ERROR));
+              e, OperationType.FETCH_RESULTS, 
TSStatusCode.INTERNAL_SERVER_ERROR));
     }
   }
 
@@ -1235,9 +1240,13 @@ public class TSServiceImpl implements TSIService.Iface {
     } catch (InterruptedException e) {
       LOGGER.error(INFO_INTERRUPT_ERROR, req, e);
       Thread.currentThread().interrupt();
-      return RpcUtils.getTSExecuteStatementResp(onQueryException(e, "executing 
update statement"));
+      return RpcUtils.getTSExecuteStatementResp(
+          onQueryException(
+              e, "\"" + req.statement + "\". " + 
OperationType.EXECUTE_UPDATE_STATEMENT));
     } catch (Exception e) {
-      return RpcUtils.getTSExecuteStatementResp(onQueryException(e, "executing 
update statement"));
+      return RpcUtils.getTSExecuteStatementResp(
+          onQueryException(
+              e, "\"" + req.statement + "\". " + 
OperationType.EXECUTE_UPDATE_STATEMENT));
     }
   }
 
@@ -1306,7 +1315,7 @@ public class TSServiceImpl implements TSIService.Iface {
     } catch (Exception e) {
       return new TSGetTimeZoneResp(
           onNPEOrUnexpectedException(
-              e, "generating time zone", 
TSStatusCode.GENERATE_TIME_ZONE_ERROR),
+              e, OperationType.GET_TIME_ZONE, 
TSStatusCode.GENERATE_TIME_ZONE_ERROR),
           "Unknown time zone");
     }
   }
@@ -1317,7 +1326,8 @@ public class TSServiceImpl implements TSIService.Iface {
       sessionManager.setTimezone(req.sessionId, req.timeZone);
       return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS);
     } catch (Exception e) {
-      return onNPEOrUnexpectedException(e, "setting time zone", 
TSStatusCode.SET_TIME_ZONE_ERROR);
+      return onNPEOrUnexpectedException(
+          e, OperationType.SET_TIME_ZONE, TSStatusCode.SET_TIME_ZONE_ERROR);
     }
   }
 
@@ -1376,6 +1386,11 @@ public class TSServiceImpl implements TSIService.Iface {
           allCheckSuccess = false;
         }
         insertRowsPlan.addOneInsertRowPlan(plan, i);
+      } catch (IoTDBException e) {
+        allCheckSuccess = false;
+        insertRowsPlan
+            .getResults()
+            .put(i, onIoTDBException(e, OperationType.INSERT_RECORDS, 
e.getErrorCode()));
       } catch (Exception e) {
         allCheckSuccess = false;
         insertRowsPlan
@@ -1383,7 +1398,7 @@ public class TSServiceImpl implements TSIService.Iface {
             .put(
                 i,
                 onNPEOrUnexpectedException(
-                    e, "inserting records", 
TSStatusCode.INTERNAL_SERVER_ERROR));
+                    e, OperationType.INSERT_RECORDS, 
TSStatusCode.INTERNAL_SERVER_ERROR));
       }
     }
     TSStatus tsStatus = executeNonQueryPlan(insertRowsPlan);
@@ -1437,10 +1452,13 @@ public class TSServiceImpl implements TSIService.Iface {
               req.getValuesList().toArray(new ByteBuffer[0]));
       TSStatus status = checkAuthority(plan, req.getSessionId());
       statusList.add(status != null ? status : executeNonQueryPlan(plan));
+    } catch (IoTDBException e) {
+      statusList.add(
+          onIoTDBException(e, OperationType.INSERT_RECORDS_OF_ONE_DEVICE, 
e.getErrorCode()));
     } catch (Exception e) {
       statusList.add(
           onNPEOrUnexpectedException(
-              e, "inserting records of one device", 
TSStatusCode.INTERNAL_SERVER_ERROR));
+              e, OperationType.INSERT_RECORDS_OF_ONE_DEVICE, 
TSStatusCode.INTERNAL_SERVER_ERROR));
     }
 
     TSStatus resp = RpcUtils.getStatus(statusList);
@@ -1485,13 +1503,18 @@ public class TSServiceImpl implements TSIService.Iface {
           allCheckSuccess = false;
         }
         insertRowsPlan.addOneInsertRowPlan(plan, i);
+      } catch (IoTDBException e) {
+        insertRowsPlan
+            .getResults()
+            .put(i, onIoTDBException(e, OperationType.INSERT_STRING_RECORDS, 
e.getErrorCode()));
+        allCheckSuccess = false;
       } catch (Exception e) {
         insertRowsPlan
             .getResults()
             .put(
                 i,
                 onNPEOrUnexpectedException(
-                    e, "inserting string records", 
TSStatusCode.INTERNAL_SERVER_ERROR));
+                    e, OperationType.INSERT_STRING_RECORDS, 
TSStatusCode.INTERNAL_SERVER_ERROR));
         allCheckSuccess = false;
       }
     }
@@ -1584,9 +1607,11 @@ public class TSServiceImpl implements TSIService.Iface {
 
       TSStatus status = checkAuthority(plan, req.getSessionId());
       return status != null ? status : executeNonQueryPlan(plan);
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.INSERT_RECORD, 
e.getErrorCode());
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "inserting a record", TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.INSERT_RECORD, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
   }
 
@@ -1613,9 +1638,11 @@ public class TSServiceImpl implements TSIService.Iface {
 
       TSStatus status = checkAuthority(plan, req.getSessionId());
       return status != null ? status : executeNonQueryPlan(plan);
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.INSERT_STRING_RECORD, 
e.getErrorCode());
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "inserting a string record", 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.INSERT_STRING_RECORD, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
   }
 
@@ -1637,8 +1664,11 @@ public class TSServiceImpl implements TSIService.Iface {
 
       TSStatus status = checkAuthority(plan, req.getSessionId());
       return status != null ? new TSStatus(status) : new 
TSStatus(executeNonQueryPlan(plan));
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.DELETE_DATA, e.getErrorCode());
     } catch (Exception e) {
-      return onNPEOrUnexpectedException(e, "deleting data", 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
+      return onNPEOrUnexpectedException(
+          e, OperationType.DELETE_DATA, TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
   }
 
@@ -1664,9 +1694,11 @@ public class TSServiceImpl implements TSIService.Iface {
 
       TSStatus status = checkAuthority(insertTabletPlan, req.getSessionId());
       return status != null ? status : executeNonQueryPlan(insertTabletPlan);
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.INSERT_TABLET, 
e.getErrorCode());
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "inserting tablet", TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.INSERT_TABLET, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     } finally {
       
Measurement.INSTANCE.addOperationLatency(Operation.EXECUTE_RPC_BATCH_INSERT, 
t1);
     }
@@ -1681,12 +1713,14 @@ public class TSServiceImpl implements TSIService.Iface {
       }
 
       return insertTabletsInternally(req);
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.INSERT_TABLETS, 
e.getErrorCode());
     } catch (NullPointerException e) {
       LOGGER.error("{}: error occurs when insertTablets", 
IoTDBConstant.GLOBAL_DB_NAME, e);
       return RpcUtils.getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR);
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "inserting tablets", TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.INSERT_TABLETS, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     } finally {
       
Measurement.INSTANCE.addOperationLatency(Operation.EXECUTE_RPC_BATCH_INSERT, 
t1);
     }
@@ -1741,9 +1775,11 @@ public class TSServiceImpl implements TSIService.Iface {
 
       TSStatus status = checkAuthority(plan, sessionId);
       return status != null ? status : executeNonQueryPlan(plan);
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.SET_STORAGE_GROUP, 
e.getErrorCode());
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "setting storage group", TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.SET_STORAGE_GROUP, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
   }
 
@@ -1762,9 +1798,11 @@ public class TSServiceImpl implements TSIService.Iface {
 
       TSStatus status = checkAuthority(plan, sessionId);
       return status != null ? status : executeNonQueryPlan(plan);
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.DELETE_STORAGE_GROUPS, 
e.getErrorCode());
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "deleting storage group", TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.DELETE_STORAGE_GROUPS, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
   }
 
@@ -1793,9 +1831,11 @@ public class TSServiceImpl implements TSIService.Iface {
 
       TSStatus status = checkAuthority(plan, req.getSessionId());
       return status != null ? status : executeNonQueryPlan(plan);
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.CREATE_TIMESERIES, 
e.getErrorCode());
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "creating timeseries", TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.CREATE_TIMESERIES, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
   }
 
@@ -1845,9 +1885,11 @@ public class TSServiceImpl implements TSIService.Iface {
 
       TSStatus status = checkAuthority(plan, req.getSessionId());
       return status != null ? status : executeNonQueryPlan(plan);
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.CREATE_ALIGNED_TIMESERIES, 
e.getErrorCode());
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "creating aligned timeseries", 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.CREATE_ALIGNED_TIMESERIES, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
   }
 
@@ -1931,10 +1973,12 @@ public class TSServiceImpl implements TSIService.Iface {
       multiPlan.setIndexes(new ArrayList<>());
 
       return executeNonQueryPlan(multiPlan);
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.CREATE_MULTI_TIMESERIES, 
e.getErrorCode());
     } catch (Exception e) {
       LOGGER.error("creating multi timeseries fails", e);
       return onNPEOrUnexpectedException(
-          e, "creating multi timeseries", 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.CREATE_MULTI_TIMESERIES, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
   }
 
@@ -1953,9 +1997,11 @@ public class TSServiceImpl implements TSIService.Iface {
 
       TSStatus status = checkAuthority(plan, sessionId);
       return status != null ? status : executeNonQueryPlan(plan);
+    } catch (IoTDBException e) {
+      return onIoTDBException(e, OperationType.DELETE_TIMESERIES, 
e.getErrorCode());
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "deleting timeseries", TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.DELETE_TIMESERIES, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
   }
 
@@ -2019,7 +2065,7 @@ public class TSServiceImpl implements TSIService.Iface {
       return status != null ? status : executeNonQueryPlan(plan);
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "creating aligned timeseries", 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.CREATE_SCHEMA_TEMPLATE, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
   }
 
@@ -2056,7 +2102,7 @@ public class TSServiceImpl implements TSIService.Iface {
       return RpcUtils.getStatus(TSStatusCode.UNINITIALIZED_AUTH_ERROR, 
e.getMessage());
     } catch (Exception e) {
       return onNPEOrUnexpectedException(
-          e, "checking authority", TSStatusCode.EXECUTE_STATEMENT_ERROR);
+          e, OperationType.CHECK_AUTHORITY, 
TSStatusCode.EXECUTE_STATEMENT_ERROR);
     }
     return null;
   }
@@ -2067,7 +2113,7 @@ public class TSServiceImpl implements TSIService.Iface {
       plan.checkIntegrity();
       isSuccessful = executeNonQuery(plan);
     } catch (Exception e) {
-      return onNonQueryException(e, "executing non query plan");
+      return onNonQueryException(e, OperationType.EXECUTE_NON_QUERY_PLAN);
     }
 
     return isSuccessful
@@ -2097,6 +2143,10 @@ public class TSServiceImpl implements TSIService.Iface {
         : onNPEOrUnexpectedException(e, operation, 
TSStatusCode.INTERNAL_SERVER_ERROR);
   }
 
+  private TSStatus onQueryException(Exception e, OperationType operation) {
+    return onQueryException(e, operation.getName());
+  }
+
   private TSStatus tryCatchQueryException(Exception e) {
     if (e instanceof QueryTimeoutRuntimeException) {
       DETAILED_FAILURE_QUERY_TRACE_LOGGER.warn(e.getMessage(), e);
@@ -2131,6 +2181,10 @@ public class TSServiceImpl implements TSIService.Iface {
         : onNPEOrUnexpectedException(e, operation, 
TSStatusCode.INTERNAL_SERVER_ERROR);
   }
 
+  private TSStatus onNonQueryException(Exception e, OperationType operation) {
+    return onNonQueryException(e, operation.getName());
+  }
+
   private TSStatus tryCatchNonQueryException(Exception e) {
     String message = "Exception occurred while processing non-query. ";
     if (e instanceof BatchProcessException) {
@@ -2150,7 +2204,7 @@ public class TSServiceImpl implements TSIService.Iface {
   private TSStatus onNPEOrUnexpectedException(
       Exception e, String operation, TSStatusCode statusCode) {
     String message =
-        String.format("[%s] Exception occurred while %s. ", statusCode.name(), 
operation);
+        String.format("[%s] Exception occurred: %s failed. ", 
statusCode.name(), operation);
     if (e instanceof NullPointerException) {
       LOGGER.error("Status code: {}, MSG: {}", statusCode, message, e);
     } else if (e instanceof UnSupportedDataTypeException) {
@@ -2161,6 +2215,28 @@ public class TSServiceImpl implements TSIService.Iface {
     return RpcUtils.getStatus(statusCode, message + e.getMessage());
   }
 
+  private TSStatus onNPEOrUnexpectedException(
+      Exception e, OperationType operation, TSStatusCode statusCode) {
+    return onNPEOrUnexpectedException(e, operation.getName(), statusCode);
+  }
+
+  private TSStatus onIoTDBException(Exception e, String operation, int 
errorCode) {
+    String errorName = "IOTDBException";
+    for (TSStatusCode value : TSStatusCode.values()) {
+      if (value.getStatusCode() == errorCode) {
+        errorName = value.name();
+        break;
+      }
+    }
+    String message = String.format("[%s] Exception occurred: %s failed. ", 
errorName, operation);
+    LOGGER.warn("Status code: {}, MSG: {}", errorName, message, e);
+    return RpcUtils.getStatus(errorCode, message + e.getMessage());
+  }
+
+  private TSStatus onIoTDBException(Exception e, OperationType operation, int 
errorCode) {
+    return onIoTDBException(e, operation.getName(), errorCode);
+  }
+
   private TSStatus getNotLoggedInStatus() {
     return RpcUtils.getStatus(
         TSStatusCode.NOT_LOGIN_ERROR,
diff --git 
a/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java
 
b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java
index 07a3813..d2082d0 100644
--- 
a/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java
+++ 
b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java
@@ -20,6 +20,7 @@
 package org.apache.iotdb.db.integration.aggregation;
 
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.conf.OperationType;
 import org.apache.iotdb.db.engine.compaction.CompactionStrategy;
 import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.jdbc.Config;
@@ -228,9 +229,11 @@ public class IoTDBAggregationSmallDataIT {
         Assert.assertTrue(
             e.toString()
                 .contains(
-                    "500: [INTERNAL_SERVER_ERROR] Exception occurred while 
executing "
-                        + "\"SELECT 
max_value(d0.s0),max_value(d1.s1),max_value(d0.s3) "
-                        + "FROM root.vehicle\". Binary statistics does not 
support: max"));
+                    String.format(
+                        "500: [INTERNAL_SERVER_ERROR] Exception occurred: "
+                            + "\"SELECT 
max_value(d0.s0),max_value(d1.s1),max_value(d0.s3) "
+                            + "FROM root.vehicle\". %s failed. Binary 
statistics does not support: max",
+                        OperationType.EXECUTE_STATEMENT.getName())));
       }
 
       boolean hasResultSet =
@@ -272,9 +275,11 @@ public class IoTDBAggregationSmallDataIT {
         Assert.assertTrue(
             e.toString()
                 .contains(
-                    "500: [INTERNAL_SERVER_ERROR] Exception occurred while 
executing "
-                        + "\"SELECT 
extreme(d0.s0),extreme(d1.s1),extreme(d0.s3) "
-                        + "FROM root.vehicle\". Binary statistics does not 
support: max"));
+                    String.format(
+                        "500: [INTERNAL_SERVER_ERROR] Exception occurred: "
+                            + "\"SELECT 
extreme(d0.s0),extreme(d1.s1),extreme(d0.s3) "
+                            + "FROM root.vehicle\". %s failed. Binary 
statistics does not support: max",
+                        OperationType.EXECUTE_STATEMENT.getName())));
       }
 
       boolean hasResultSet =
diff --git 
a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java 
b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
index c8e098f..2dd9230 100644
--- a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
+++ b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
@@ -20,6 +20,7 @@ package org.apache.iotdb.session;
 
 import org.apache.iotdb.db.conf.IoTDBConstant;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.conf.OperationType;
 import org.apache.iotdb.db.exception.metadata.MetadataException;
 import org.apache.iotdb.db.metadata.MManager;
 import org.apache.iotdb.db.metadata.PartialPath;
@@ -28,6 +29,7 @@ import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.rpc.BatchExecutionException;
 import org.apache.iotdb.rpc.IoTDBConnectionException;
 import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
 import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
 import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
@@ -56,10 +58,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 public class IoTDBSessionSimpleIT {
 
@@ -726,6 +725,283 @@ public class IoTDBSessionSimpleIT {
     session.close();
   }
 
+  @Test
+  public void testInsertIlligalPath() throws IoTDBConnectionException {
+    session = new Session("127.0.0.1", 6667, "root", "root");
+    session.open();
+
+    String msg = "[%s] Exception occurred: %s failed. %s is not a legal path";
+    String deviceId = "root.sg..d1";
+    List<String> deviceIds = Arrays.asList("root.sg..d1", "root.sg.d2");
+    List<Long> timestamps = Arrays.asList(1L, 1L);
+    List<String> measurements = Arrays.asList("s1", "s2", "s3");
+    List<List<String>> allMeasurements = Arrays.asList(measurements, 
measurements);
+    List<TSDataType> tsDataTypes =
+        Arrays.asList(TSDataType.INT32, TSDataType.FLOAT, TSDataType.TEXT);
+    List<List<TSDataType>> allTsDataTypes = Arrays.asList(tsDataTypes, 
tsDataTypes);
+    List<TSEncoding> tsEncodings =
+        Arrays.asList(TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN);
+    List<CompressionType> compressionTypes =
+        Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY, 
CompressionType.SNAPPY);
+    List<Object> values = Arrays.asList(1, 2f, "3");
+    List<List<Object>> allValues = Arrays.asList(values, values);
+    List<String> stringValues = Arrays.asList("1", "2", "3");
+    List<List<String>> allstringValues = Arrays.asList(stringValues, 
stringValues);
+
+    try {
+      session.insertRecords(deviceIds, timestamps, allMeasurements, 
allTsDataTypes, allValues);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg, TSStatusCode.PATH_ILLEGAL, 
OperationType.INSERT_RECORDS, deviceId)));
+    }
+
+    try {
+      session.insertRecords(deviceIds, Arrays.asList(2L, 2L), allMeasurements, 
allstringValues);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg,
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.INSERT_STRING_RECORDS,
+                      deviceIds.get(0))));
+    }
+
+    try {
+      session.insertRecord(deviceId, 3L, measurements, tsDataTypes, values);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg, TSStatusCode.PATH_ILLEGAL, 
OperationType.INSERT_RECORD, deviceId)));
+    }
+
+    try {
+      session.insertRecord(deviceId, 4L, measurements, stringValues);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg,
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.INSERT_STRING_RECORD,
+                      deviceId)));
+    }
+
+    try {
+      session.insertRecordsOfOneDevice(
+          deviceId, Arrays.asList(5L, 6L), allMeasurements, allTsDataTypes, 
allValues);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg,
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.INSERT_RECORDS_OF_ONE_DEVICE,
+                      deviceId)));
+    }
+
+    try {
+      session.deleteData(deviceId + ".s1", 6L);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg,
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.DELETE_DATA,
+                      deviceId + ".s1")));
+    }
+
+    try {
+      Tablet tablet =
+          new Tablet(
+              deviceId,
+              Arrays.asList(
+                  new MeasurementSchema("s1", TSDataType.INT32),
+                  new MeasurementSchema("s2", TSDataType.FLOAT)),
+              5);
+      long ts = 7L;
+      for (long row = 0; row < 8; row++) {
+        int rowIndex = tablet.rowSize++;
+        tablet.addTimestamp(rowIndex, ts);
+        tablet.addValue("s1", rowIndex, 1);
+        tablet.addValue("s2", rowIndex, 1.0F);
+        if (tablet.rowSize == tablet.getMaxRowNumber()) {
+          session.insertTablet(tablet, true);
+          tablet.reset();
+        }
+        ts++;
+      }
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg, TSStatusCode.PATH_ILLEGAL, 
OperationType.INSERT_TABLET, deviceId)));
+    }
+
+    try {
+      Tablet tablet1 =
+          new Tablet(
+              deviceId,
+              Arrays.asList(
+                  new MeasurementSchema("s1", TSDataType.INT32),
+                  new MeasurementSchema("s2", TSDataType.FLOAT)),
+              5);
+      Tablet tablet2 =
+          new Tablet(
+              "root.sg.d2",
+              Arrays.asList(
+                  new MeasurementSchema("s1", TSDataType.INT32),
+                  new MeasurementSchema("s2", TSDataType.FLOAT)),
+              5);
+      HashMap<String, Tablet> tablets = new HashMap<>();
+      tablets.put(deviceId, tablet1);
+      tablets.put("root.sg.d2", tablet2);
+      long ts = 16L;
+      for (long row = 0; row < 8; row++) {
+        int row1 = tablet1.rowSize++;
+        int row2 = tablet2.rowSize++;
+        tablet1.addTimestamp(row1, ts);
+        tablet2.addTimestamp(row2, ts);
+        tablet1.addValue("s1", row1, 1);
+        tablet1.addValue("s2", row1, 1.0F);
+        tablet2.addValue("s1", row2, 1);
+        tablet2.addValue("s2", row2, 1.0F);
+        if (tablet1.rowSize == tablet1.getMaxRowNumber()) {
+          session.insertTablets(tablets, true);
+          tablet1.reset();
+          tablet2.reset();
+        }
+        ts++;
+      }
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg, TSStatusCode.PATH_ILLEGAL, 
OperationType.INSERT_TABLETS, deviceId)));
+    }
+
+    try {
+      session.setStorageGroup("root..sg");
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg,
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.SET_STORAGE_GROUP,
+                      "root..sg")));
+    }
+
+    try {
+      session.createTimeseries(
+          "root.sg..d1.s1", TSDataType.INT32, TSEncoding.PLAIN, 
CompressionType.SNAPPY);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg,
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.CREATE_TIMESERIES,
+                      "root.sg..d1.s1")));
+    }
+
+    try {
+      session.createAlignedTimeseries(
+          deviceId,
+          measurements,
+          tsDataTypes,
+          tsEncodings,
+          CompressionType.SNAPPY,
+          Arrays.asList("alias1", "alias2", "alias3"));
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg,
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.CREATE_ALIGNED_TIMESERIES,
+                      deviceId)));
+    }
+
+    try {
+      session.createMultiTimeseries(
+          Arrays.asList("root.sg.d1..s1", "root.sg.d1.s2", "root.sg.d1.s3"),
+          tsDataTypes,
+          tsEncodings,
+          compressionTypes,
+          null,
+          null,
+          null,
+          null);
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg,
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.CREATE_MULTI_TIMESERIES,
+                      "root.sg.d1..s1")));
+    }
+
+    try {
+      session.deleteTimeseries("root.sg.d1..s1");
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg,
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.DELETE_TIMESERIES,
+                      "root.sg.d1..s1")));
+    }
+
+    try {
+      session.deleteStorageGroup("root..sg");
+      fail("Exception expected");
+    } catch (StatementExecutionException e) {
+      assertTrue(
+          e.getMessage()
+              .contains(
+                  String.format(
+                      msg,
+                      TSStatusCode.PATH_ILLEGAL,
+                      OperationType.DELETE_STORAGE_GROUPS,
+                      "root..sg")));
+    }
+
+    session.close();
+  }
+
   private void checkResult(Session session)
       throws StatementExecutionException, IoTDBConnectionException {
     SessionDataSet dataSet = session.executeQueryStatement("select * from 
root.sg.d1");
diff --git a/site/src/main/.vuepress/public/img/contributor-avatar/cw.jpg 
b/site/src/main/.vuepress/public/img/contributor-avatar/cw.jpg
index b8f6c53..f87ed70 100644
Binary files a/site/src/main/.vuepress/public/img/contributor-avatar/cw.jpg and 
b/site/src/main/.vuepress/public/img/contributor-avatar/cw.jpg differ

Reply via email to