Skip to content

Commit

Permalink
Merge 9dce619 into 1969b54
Browse files Browse the repository at this point in the history
  • Loading branch information
jixuan1989 committed Feb 23, 2020
2 parents 1969b54 + 9dce619 commit 3d4791f
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 29 deletions.
5 changes: 3 additions & 2 deletions client-py/src/client_example.py
Expand Up @@ -164,14 +164,15 @@ def convertQueryDataSet(queryDataSet, dataTypeList):
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
Expand Down
65 changes: 65 additions & 0 deletions 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)
1 change: 1 addition & 0 deletions docs/Documentation/UserGuide/0-Content.md
Expand Up @@ -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)
Expand Down
66 changes: 66 additions & 0 deletions 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)
27 changes: 17 additions & 10 deletions jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
Expand Up @@ -53,7 +53,7 @@
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;
Expand Down Expand Up @@ -410,7 +410,7 @@ private void openTransport() throws TTransportException {
}

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());
Expand All @@ -423,11 +423,14 @@ private void openSession() throws SQLException {
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());
Expand All @@ -437,8 +440,14 @@ private void openSession() throws SQLException {

} 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();
Expand Down Expand Up @@ -505,7 +514,5 @@ public ServerProperties getServerProperties() throws TException {
return getClient().getProperties();
}

private void setProtocol(TSProtocolVersion protocol) {
}

}
Expand Up @@ -234,9 +234,20 @@ public TSOpenSessionResp openSession(TSOpenSessionReq req) throws TException {
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());
Expand All @@ -245,8 +256,8 @@ public TSOpenSessionResp openSession(TSOpenSessionReq req) throws TException {
} 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 : {}",
Expand All @@ -257,6 +268,10 @@ public TSOpenSessionResp openSession(TSOpenSessionReq req) throws TException {
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);
Expand Down
Expand Up @@ -474,7 +474,7 @@ public void avgSumErrorTest() throws SQLException {
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)" +
Expand All @@ -483,7 +483,7 @@ public void avgSumErrorTest() throws SQLException {
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)" +
Expand All @@ -492,7 +492,7 @@ public void avgSumErrorTest() throws SQLException {
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)" +
Expand All @@ -501,7 +501,7 @@ public void avgSumErrorTest() throws SQLException {
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();
Expand Down
Expand Up @@ -417,7 +417,7 @@ public void loadTsFileTestWithAutoCreateSchema() throws SQLException {
} 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);
Expand Down
Expand Up @@ -408,7 +408,7 @@ public void selectWhereUnknownTimeSeries() throws ClassNotFoundException {
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());
}
}
Expand All @@ -426,7 +426,7 @@ public void selectWhereUnknownTimeSeriesFromRoot() throws ClassNotFoundException
} 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] doesn't correspond to any known time series",
e.getMessage());
}
}
Expand Down
Expand Up @@ -36,7 +36,7 @@ public static TSIService.Iface newSynchronizedClient(TSIService.Iface client) {
*/
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()));
}
}

Expand Down
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion service-rpc/src/main/thrift/rpc.thrift
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 3d4791f

Please sign in to comment.