You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/06/23 14:09:41 UTC

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #1408: move getSeriesSchemas to MManager

qiaojialin commented on a change in pull request #1408:
URL: https://github.com/apache/incubator-iotdb/pull/1408#discussion_r444051474



##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
##########
@@ -1800,4 +1807,207 @@ private void checkMTreeModified() {
       }
     }
   }
+
+  /**
+   * get schema for device.
+   * Attention!!!  Only support insertPlan and insertTabletsPlan
+   * @param deviceId
+   * @param measurementList
+   * @param plan
+   * @return
+   * @throws MetadataException
+   */
+  public MeasurementSchema[] getSeriesSchemasAndLock(String deviceId, String[] measurementList, PhysicalPlan plan) throws MetadataException {
+    MeasurementSchema[] schemas = new MeasurementSchema[measurementList.length];
+
+    MNode deviceNode = null;
+    // 1. get device node
+    deviceNode = getDeviceNodeWithAutoCreateAndReadLock(deviceId);
+    // To reduce the String number in memory, set the deviceId from MManager to insertPlan
+    if (plan instanceof InsertPlan) {
+      ((InsertPlan) plan).setDeviceId(deviceNode.getFullPath());
+    } else if (plan instanceof InsertTabletPlan) {
+      ((InsertTabletPlan) plan).setDeviceId(deviceNode.getFullPath());
+    } else {
+      throw new MetadataException(String.format(
+        "Only support insert and insertTablets, deviceId[%s], plans [%s]", deviceId, plan.getOperatorType()));
+    }

Review comment:
       No need to set this, the insertplan will be gc soon

##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
##########
@@ -1800,4 +1807,207 @@ private void checkMTreeModified() {
       }
     }
   }
+
+  /**
+   * get schema for device.
+   * Attention!!!  Only support insertPlan and insertTabletsPlan
+   * @param deviceId
+   * @param measurementList
+   * @param plan
+   * @return
+   * @throws MetadataException
+   */
+  public MeasurementSchema[] getSeriesSchemasAndLock(String deviceId, String[] measurementList, PhysicalPlan plan) throws MetadataException {
+    MeasurementSchema[] schemas = new MeasurementSchema[measurementList.length];
+
+    MNode deviceNode = null;
+    // 1. get device node
+    deviceNode = getDeviceNodeWithAutoCreateAndReadLock(deviceId);
+    // To reduce the String number in memory, set the deviceId from MManager to insertPlan
+    if (plan instanceof InsertPlan) {
+      ((InsertPlan) plan).setDeviceId(deviceNode.getFullPath());
+    } else if (plan instanceof InsertTabletPlan) {
+      ((InsertTabletPlan) plan).setDeviceId(deviceNode.getFullPath());
+    } else {
+      throw new MetadataException(String.format(
+        "Only support insert and insertTablets, deviceId[%s], plans [%s]", deviceId, plan.getOperatorType()));
+    }
+
+    // 2. get schema of each measurement
+    for (int i = 0; i < measurementList.length; i++) {
+      try {
+        // if do not has measurement
+        boolean isCreated = false;
+        if (!deviceNode.hasChild(measurementList[i])) {
+          // could not create it
+          if (!config.isAutoCreateSchemaEnabled()) {
+            throw new MetadataException(String.format(
+              "Current deviceId[%s] does not contain measurement:%s", deviceId, measurementList[i]));
+          }
+
+          // create it
+          Path path = new Path(deviceId, measurementList[i]);
+          TSDataType dataType = getTypeInLoc(plan, i);
+
+          createTimeseries(
+            path.getFullPath(),
+            dataType,
+            getDefaultEncoding(dataType),
+            TSFileDescriptor.getInstance().getConfig().getCompressor(),
+            Collections.emptyMap());
+          isCreated = true;
+        }

Review comment:
       what if the measurement already exists? 
   
   add 
   
   else {
    isCreated = true
   }
   
   besides,combine these to one line

##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
##########
@@ -1800,4 +1807,207 @@ private void checkMTreeModified() {
       }
     }
   }
+
+  /**
+   * get schema for device.
+   * Attention!!!  Only support insertPlan and insertTabletsPlan
+   * @param deviceId
+   * @param measurementList
+   * @param plan
+   * @return
+   * @throws MetadataException
+   */
+  public MeasurementSchema[] getSeriesSchemasAndLock(String deviceId, String[] measurementList, PhysicalPlan plan) throws MetadataException {
+    MeasurementSchema[] schemas = new MeasurementSchema[measurementList.length];
+
+    MNode deviceNode = null;
+    // 1. get device node
+    deviceNode = getDeviceNodeWithAutoCreateAndReadLock(deviceId);
+    // To reduce the String number in memory, set the deviceId from MManager to insertPlan
+    if (plan instanceof InsertPlan) {
+      ((InsertPlan) plan).setDeviceId(deviceNode.getFullPath());
+    } else if (plan instanceof InsertTabletPlan) {
+      ((InsertTabletPlan) plan).setDeviceId(deviceNode.getFullPath());
+    } else {
+      throw new MetadataException(String.format(
+        "Only support insert and insertTablets, deviceId[%s], plans [%s]", deviceId, plan.getOperatorType()));
+    }
+
+    // 2. get schema of each measurement
+    for (int i = 0; i < measurementList.length; i++) {
+      try {
+        // if do not has measurement
+        boolean isCreated = false;
+        if (!deviceNode.hasChild(measurementList[i])) {
+          // could not create it
+          if (!config.isAutoCreateSchemaEnabled()) {
+            throw new MetadataException(String.format(
+              "Current deviceId[%s] does not contain measurement:%s", deviceId, measurementList[i]));
+          }
+
+          // create it
+          Path path = new Path(deviceId, measurementList[i]);
+          TSDataType dataType = getTypeInLoc(plan, i);
+
+          createTimeseries(
+            path.getFullPath(),
+            dataType,
+            getDefaultEncoding(dataType),
+            TSFileDescriptor.getInstance().getConfig().getCompressor(),
+            Collections.emptyMap());
+          isCreated = true;
+        }
+
+        MeasurementMNode measurementNode = (MeasurementMNode) getChild(deviceNode, measurementList[i]);
+
+        // check type is match
+        if (plan instanceof InsertTabletPlan) {
+          TSDataType trueType = getTypeInLoc(plan, i);
+          if (measurementNode.getSchema().getType() != trueType) {
+            logger.warn("Datatype mismatch, Insert measurement {} type {}, metadata tree type {}",
+              measurementList[i], trueType, measurementNode.getSchema().getType());
+            if (!config.isEnablePartialInsert()) {
+              throw new MetadataException(String.format(
+                "Datatype mismatch, Insert measurement %s type %s, metadata tree type %s",
+                measurementList[i], measurementNode.getSchema().getType(),
+                trueType));
+            } else {
+              // mark failed measurement
+              ((InsertTabletPlan) plan).markMeasurementInsertionFailed(i);
+              continue;
+            }
+          }
+        }
+
+        if ((plan instanceof InsertPlan) && isCreated) {

Review comment:
       Is the isCreated needed? If a measurement does not exist, we already throw an exception

##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
##########
@@ -1800,4 +1807,207 @@ private void checkMTreeModified() {
       }
     }
   }
+
+  /**
+   * get schema for device.
+   * Attention!!!  Only support insertPlan and insertTabletsPlan
+   * @param deviceId
+   * @param measurementList
+   * @param plan
+   * @return
+   * @throws MetadataException
+   */
+  public MeasurementSchema[] getSeriesSchemasAndLock(String deviceId, String[] measurementList, PhysicalPlan plan) throws MetadataException {
+    MeasurementSchema[] schemas = new MeasurementSchema[measurementList.length];
+
+    MNode deviceNode = null;
+    // 1. get device node
+    deviceNode = getDeviceNodeWithAutoCreateAndReadLock(deviceId);
+    // To reduce the String number in memory, set the deviceId from MManager to insertPlan
+    if (plan instanceof InsertPlan) {
+      ((InsertPlan) plan).setDeviceId(deviceNode.getFullPath());
+    } else if (plan instanceof InsertTabletPlan) {
+      ((InsertTabletPlan) plan).setDeviceId(deviceNode.getFullPath());
+    } else {
+      throw new MetadataException(String.format(
+        "Only support insert and insertTablets, deviceId[%s], plans [%s]", deviceId, plan.getOperatorType()));
+    }
+
+    // 2. get schema of each measurement
+    for (int i = 0; i < measurementList.length; i++) {
+      try {
+        // if do not has measurement
+        boolean isCreated = false;
+        if (!deviceNode.hasChild(measurementList[i])) {
+          // could not create it
+          if (!config.isAutoCreateSchemaEnabled()) {
+            throw new MetadataException(String.format(
+              "Current deviceId[%s] does not contain measurement:%s", deviceId, measurementList[i]));
+          }
+
+          // create it
+          Path path = new Path(deviceId, measurementList[i]);
+          TSDataType dataType = getTypeInLoc(plan, i);
+
+          createTimeseries(
+            path.getFullPath(),
+            dataType,
+            getDefaultEncoding(dataType),
+            TSFileDescriptor.getInstance().getConfig().getCompressor(),
+            Collections.emptyMap());
+          isCreated = true;
+        }
+
+        MeasurementMNode measurementNode = (MeasurementMNode) getChild(deviceNode, measurementList[i]);
+
+        // check type is match
+        if (plan instanceof InsertTabletPlan) {
+          TSDataType trueType = getTypeInLoc(plan, i);

Review comment:
       insertDataType

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
##########
@@ -907,6 +907,17 @@ public void delete(Path path, long timestamp) throws QueryProcessException {
     }
   }
 
+  protected MeasurementSchema[] getSeriesSchemas(InsertPlan insertPlan)
+    throws MetadataException {
+    return mManager.getSeriesSchemasAndLock(insertPlan.getDeviceId(), insertPlan.getMeasurements(), insertPlan);
+  }
+
+  protected MeasurementSchema[] getSeriesSchemas(InsertTabletPlan insertTabletPlan)
+    throws MetadataException {
+    return mManager.getSeriesSchemasAndLock(insertTabletPlan.getDeviceId(),
+      insertTabletPlan.getMeasurements(), insertTabletPlan);
+  }
+

Review comment:
       remove these two methods and use mManager.getSeriesSchemasAndLock direclty




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org