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 2020/04/06 01:46:37 UTC

[incubator-iotdb] branch fix_auto_create_schema_bug created (now eed972d)

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

qiaojialin pushed a change to branch fix_auto_create_schema_bug
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git.


      at eed972d  fix concurrent auto create schema bug

This branch includes the following new commits:

     new eed972d  fix concurrent auto create schema bug

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-iotdb] 01/01: fix concurrent auto create schema bug

Posted by qi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

qiaojialin pushed a commit to branch fix_auto_create_schema_bug
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git

commit eed972d6264794ddd16bad672aa45ff95753f8af
Author: qiaojialin <64...@qq.com>
AuthorDate: Mon Apr 6 09:46:20 2020 +0800

    fix concurrent auto create schema bug
---
 .../java/org/apache/iotdb/db/metadata/MTree.java   |  8 +++---
 .../apache/iotdb/db/qp/executor/PlanExecutor.java  | 30 +++++++++++++++++-----
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
index cdb3e6e..463abaf 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
@@ -101,11 +101,11 @@ public class MTree implements Serializable {
     if (cur instanceof LeafMNode) {
       throw new PathAlreadyExistException(cur.getFullPath());
     }
-    MNode leaf = new LeafMNode(cur, nodeNames[nodeNames.length - 1], dataType, encoding,
-        compressor, props);
-    if (cur.hasChild(leaf.getName())) {
-      throw new MetadataException(String.format("The timeseries %s has already existed.", path));
+    String leafName = nodeNames[nodeNames.length - 1];
+    if (cur.hasChild(leafName)) {
+      throw new PathAlreadyExistException(String.format("Path %s has already existed.", path));
     }
+    MNode leaf = new LeafMNode(cur, leafName, dataType, encoding, compressor, props);
     cur.addChild(leaf);
   }
 
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
index de6bfc7..141ff43 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
@@ -63,6 +63,7 @@ import org.apache.iotdb.db.engine.flush.pool.FlushTaskPoolManager;
 import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
 import org.apache.iotdb.db.exception.StorageEngineException;
 import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.metadata.PathAlreadyExistException;
 import org.apache.iotdb.db.exception.metadata.PathNotExistException;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.metadata.MManager;
@@ -127,9 +128,12 @@ import org.apache.iotdb.tsfile.utils.Binary;
 import org.apache.iotdb.tsfile.utils.Pair;
 import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
 import org.apache.iotdb.tsfile.write.writer.RestorableTsFileIOWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class PlanExecutor implements IPlanExecutor {
 
+  private static final Logger logger = LoggerFactory.getLogger(PlanExecutor.class);
   // for data query
   protected IQueryRouter queryRouter;
   // for system schema
@@ -710,9 +714,16 @@ public class PlanExecutor implements IPlanExecutor {
           TSDataType dataType = TypeInferenceUtils.getPredictedDataType(strValues[i]);
           Path path = new Path(deviceId, measurement);
 
-          mManager.createTimeseries(path.toString(), dataType, getDefaultEncoding(dataType),
-                  TSFileDescriptor.getInstance().getConfig().getCompressor(),
-              Collections.emptyMap());
+          try {
+            mManager.createTimeseries(path.toString(), dataType, getDefaultEncoding(dataType),
+                TSFileDescriptor.getInstance().getConfig().getCompressor(),
+                Collections.emptyMap());
+          } catch (PathAlreadyExistException e) {
+            if (logger.isDebugEnabled()) {
+              logger.debug("Ignore PathAlreadyExistException when Concurrent inserting"
+                  + " a non-exist time series {}", path.getFullPath());
+            }
+          }
         }
         LeafMNode measurementNode = (LeafMNode) node.getChild(measurement);
         schemas[i] = measurementNode.getSchema();
@@ -768,9 +779,16 @@ public class PlanExecutor implements IPlanExecutor {
           }
           Path path = new Path(deviceId, measurementList[i]);
           TSDataType dataType = dataTypes[i];
-          mManager.createTimeseries(path.getFullPath(), dataType, getDefaultEncoding(dataType),
-                  TSFileDescriptor.getInstance().getConfig().getCompressor(),
-                  Collections.emptyMap());
+          try {
+            mManager.createTimeseries(path.getFullPath(), dataType, getDefaultEncoding(dataType),
+                TSFileDescriptor.getInstance().getConfig().getCompressor(),
+                Collections.emptyMap());
+          } catch (PathAlreadyExistException e) {
+            if (logger.isDebugEnabled()) {
+              logger.debug("Ignore PathAlreadyExistException when Concurrent inserting"
+                  + " a non-exist time series {}", path.getFullPath());
+            }
+          }
         }
         LeafMNode measurementNode = (LeafMNode) node.getChild(measurementList[i]);