Ring-k commented on a change in pull request #1387:
URL: https://github.com/apache/incubator-iotdb/pull/1387#discussion_r444929700



##########
File path: 
cluster/src/main/java/org/apache/iotdb/cluster/server/member/MetaGroupMember.java
##########
@@ -1530,9 +1544,39 @@ private TSStatus processPartitionedPlan(PhysicalPlan 
plan) throws UnsupportedPla
     } catch (MetadataException e) {
       logger.error("Cannot route plan {}", plan, e);
     }
-    // the storage group is not found locally, forward it to the leader
+    // the storage group is not found locally
     if (planGroupMap == null || planGroupMap.isEmpty()) {
-      logger.debug("{}: Cannot found storage groups for {}", name, plan);
+      if (plan instanceof InsertPlan && 
ClusterDescriptor.getInstance().getConfig()
+          .isEnableAutoCreateSchema()) {
+        // try to set storage group
+        String deviceId = ((InsertPlan) plan).getDeviceId();
+        try {
+          String storageGroupName = MetaUtils
+              .getStorageGroupNameByLevel(deviceId, 
IoTDBDescriptor.getInstance()
+                  .getConfig().getDefaultStorageGroupLevel());
+          SetStorageGroupPlan setStorageGroupPlan = new SetStorageGroupPlan(
+              new Path(storageGroupName));
+          TSStatus setStorageGroupResult = 
processNonPartitionedMetaPlan(setStorageGroupPlan);
+          if (setStorageGroupResult.getCode() != 
TSStatusCode.SUCCESS_STATUS.getStatusCode() &&
+          setStorageGroupResult.getCode() != 
TSStatusCode.PATH_ALREADY_EXIST_ERROR.getStatusCode()) {
+            throw new MetadataException(
+                String.format("Status Code: %d, failed to set storage group ",
+                    setStorageGroupResult.getCode(), storageGroupName)
+            );
+          }
+          // try to create timeseries
+          boolean isAutoCreateTimeseriesSuccess = 
autoCreateTimeseries((InsertPlan)plan);
+          if(!isAutoCreateTimeseriesSuccess){
+            throw new MetadataException(
+                String.format("Failed to create timeseries from InsertPlan 
automatically.")
+            );
+          }
+          return executeNonQuery(plan);
+        } catch (MetadataException e) {
+          logger.error("Failed to set storage group or create timeseries, 
because {}", e.getMessage());

Review comment:
       Thanks for your suggestion. 




----------------------------------------------------------------
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:
[email protected]


Reply via email to