761417898 commented on code in PR #15439:
URL: https://github.com/apache/iotdb/pull/15439#discussion_r2081267764


##########
iotdb-client/client-cpp/src/main/Session.cpp:
##########
@@ -942,325 +955,273 @@ void Session::close() {
         return;
     }
     isClosed = true;
-
-    bool needThrowException = false;
-    string errMsg;
-    try {
-        TSCloseSessionReq req;
-        req.__set_sessionId(sessionId);
-        TSStatus tsStatus;
-        client->closeSession(tsStatus, req);
-    } catch (const TTransportException &e) {
-        log_debug(e.what());
-        throw IoTDBConnectionException(e.what());
-    } catch (const exception &e) {
-        log_debug(e.what());
-        errMsg = errMsg + "Session::close() client->closeSession() error, 
maybe remote server is down. " + e.what() + "\n" ;
-        needThrowException = true;
-    }
-
-    try {
-        if (transport->isOpen()) {
-            transport->close();
-        }
-    }
-    catch (const exception &e) {
-        log_debug(e.what());
-        errMsg = errMsg + "Session::close() transport->close() error. " + 
e.what() + "\n" ;
-        needThrowException = true;
-    }
-
-    if (needThrowException) {
-        throw IoTDBException(errMsg);
-    }
 }
 
 
-void Session::insertRecord(const string &deviceId, int64_t time,
-                           const vector<string> &measurements,
-                           const vector<string> &values) {
+void Session::insertRecord(const string& deviceId, int64_t time,
+                           const vector<string>& measurements,
+                           const vector<string>& values) {
     TSInsertStringRecordReq req;
-    req.__set_sessionId(sessionId);
     req.__set_prefixPath(deviceId);
     req.__set_timestamp(time);
     req.__set_measurements(measurements);
     req.__set_values(values);
     req.__set_isAligned(false);
-    TSStatus respStatus;
     try {
-        
getSessionConnection(deviceId)->getSessionClient()->insertStringRecord(respStatus,
 req);
-        RpcUtils::verifySuccess(respStatus);
-    } catch (RedirectException& e) {
+        getSessionConnection(deviceId)->insertStringRecord(req);
+    }
+    catch (RedirectException& e) {
         handleRedirection(deviceId, e.endPoint);
-    } catch (const IoTDBConnectionException &e) {
+    } catch (const IoTDBConnectionException& e) {
         if (enableRedirection && deviceIdToEndpoint.find(deviceId) != 
deviceIdToEndpoint.end()) {
             deviceIdToEndpoint.erase(deviceId);
             try {
-                
defaultSessionConnection->getSessionClient()->insertStringRecord(respStatus, 
req);
-            } catch (RedirectException& e) {
+                defaultSessionConnection->insertStringRecord(req);
+            }
+            catch (RedirectException& e) {
             }
-        } else {
-            throw IoTDBConnectionException(e.what());
         }
-    } catch (const TTransportException &e) {
-        log_debug(e.what());
-        throw IoTDBConnectionException(e.what());
-    } catch (const IoTDBException &e) {
-        log_debug(e.what());
-        throw;
-    } catch (const exception &e) {
-        log_debug(e.what());
-        throw IoTDBException(e.what());
+        else {
+            throw e;
+        }
     }
 }
 
-void Session::insertRecord(const string &prefixPath, int64_t time,
-                           const vector<string> &measurements,
-                           const vector<TSDataType::TSDataType> &types,
-                           const vector<char *> &values) {
+void Session::insertRecord(const string& deviceId, int64_t time,
+                           const vector<string>& measurements,
+                           const vector<TSDataType::TSDataType>& types,
+                           const vector<char*>& values) {
     TSInsertRecordReq req;
-    req.__set_sessionId(sessionId);
-    req.__set_prefixPath(prefixPath);
+    req.__set_prefixPath(deviceId);
     req.__set_timestamp(time);
     req.__set_measurements(measurements);
     string buffer;
     putValuesIntoBuffer(types, values, buffer);
     req.__set_values(buffer);
     req.__set_isAligned(false);
-    TSStatus respStatus;
     try {
-        client->insertRecord(respStatus, req);
-        RpcUtils::verifySuccess(respStatus);
-    } catch (const TTransportException &e) {
-        log_debug(e.what());
-        throw IoTDBConnectionException(e.what());
-    } catch (const IoTDBException &e) {
-        log_debug(e.what());
-        throw;
-    } catch (const exception &e) {
-        log_debug(e.what());
-        throw IoTDBException(e.what());
+        getSessionConnection(deviceId)->insertRecord(req);
+    }
+    catch (RedirectException& e) {
+        handleRedirection(deviceId, e.endPoint);
+    } catch (const IoTDBConnectionException& e) {
+        if (enableRedirection && deviceIdToEndpoint.find(deviceId) != 
deviceIdToEndpoint.end()) {
+            deviceIdToEndpoint.erase(deviceId);
+            try {
+                defaultSessionConnection->insertRecord(req);
+            }
+            catch (RedirectException& e) {
+            }

Review Comment:
   Maintained processing logic consistency with the Java version
   ```Java
     private void insertRecord(String prefixPath, TSInsertRecordReq request)
         throws IoTDBConnectionException, StatementExecutionException {
       try {
         getSessionConnection(prefixPath).insertRecord(request);
       } catch (RedirectException e) {
         handleRedirection(prefixPath, e.getEndPoint());
       } catch (IoTDBConnectionException e) {
         if (enableRedirection
             && !deviceIdToEndpoint.isEmpty()
             && deviceIdToEndpoint.get(prefixPath) != null) {
           logger.warn(SESSION_CANNOT_CONNECT, 
deviceIdToEndpoint.get(prefixPath));
           deviceIdToEndpoint.remove(prefixPath);
           try {
             defaultSessionConnection.insertRecord(request);
           } catch (RedirectException ignored) {
           }
         } else {
           throw e;
         }
       }
     }
   ```



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to