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 2022/04/12 02:39:29 UTC

[GitHub] [iotdb] wangchao316 commented on a diff in pull request #5479: [IOTDB-2804] DataRegion consensus state machine

wangchao316 commented on code in PR #5479:
URL: https://github.com/apache/iotdb/pull/5479#discussion_r847860644


##########
server/src/main/java/org/apache/iotdb/db/consensus/statemachine/DataRegionStateMachine.java:
##########
@@ -51,7 +57,28 @@ public void stop() {}
   @Override
   protected TSStatus write(FragmentInstance fragmentInstance) {
     logger.info("Execute write plan in DataRegionStateMachine");
-    return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
+    PlanNode insertNode = fragmentInstance.getFragment().getRoot();
+    try {
+      if (insertNode instanceof InsertRowNode) {
+        region.insert((InsertRowNode) insertNode);
+      } else if (insertNode instanceof InsertTabletNode) {
+        region.insertTablet((InsertTabletNode) insertNode);
+      } else if (insertNode instanceof InsertRowsNode) {
+        region.insert((InsertRowsNode) insertNode);
+      } else if (insertNode instanceof InsertMultiTabletsNode) {
+        region.insertTablets((InsertMultiTabletsNode) (insertNode));
+      } else if (insertNode instanceof InsertRowsOfOneDeviceNode) {
+        region.insert((InsertRowsOfOneDeviceNode) insertNode);
+      } else {
+        logger.error("Unsupported plan node for writing to data region : {}", insertNode);
+        return StatusUtils.UNSUPPORTED_OPERATION;
+      }
+    } catch (BatchProcessException e) {
+      return RpcUtils.getStatus(Arrays.asList(e.getFailingStatus()));
+    } catch (Exception e) {
+      return StatusUtils.EXECUTE_STATEMENT_ERROR;

Review Comment:
   print exception log



##########
server/src/main/java/org/apache/iotdb/db/consensus/statemachine/DataRegionStateMachine.java:
##########
@@ -51,7 +57,28 @@ public void stop() {}
   @Override
   protected TSStatus write(FragmentInstance fragmentInstance) {
     logger.info("Execute write plan in DataRegionStateMachine");
-    return new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode());
+    PlanNode insertNode = fragmentInstance.getFragment().getRoot();
+    try {
+      if (insertNode instanceof InsertRowNode) {
+        region.insert((InsertRowNode) insertNode);
+      } else if (insertNode instanceof InsertTabletNode) {
+        region.insertTablet((InsertTabletNode) insertNode);
+      } else if (insertNode instanceof InsertRowsNode) {
+        region.insert((InsertRowsNode) insertNode);
+      } else if (insertNode instanceof InsertMultiTabletsNode) {
+        region.insertTablets((InsertMultiTabletsNode) (insertNode));
+      } else if (insertNode instanceof InsertRowsOfOneDeviceNode) {
+        region.insert((InsertRowsOfOneDeviceNode) insertNode);
+      } else {
+        logger.error("Unsupported plan node for writing to data region : {}", insertNode);
+        return StatusUtils.UNSUPPORTED_OPERATION;
+      }
+    } catch (BatchProcessException e) {
+      return RpcUtils.getStatus(Arrays.asList(e.getFailingStatus()));

Review Comment:
   print exception log.



##########
server/src/main/java/org/apache/iotdb/db/engine/storagegroup/DataRegion.java:
##########
@@ -62,8 +62,7 @@
 import org.apache.iotdb.db.metadata.idtable.IDTableManager;
 import org.apache.iotdb.db.metadata.mnode.IMeasurementMNode;
 import org.apache.iotdb.db.metadata.path.PartialPath;
-import org.apache.iotdb.db.mpp.sql.planner.plan.node.write.InsertRowNode;
-import org.apache.iotdb.db.mpp.sql.planner.plan.node.write.InsertTabletNode;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.write.*;

Review Comment:
   does not import *



##########
server/src/main/java/org/apache/iotdb/db/consensus/statemachine/DataRegionStateMachine.java:
##########
@@ -22,13 +22,19 @@
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.consensus.common.DataSet;
 import org.apache.iotdb.db.engine.storagegroup.DataRegion;
+import org.apache.iotdb.db.exception.BatchProcessException;
 import org.apache.iotdb.db.mpp.execution.FragmentInstanceManager;
 import org.apache.iotdb.db.mpp.sql.planner.plan.FragmentInstance;
-import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.PlanNode;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.write.*;

Review Comment:
   import *



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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