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/06/01 15:11:48 UTC

[GitHub] [iotdb] MrQuansy commented on a diff in pull request #6083: [IOTDB-2988] Cache leader in session

MrQuansy commented on code in PR #6083:
URL: https://github.com/apache/iotdb/pull/6083#discussion_r886926554


##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/QueryExecution.java:
##########
@@ -360,6 +359,41 @@ private void initResultHandle() {
     }
   }
 
+  private ExecutionResult getExecutionResult(QueryState state) {
+    TSStatusCode statusCode =
+        // For WRITE, the state should be FINISHED; For READ, the state could be RUNNING
+        state == QueryState.FINISHED || state == QueryState.RUNNING
+            ? TSStatusCode.SUCCESS_STATUS
+            : TSStatusCode.QUERY_PROCESS_ERROR;
+
+    TSStatus tsstatus = RpcUtils.getStatus(statusCode, stateMachine.getFailureMessage());
+
+    // collect redirect info to client for writing
+    if (analysis.getStatement() instanceof InsertBaseStatement) {
+      InsertBaseStatement insertStatement = (InsertBaseStatement) analysis.getStatement();
+      List<TEndPoint> redirectNodeList =
+          insertStatement.collectRedirectInfo(analysis.getDataPartitionInfo());
+      if (insertStatement instanceof InsertRowStatement
+          || insertStatement instanceof InsertMultiTabletsStatement) {
+        // multiple devices
+        if (statusCode == TSStatusCode.SUCCESS_STATUS) {
+          List<TSStatus> subStatus = new ArrayList<>();
+          tsstatus.setCode(TSStatusCode.NEED_REDIRECTION.getStatusCode());
+          for (TEndPoint endPoint : redirectNodeList) {
+            subStatus.add(
+                StatusUtils.getStatus(TSStatusCode.NEED_REDIRECTION).setRedirectNode(endPoint));
+          }
+          tsstatus.setSubStatus(subStatus);
+        }
+      } else {
+        // single device
+        tsstatus.setRedirectNode(redirectNodeList.get(0));

Review Comment:
   > 
   We get data partition info from config nodes or local partition cache. Config nodes will set the leader at the first one in `TRegionReplicaSet`. When the leader has been transferred, we will update local partition cache afterwards.
   



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