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

[incubator-iotdb] branch master updated: [IOTDB-506]upgrade the protocol to v2 to reject clients or servers that version < 0.10 (#830)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d750b2e  [IOTDB-506]upgrade the protocol to v2 to reject clients or servers that version < 0.10 (#830)
d750b2e is described below

commit d750b2eadde854d3e829dba578ac73fce7cf3e96
Author: Xiangdong Huang <hx...@qq.com>
AuthorDate: Wed Feb 26 10:37:19 2020 +0800

    [IOTDB-506]upgrade the protocol to v2 to reject clients or servers that version < 0.10 (#830)
    
    * upgrade the protocol to v2 to reject clients or servers that version < 0.10
    * print better message if users use new client to connect iotdb 0.9.
---
 client-py/src/client_example.py                    |  5 +-
 .../UserGuide/4-Client/6-Status Codes.md           | 65 +++++++++++++++++++++
 docs/Documentation/UserGuide/0-Content.md          |  1 +
 .../UserGuide/4-Client/6-Status Codes.md           | 66 ++++++++++++++++++++++
 .../org/apache/iotdb/jdbc/IoTDBConnection.java     | 27 +++++----
 .../org/apache/iotdb/db/service/TSServiceImpl.java | 19 ++++++-
 .../iotdb/db/integration/IoTDBAggregationIT.java   |  8 +--
 .../integration/IoTDBAggregationSmallDataIT.java   |  2 +-
 .../integration/IoTDBLoadExternalTsfileTest.java   |  2 +-
 .../iotdb/db/integration/IoTDBMultiSeriesIT.java   |  4 +-
 .../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 +-
 .../java/org/apache/iotdb/session/Session.java     | 14 +++--
 14 files changed, 192 insertions(+), 30 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/docs/Documentation-CHN/UserGuide/4-Client/6-Status Codes.md b/docs/Documentation-CHN/UserGuide/4-Client/6-Status Codes.md
new file mode 100644
index 0000000..40d1e28
--- /dev/null
+++ b/docs/Documentation-CHN/UserGuide/4-Client/6-Status Codes.md	
@@ -0,0 +1,65 @@
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+
+# Chapter 4: Client
+# Status codes
+
+对于每个SQL请求,都会返回一个结果码;
+若SQL运行失败,客户端会收到错误码和一段错误消息。
+目前的结果码定义如下:
+
+  SUCCESS_STATUS(200),
+  STILL_EXECUTING_STATUS(201),
+  INVALID_HANDLE_STATUS(202),
+  TIMESERIES_ALREADY_EXIST_ERROR(300),
+  TIMESERIES_NOT_EXIST_ERROR(301),
+  UNSUPPORTED_FETCH_METADATA_OPERATION_ERROR(302),
+  METADATA_ERROR(303),
+  OUT_OF_TTL_ERROR(305),
+  CONFIG_ADJUSTER(306),
+  MERGE_ERROR(307),
+  SYSTEM_CHECK_ERROR(308),
+  SYNC_DEVICE_OWNER_CONFLICT_ERROR(309),
+  SYNC_CONNECTION_EXCEPTION(310),
+  STORAGE_GROUP_PROCESSOR_ERROR(311),
+  STORAGE_GROUP_ERROR(312),
+  STORAGE_ENGINE_ERROR(313),
+  EXECUTE_STATEMENT_ERROR(400),
+  SQL_PARSE_ERROR(401),
+  GENERATE_TIME_ZONE_ERROR(402),
+  SET_TIME_ZONE_ERROR(403),
+  NOT_STORAGE_GROUP_ERROR(404),
+  QUERY_NOT_ALLOWED(405),
+  AST_FORMAT_ERROR(406),
+  LOGICAL_OPERATOR_ERROR(407),
+  LOGICAL_OPTIMIZE_ERROR(408),
+  UNSUPPORTED_FILL_TYPE_ERROR(409),
+  PATH_ERROR(410),
+  INTERNAL_SERVER_ERROR(500),
+  CLOSE_OPERATION_ERROR(501),
+  READ_ONLY_SYSTEM_ERROR(502),
+  DISK_SPACE_INSUFFICIENT_ERROR(503),
+  START_UP_ERROR(504),
+  WRONG_LOGIN_PASSWORD_ERROR(600),
+  NOT_LOGIN_ERROR(601),
+  NO_PERMISSION_ERROR(602),
+  UNINITIALIZED_AUTH_ERROR(603),
+  INCOMPATIBLE_VERSION(203) 
\ No newline at end of file
diff --git a/docs/Documentation/UserGuide/0-Content.md b/docs/Documentation/UserGuide/0-Content.md
index 03f5edb..8404e3d 100644
--- a/docs/Documentation/UserGuide/0-Content.md
+++ b/docs/Documentation/UserGuide/0-Content.md
@@ -46,6 +46,7 @@
 * 3-Programming - JDBC
 * 4-Programming - Other Languages
 * 5-Programming - TsFile API
+* 6-Status Codes
 # Chapter 5: Operation Manual
 * 1-DDL (Data Definition Language)
 * 2-DML (Data Manipulation Language)
diff --git a/docs/Documentation/UserGuide/4-Client/6-Status Codes.md b/docs/Documentation/UserGuide/4-Client/6-Status Codes.md
new file mode 100644
index 0000000..55a18f3
--- /dev/null
+++ b/docs/Documentation/UserGuide/4-Client/6-Status Codes.md	
@@ -0,0 +1,66 @@
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+
+# Chapter 4: Client
+# Status codes
+
+For each request, the client will receive a status code. 
+If a SQL is not successfully, the status code and some message will be returned. 
+
+Current status codes:
+
+  SUCCESS_STATUS(200),
+  STILL_EXECUTING_STATUS(201),
+  INVALID_HANDLE_STATUS(202),
+  TIMESERIES_ALREADY_EXIST_ERROR(300),
+  TIMESERIES_NOT_EXIST_ERROR(301),
+  UNSUPPORTED_FETCH_METADATA_OPERATION_ERROR(302),
+  METADATA_ERROR(303),
+  OUT_OF_TTL_ERROR(305),
+  CONFIG_ADJUSTER(306),
+  MERGE_ERROR(307),
+  SYSTEM_CHECK_ERROR(308),
+  SYNC_DEVICE_OWNER_CONFLICT_ERROR(309),
+  SYNC_CONNECTION_EXCEPTION(310),
+  STORAGE_GROUP_PROCESSOR_ERROR(311),
+  STORAGE_GROUP_ERROR(312),
+  STORAGE_ENGINE_ERROR(313),
+  EXECUTE_STATEMENT_ERROR(400),
+  SQL_PARSE_ERROR(401),
+  GENERATE_TIME_ZONE_ERROR(402),
+  SET_TIME_ZONE_ERROR(403),
+  NOT_STORAGE_GROUP_ERROR(404),
+  QUERY_NOT_ALLOWED(405),
+  AST_FORMAT_ERROR(406),
+  LOGICAL_OPERATOR_ERROR(407),
+  LOGICAL_OPTIMIZE_ERROR(408),
+  UNSUPPORTED_FILL_TYPE_ERROR(409),
+  PATH_ERROR(410),
+  INTERNAL_SERVER_ERROR(500),
+  CLOSE_OPERATION_ERROR(501),
+  READ_ONLY_SYSTEM_ERROR(502),
+  DISK_SPACE_INSUFFICIENT_ERROR(503),
+  START_UP_ERROR(504),
+  WRONG_LOGIN_PASSWORD_ERROR(600),
+  NOT_LOGIN_ERROR(601),
+  NO_PERMISSION_ERROR(602),
+  UNINITIALIZED_AUTH_ERROR(603),
+  INCOMPATIBLE_VERSION(203) 
\ No newline at end of file
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..4afaf45 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,14 @@ public class IoTDBConnection implements Connection {
 
     } catch (TException e) {
       transport.close();
-      throw new SQLException(String.format("Can not establish connection with %s.",
-          params.getJdbcUriString()), e);
+      if (e.getMessage().contains("Required field 'client_protocol' was not present!")) {
+        // the server is an old version (less than 0.10)
+        throw new SQLException(String.format(
+            "Can not establish connection with %s : You may try to connect an old version IoTDB instance using a client with new version: %s. ",
+            params.getJdbcUriString(), e.getMessage()), 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 +514,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 b2a8f71..2a7a614 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
@@ -234,9 +234,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());
@@ -245,8 +256,8 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     } else {
       tsStatus = getStatus(TSStatusCode.WRONG_LOGIN_PASSWORD_ERROR);
     }
-    TSOpenSessionResp resp =
-        new TSOpenSessionResp(tsStatus, TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1);
+    TSOpenSessionResp resp = new TSOpenSessionResp(tsStatus,
+            TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2);
     resp.setSessionId(sessionId);
     logger.info(
         "{}: Login status: {}. User : {}",
@@ -257,6 +268,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/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java
index c3b0839..da6d3bd 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java
@@ -474,7 +474,7 @@ public class IoTDBAggregationIT {
         resultSet.next();
         fail();
       } catch (Exception e) {
-        Assert.assertEquals("Unsupported data type in aggregation AVG : TEXT", e.getMessage());
+        Assert.assertEquals("500: Unsupported data type in aggregation AVG : TEXT", e.getMessage());
       }
       try {
         statement.execute("SELECT sum(s3)" +
@@ -483,7 +483,7 @@ public class IoTDBAggregationIT {
         resultSet.next();
         fail();
       } catch (Exception e) {
-        Assert.assertEquals("Unsupported data type in aggregation SUM : TEXT", e.getMessage());
+        Assert.assertEquals("500: Unsupported data type in aggregation SUM : TEXT", e.getMessage());
       }
       try {
         statement.execute("SELECT avg(s4)" +
@@ -492,7 +492,7 @@ public class IoTDBAggregationIT {
         resultSet.next();
         fail();
       } catch (Exception e) {
-        Assert.assertEquals("Unsupported data type in aggregation AVG : BOOLEAN", e.getMessage());
+        Assert.assertEquals("500: Unsupported data type in aggregation AVG : BOOLEAN", e.getMessage());
       }
       try {
         statement.execute("SELECT sum(s4)" +
@@ -501,7 +501,7 @@ public class IoTDBAggregationIT {
         resultSet.next();
         fail();
       } catch (Exception e) {
-        Assert.assertEquals("Unsupported data type in aggregation SUM : BOOLEAN", e.getMessage());
+        Assert.assertEquals("500: Unsupported data type in aggregation SUM : BOOLEAN", e.getMessage());
       }
     } catch (Exception e) {
       e.printStackTrace();
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationSmallDataIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationSmallDataIT.java
index ce9c092..05fbcb1 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationSmallDataIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationSmallDataIT.java
@@ -205,7 +205,7 @@ public class IoTDBAggregationSmallDataIT {
             "SELECT max_value(d0.s0),max_value(d1.s1),max_value(d0.s3) FROM root.vehicle");
         fail();
       } catch (IoTDBSQLException e) {
-        Assert.assertEquals("Binary statistics does not support: max", e.getMessage());
+        Assert.assertEquals("500: Binary statistics does not support: max", e.getMessage());
       }
 
       hasResultSet = statement.execute(
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLoadExternalTsfileTest.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLoadExternalTsfileTest.java
index 7304028..70a9e72 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLoadExternalTsfileTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBLoadExternalTsfileTest.java
@@ -417,7 +417,7 @@ public class IoTDBLoadExternalTsfileTest {
       } catch (Exception e) {
         hasError = true;
         Assert.assertEquals(
-            "Statement format is not right: Please check the statement: load [FILE] true/false [storage group level]",
+            "401: Statement format is not right: Please check the statement: load [FILE] true/false [storage group level]",
             e.getMessage());
       }
       Assert.assertTrue(hasError);
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java
index debfb9e..a814340 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java
@@ -408,7 +408,7 @@ public class IoTDBMultiSeriesIT {
       fail("not throw exception when unknown time series in where clause");
     } catch (SQLException e) {
       assertEquals(
-          "Statement format is not right: Filter has some time series don't correspond to any known time series",
+          "401: Statement format is not right: Filter has some time series don't correspond to any known time series",
           e.getMessage());
     }
   }
@@ -426,7 +426,7 @@ public class IoTDBMultiSeriesIT {
     } catch (SQLException e) {
       e.printStackTrace();
       assertEquals(
-          "Statement format is not right: Path [root.vehicle.d0.s10] does not exist",
+          "401: Statement format is not right: Path [root.vehicle.d0.s10] does not exist",
           e.getMessage());
     }
   }
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 b5aa64f..fb307df 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
@@ -61,7 +61,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();