You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2020/02/21 16:43:50 UTC

[incubator-iotdb] branch version_compatibility created (now d2b551f)

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

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


      at d2b551f  upgrade the protocol to v2 to reject clients or servers that version < 0.10

This branch includes the following new commits:

     new d2b551f  upgrade the protocol to v2 to reject clients or servers that version < 0.10

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: upgrade the protocol to v2 to reject clients or servers that version < 0.10

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

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

commit d2b551fb784721bcfb3bfc858c16e4836441b670
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Sat Feb 22 00:43:17 2020 +0800

    upgrade the protocol to v2 to reject clients or servers that version < 0.10
---
 client-py/src/client_example.py                     |  5 +++--
 .../java/org/apache/iotdb/jdbc/IoTDBConnection.java | 21 +++++++++++----------
 .../org/apache/iotdb/db/service/TSServiceImpl.java  | 17 ++++++++++++++++-
 .../main/java/org/apache/iotdb/rpc/RpcUtils.java    |  2 +-
 .../java/org/apache/iotdb/rpc/TSStatusCode.java     |  4 +++-
 service-rpc/src/main/thrift/rpc.thrift              |  3 ++-
 .../main/java/org/apache/iotdb/session/Session.java | 14 +++++++++-----
 7 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/client-py/src/client_example.py b/client-py/src/client_example.py
index 90c39f8..deb3022 100644
--- a/client-py/src/client_example.py
+++ b/client-py/src/client_example.py
@@ -164,14 +164,15 @@ if __name__ == '__main__':
     transport.open()
 
     # Authentication
-    clientProtocol = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1
+    clientProtocol = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2
     resp = client.openSession(TSOpenSessionReq(client_protocol=clientProtocol,
                                                username=username,
                                                password=password))
     if resp.serverProtocolVersion != clientProtocol:
         print('Inconsistent protocol, server version: %d, client version: %d'
               % (resp.serverProtocolVersion, clientProtocol))
-        exit()
+        if resp.serverProtocolVersion > clientProtocol:
+          exit()
     sessionId = resp.sessionId
 
     # This is necessary for resource control
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
index 4760b9c..691d53f 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
@@ -53,7 +53,7 @@ import org.slf4j.LoggerFactory;
 public class IoTDBConnection implements Connection {
 
   private static final Logger logger = LoggerFactory.getLogger(IoTDBConnection.class);
-  private static final TSProtocolVersion protocolVersion = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1;
+  private static final TSProtocolVersion protocolVersion = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2;
   private TSIService.Iface client = null;
   private long sessionId = -1;
   private IoTDBConnectionParams params;
@@ -410,7 +410,7 @@ public class IoTDBConnection implements Connection {
   }
 
   private void openSession() throws SQLException {
-    TSOpenSessionReq openReq = new TSOpenSessionReq(TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1);
+    TSOpenSessionReq openReq = new TSOpenSessionReq();
 
     openReq.setUsername(params.getUsername());
     openReq.setPassword(params.getPassword());
@@ -423,11 +423,14 @@ public class IoTDBConnection implements Connection {
       RpcUtils.verifySuccess(openResp.getStatus());
 
       if (protocolVersion.getValue() != openResp.getServerProtocolVersion().getValue()) {
-        throw new TException(String
-            .format("Protocol not supported, Client version is %d, but Server version is %d",
-                protocolVersion.getValue(), openResp.getServerProtocolVersion().getValue()));
+        logger.warn("Protocol differ, Client version is {}}, but Server version is {}",
+            protocolVersion.getValue(), openResp.getServerProtocolVersion().getValue());
+        if (openResp.getServerProtocolVersion().getValue() == 0) {// less than 0.10
+          throw new TException(String
+              .format("Protocol not supported, Client version is %s, but Server version is %s",
+                  protocolVersion.getValue(), openResp.getServerProtocolVersion().getValue()));
+        }
       }
-      setProtocol(openResp.getServerProtocolVersion());
 
       if (zoneId != null) {
         setTimeZone(zoneId.toString());
@@ -437,8 +440,8 @@ public class IoTDBConnection implements Connection {
 
     } catch (TException e) {
       transport.close();
-      throw new SQLException(String.format("Can not establish connection with %s.",
-          params.getJdbcUriString()), e);
+      throw new SQLException(String.format("Can not establish connection with %s : %s",
+          params.getJdbcUriString(), e.getMessage()), e);
     } catch (IoTDBRPCException e) {
       // failed to connect, disconnect from the server
       transport.close();
@@ -505,7 +508,5 @@ public class IoTDBConnection implements Connection {
     return getClient().getProperties();
   }
 
-  private void setProtocol(TSProtocolVersion protocol) {
-  }
 
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index b9a4685..cbfe6f7 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -221,9 +221,20 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
       logger.info("meet error while logging in.", e);
       status = false;
     }
+
     TSStatus tsStatus;
     long sessionId = -1;
     if (status) {
+      //check the version compatibility
+      boolean compatible = checkCompatibility(req.getClient_protocol());
+      if (!compatible) {
+        tsStatus = getStatus(TSStatusCode.INCOMPATIBLE_VERSION, "The version is incompatible, please upgrade to " + IoTDBConstant.VERSION);
+        TSOpenSessionResp resp = new TSOpenSessionResp(tsStatus,
+            TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2);
+        resp.setSessionId(sessionId);
+        return resp;
+      }
+
       tsStatus = getStatus(TSStatusCode.SUCCESS_STATUS, "Login successfully");
       sessionId = sessionIdGenerator.incrementAndGet();
       sessionIdUsernameMap.put(sessionId, req.getUsername());
@@ -233,7 +244,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
       tsStatus = getStatus(TSStatusCode.WRONG_LOGIN_PASSWORD_ERROR);
     }
     TSOpenSessionResp resp = new TSOpenSessionResp(tsStatus,
-            TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1);
+            TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2);
     resp.setSessionId(sessionId);
     logger.info("{}: Login status: {}. User : {}", IoTDBConstant.GLOBAL_DB_NAME,
             tsStatus.getStatusType().getMessage(), req.getUsername());
@@ -241,6 +252,10 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     return resp;
   }
 
+  private boolean checkCompatibility(TSProtocolVersion version) {
+    return version.equals(TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2);
+  }
+
   @Override
   public TSStatus closeSession(TSCloseSessionReq req) {
     logger.info("{}: receive close session", IoTDBConstant.GLOBAL_DB_NAME);
diff --git a/service-rpc/src/main/java/org/apache/iotdb/rpc/RpcUtils.java b/service-rpc/src/main/java/org/apache/iotdb/rpc/RpcUtils.java
index b707c70..dbae831 100644
--- a/service-rpc/src/main/java/org/apache/iotdb/rpc/RpcUtils.java
+++ b/service-rpc/src/main/java/org/apache/iotdb/rpc/RpcUtils.java
@@ -36,7 +36,7 @@ public class RpcUtils {
    */
   public static void verifySuccess(TSStatus status) throws IoTDBRPCException {
     if (status.getStatusType().getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
-      throw new IoTDBRPCException(status.getStatusType().getMessage());
+      throw new IoTDBRPCException(String.format("%d: %s", status.getStatusType().getCode(), status.getStatusType().getMessage()));
     }
   }
 
diff --git a/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java b/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java
index 3ec590d..703b28e 100644
--- a/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java
+++ b/service-rpc/src/main/java/org/apache/iotdb/rpc/TSStatusCode.java
@@ -55,7 +55,9 @@ public enum TSStatusCode {
   WRONG_LOGIN_PASSWORD_ERROR(600),
   NOT_LOGIN_ERROR(601),
   NO_PERMISSION_ERROR(602),
-  UNINITIALIZED_AUTH_ERROR(603);
+  UNINITIALIZED_AUTH_ERROR(603),
+  INCOMPATIBLE_VERSION(203)
+  ;
 
   private int statusCode;
 
diff --git a/service-rpc/src/main/thrift/rpc.thrift b/service-rpc/src/main/thrift/rpc.thrift
index c47ad38..fb96f02 100644
--- a/service-rpc/src/main/thrift/rpc.thrift
+++ b/service-rpc/src/main/thrift/rpc.thrift
@@ -47,6 +47,7 @@ struct TSExecuteStatementResp {
 
 enum TSProtocolVersion {
   IOTDB_SERVICE_PROTOCOL_V1,
+  IOTDB_SERVICE_PROTOCOL_V2,//V2 is the first version that we can check version compatibility
 }
 
 struct TSOpenSessionResp {
@@ -65,7 +66,7 @@ struct TSOpenSessionResp {
 // OpenSession()
 // Open a session (connection) on the server against which operations may be executed.
 struct TSOpenSessionReq {
-  1: required TSProtocolVersion client_protocol = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1
+  1: required TSProtocolVersion client_protocol = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2
   2: optional string username
   3: optional string password
   4: optional map<string, string> configuration
diff --git a/session/src/main/java/org/apache/iotdb/session/Session.java b/session/src/main/java/org/apache/iotdb/session/Session.java
index 26bc558..2db5923 100644
--- a/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -65,7 +65,7 @@ import org.slf4j.LoggerFactory;
 public class Session {
 
   private static final Logger logger = LoggerFactory.getLogger(Session.class);
-  private final TSProtocolVersion protocolVersion = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1;
+  private final TSProtocolVersion protocolVersion = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2;
   private String host;
   private int port;
   private String username;
@@ -126,7 +126,7 @@ public class Session {
       client = new TSIService.Client(new TBinaryProtocol(transport));
     }
 
-    TSOpenSessionReq openReq = new TSOpenSessionReq(TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1);
+    TSOpenSessionReq openReq = new TSOpenSessionReq();
     openReq.setUsername(username);
     openReq.setPassword(password);
 
@@ -136,9 +136,13 @@ public class Session {
       RpcUtils.verifySuccess(openResp.getStatus());
 
       if (protocolVersion.getValue() != openResp.getServerProtocolVersion().getValue()) {
-        throw new TException(String
-            .format("Protocol not supported, Client version is %s, but Server version is %s",
-                protocolVersion.getValue(), openResp.getServerProtocolVersion().getValue()));
+        logger.warn("Protocol differ, Client version is {}}, but Server version is {}",
+            protocolVersion.getValue(), openResp.getServerProtocolVersion().getValue());
+        if (openResp.getServerProtocolVersion().getValue() == 0) {// less than 0.10
+          throw new TException(String
+              .format("Protocol not supported, Client version is %s, but Server version is %s",
+                  protocolVersion.getValue(), openResp.getServerProtocolVersion().getValue()));
+        }
       }
 
       sessionId = openResp.getSessionId();