From f947c8f0a2d07583270c48763916cf7bc1b639d2 Mon Sep 17 00:00:00 2001 From: qiaojialin <646274302@qq.com> Date: Mon, 9 Mar 2020 20:57:40 +0800 Subject: [PATCH 1/8] refine error code --- .../iotdb/rocketmq/RocketMQConsumer.java | 14 +- .../apache/iotdb/jdbc/IoTDBSQLException.java | 2 +- .../org/apache/iotdb/jdbc/IoTDBStatement.java | 49 +-- .../java/org/apache/iotdb/jdbc/BatchTest.java | 54 +-- .../iotdb/jdbc/IoTDBConnectionTest.java | 6 +- .../jdbc/IoTDBPreparedStatementTest.java | 2 +- .../iotdb/jdbc/IoTDBQueryResultSetTest.java | 4 +- .../apache/iotdb/jdbc/IoTDBStatementTest.java | 4 +- .../java/org/apache/iotdb/jdbc/UtilsTest.java | 7 +- .../apache/iotdb/db/engine/StorageEngine.java | 3 +- .../storagegroup/StorageGroupProcessor.java | 19 +- .../engine/storagegroup/TsFileProcessor.java | 6 +- .../iotdb/db/metrics/ui/MetricsPage.java | 4 +- .../iotdb/db/qp/executor/IPlanExecutor.java | 3 +- .../iotdb/db/qp/executor/PlanExecutor.java | 15 +- .../apache/iotdb/db/service/StaticResps.java | 4 +- .../iotdb/db/service/TSServiceImpl.java | 325 +++++++----------- .../IoTDBLoadExternalTsfileTest.java | 2 +- .../db/integration/IoTDBMultiSeriesIT.java | 4 +- .../iotdb/rpc/BatchExecutionException.java | 45 +++ .../java/org/apache/iotdb/rpc/RpcUtils.java | 92 ++++- service-rpc/src/main/thrift/rpc.thrift | 21 +- .../org/apache/iotdb/session/Session.java | 116 +++---- .../apache/iotdb/session/IoTDBSessionIT.java | 82 ++--- 24 files changed, 445 insertions(+), 438 deletions(-) create mode 100644 service-rpc/src/main/java/org/apache/iotdb/rpc/BatchExecutionException.java diff --git a/example/rocketmq/src/main/java/org/apache/iotdb/rocketmq/RocketMQConsumer.java b/example/rocketmq/src/main/java/org/apache/iotdb/rocketmq/RocketMQConsumer.java index 59f76518709aa..e55a9aa9456e7 100644 --- a/example/rocketmq/src/main/java/org/apache/iotdb/rocketmq/RocketMQConsumer.java +++ b/example/rocketmq/src/main/java/org/apache/iotdb/rocketmq/RocketMQConsumer.java @@ -70,12 +70,12 @@ private void initIoTDB(String host, int port, String user, String password) createTimeseries(sql); } } - + private void addStorageGroup(String storageGroup) throws IoTDBConnectionException, StatementExecutionException { session.setStorageGroup(storageGroup); } - + private void createTimeseries(String[] sql) throws StatementExecutionException, IoTDBConnectionException { String timeseries = sql[0]; TSDataType dataType = TSDataType.valueOf(sql[1]); @@ -83,8 +83,8 @@ private void createTimeseries(String[] sql) throws StatementExecutionException, CompressionType compressionType = CompressionType.valueOf(sql[3]); session.createTimeseries(timeseries, dataType, encoding, compressionType); } - - private void insert(String data) throws IoTDBConnectionException { + + private void insert(String data) throws IoTDBConnectionException, StatementExecutionException { String[] dataArray = data.split(","); String device = dataArray[0]; long time = Long.parseLong(dataArray[1]); @@ -120,7 +120,7 @@ public void prepareConsume() throws MQClientException { new String(msg.getBody()))); try { insert(new String(msg.getBody())); - } catch (IoTDBConnectionException e) { + } catch (Exception e) { logger.error(e.getMessage()); } } @@ -153,8 +153,8 @@ public static void main(String[] args) /** *Instantiate with specified consumer group name and specify name server addresses. */ - RocketMQConsumer consumer = new RocketMQConsumer(Constant.CONSUMER_GROUP, - Constant.SERVER_ADDRESS, + RocketMQConsumer consumer = new RocketMQConsumer(Constant.CONSUMER_GROUP, + Constant.SERVER_ADDRESS, Constant.IOTDB_CONNECTION_HOST, Constant.IOTDB_CONNECTION_PORT, Constant.IOTDB_CONNECTION_USER, diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBSQLException.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBSQLException.java index f924078278ca6..9403b36901a8c 100644 --- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBSQLException.java +++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBSQLException.java @@ -31,7 +31,7 @@ public IoTDBSQLException(String reason) { } public IoTDBSQLException(String reason, TSStatus status) { - super(reason, status.sqlState, status.statusType.code); + super(reason, status.message, status.code); } public IoTDBSQLException(Throwable cause) { diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java index 9ea181e9a4e3e..f0debfd99a720 100644 --- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java +++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java @@ -24,7 +24,6 @@ import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.*; import org.apache.thrift.TException; - import java.sql.*; import java.time.ZoneId; import java.util.ArrayList; @@ -258,41 +257,27 @@ public int[] executeBatch() throws SQLException { } } - private int[] executeBatchSQL() throws TException, SQLException { + private int[] executeBatchSQL() throws TException, BatchUpdateException { isCancelled = false; - TSExecuteBatchStatementReq execReq = new TSExecuteBatchStatementReq(sessionId, - batchSQLList); + TSExecuteBatchStatementReq execReq = new TSExecuteBatchStatementReq(sessionId, batchSQLList); TSExecuteBatchStatementResp execResp = client.executeBatchStatement(execReq); - if (execResp.getStatus().getStatusType().getCode() == TSStatusCode.SUCCESS_STATUS - .getStatusCode()) { - if (execResp.getResult() == null) { - return new int[0]; - } else { - List result = execResp.getResult(); - int len = result.size(); - int[] updateArray = new int[len]; - for (int i = 0; i < len; i++) { - updateArray[i] = result.get(i); - } - return updateArray; - } - } else { - BatchUpdateException exception; - if (execResp.getResult() == null) { - exception = new BatchUpdateException(execResp.getStatus().getStatusType().getMessage(), - new int[0]); - } else { - List result = execResp.getResult(); - int len = result.size(); - int[] updateArray = new int[len]; - for (int i = 0; i < len; i++) { - updateArray[i] = result.get(i); - } - exception = new BatchUpdateException(execResp.getStatus().getStatusType().getMessage(), - updateArray); + if (execResp.statusList == null) { + + } + int[] result = new int[execResp.statusList.size()]; + boolean allSuccess = true; + String message = ""; + for (int i = 0; i < result.length; i++) { + result[i] = execResp.statusList.get(i).code; + if (result[i] != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + allSuccess = false; + message = execResp.statusList.get(i).message; } - throw exception; } + if (!allSuccess) { + throw new BatchUpdateException(message, result); + } + return result; } @Override diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java index f19edd9500cd0..953f5a82e4b8c 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java @@ -29,12 +29,12 @@ import java.time.ZoneId; import java.util.ArrayList; import java.util.List; +import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementReq; import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementResp; import org.apache.iotdb.service.rpc.thrift.TSIService; import org.apache.iotdb.service.rpc.thrift.TSStatus; -import org.apache.iotdb.service.rpc.thrift.TSStatusType; import org.apache.thrift.TException; import org.junit.After; import org.junit.Before; @@ -51,8 +51,8 @@ public class BatchTest { private long sessionId; @Mock private IoTDBStatement statement; - private TSStatusType successStatus = new TSStatusType(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); - private TSStatusType errorStatus = new TSStatusType(TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), ""); + private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); + private TSStatus errorStatus = new TSStatus(TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), ""); private TSStatus Status_SUCCESS = new TSStatus(successStatus); private TSStatus Status_ERROR = new TSStatus(errorStatus); private TSExecuteBatchStatementResp resp; @@ -74,25 +74,26 @@ public void tearDown() throws Exception { @Test public void testExecuteBatchSQL1() throws SQLException, TException { Statement statement = connection.createStatement(); - resp = new TSExecuteBatchStatementResp(Status_SUCCESS); + resp = new TSExecuteBatchStatementResp(); + resp = RpcUtils.getTSBatchExecuteStatementResp(TSStatusCode.SUCCESS_STATUS); when(client.executeBatchStatement(any(TSExecuteBatchStatementReq.class))).thenReturn(resp); int[] result = statement.executeBatch(); - assertEquals(result.length, 0); + assertEquals(result.length, 1); - List resExpected = new ArrayList() { + List resExpected = new ArrayList() { { - add(Statement.SUCCESS_NO_INFO); - add(Statement.SUCCESS_NO_INFO); - add(Statement.SUCCESS_NO_INFO); - add(Statement.SUCCESS_NO_INFO); - add(Statement.SUCCESS_NO_INFO); - add(Statement.EXECUTE_FAILED); - add(Statement.SUCCESS_NO_INFO); - add(Statement.SUCCESS_NO_INFO); - add(Statement.EXECUTE_FAILED); + add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); + add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); + add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); + add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); + add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); + add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); + add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); + add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); + add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); } }; - resp.setResult(resExpected); + resp.setStatusList(resExpected); statement.addBatch("SET STORAGE GROUP TO root.ln.wf01.wt01"); statement.addBatch( @@ -112,9 +113,9 @@ public void testExecuteBatchSQL1() throws SQLException, TException { statement.addBatch( "insert into root.ln.wf01.wt01(timestamp,temperature) vvvvvv(1509465720000,20.092794)"); result = statement.executeBatch(); - assertEquals(result.length, resExpected.size()); - for (int i = 0; i < resExpected.size(); i++) { - assertEquals(result[i], (int) resExpected.get(i)); + assertEquals(resp.statusList.size(), result.length); + for (int i = 0; i < resp.statusList.size(); i++) { + assertEquals(resExpected.get(i).code, result[i]); } statement.clearBatch(); } @@ -122,7 +123,8 @@ public void testExecuteBatchSQL1() throws SQLException, TException { @Test(expected = BatchUpdateException.class) public void testExecuteBatchSQL2() throws SQLException, TException { Statement statement = connection.createStatement(); - resp = new TSExecuteBatchStatementResp(Status_ERROR); + resp = RpcUtils.getTSBatchExecuteStatementResp(TSStatusCode.SQL_PARSE_ERROR); + when(client.executeBatchStatement(any(TSExecuteBatchStatementReq.class))).thenReturn(resp); statement.executeBatch(); } @@ -131,21 +133,21 @@ public void testExecuteBatchSQL2() throws SQLException, TException { @Test public void testExecuteBatchSQL3() throws SQLException, TException { Statement statement = connection.createStatement(); - resp = new TSExecuteBatchStatementResp(Status_ERROR); - List resExpected = new ArrayList() { + resp = RpcUtils.getTSBatchExecuteStatementResp(Status_ERROR); + List resExpected = new ArrayList() { { - add(Statement.SUCCESS_NO_INFO); - add(Statement.EXECUTE_FAILED); + add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); + add(RpcUtils.getStatus(TSStatusCode.SQL_PARSE_ERROR)); } }; - resp.setResult(resExpected); + resp.setStatusList(resExpected); when(client.executeBatchStatement(any(TSExecuteBatchStatementReq.class))).thenReturn(resp); try { statement.executeBatch(); } catch (BatchUpdateException e) { int[] result = e.getUpdateCounts(); for (int i = 0; i < resExpected.size(); i++) { - assertEquals(result[i], (int) resExpected.get(i)); + assertEquals(resExpected.get(i).code, result[i]); } return; } diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java index 787c48b462a29..7f936146ceff1 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java @@ -21,10 +21,8 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; - import java.util.ArrayList; import java.util.List; - import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.*; import org.apache.thrift.TException; @@ -40,7 +38,7 @@ public class IoTDBConnectionTest { private TSIService.Iface client; private IoTDBConnection connection = new IoTDBConnection(); - private TSStatusType successStatus = new TSStatusType(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); + private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); private TSStatus Status_SUCCESS = new TSStatus(successStatus); private long sessionId; @@ -73,7 +71,7 @@ public void testGetTimeZone() throws IoTDBSQLException, TException { } @Test - public void testGetServerProperties() throws IoTDBSQLException, TException { + public void testGetServerProperties() throws TException { final String version = "v0.1"; @SuppressWarnings("serial") final List supportedAggregationTime = new ArrayList() { { diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java index b0522529edc5e..2ee1b1f0b8df1 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java @@ -48,7 +48,7 @@ public class IoTDBPreparedStatementTest { @Mock private Iface client; @Mock - private TSStatusType successStatus = new TSStatusType(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); + private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); private TSStatus Status_SUCCESS = new TSStatus(successStatus); private long queryId; private long sessionId; diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBQueryResultSetTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBQueryResultSetTest.java index 80ce9e43eb47a..7f1fa242c8615 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBQueryResultSetTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBQueryResultSetTest.java @@ -47,7 +47,6 @@ import org.apache.iotdb.service.rpc.thrift.TSIService; import org.apache.iotdb.service.rpc.thrift.TSQueryDataSet; import org.apache.iotdb.service.rpc.thrift.TSStatus; -import org.apache.iotdb.service.rpc.thrift.TSStatusType; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; import org.junit.Assert; import org.junit.Before; @@ -118,8 +117,7 @@ public class IoTDBQueryResultSetTest { @Mock private TSFetchResultsResp fetchResultsResp; - private TSStatusType successStatus = new TSStatusType(TSStatusCode.SUCCESS_STATUS.getStatusCode(), - ""); + private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); private TSStatus Status_SUCCESS = new TSStatus(successStatus); private ZoneId zoneID = ZoneId.systemDefault(); diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java index ebb17414f7fc9..31ccd997db7b2 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java @@ -29,7 +29,7 @@ import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataResp; import org.apache.iotdb.service.rpc.thrift.TSIService.Iface; import org.apache.iotdb.service.rpc.thrift.TSStatus; -import org.apache.iotdb.service.rpc.thrift.TSStatusType; +import org.apache.iotdb.service.rpc.thrift.TSStatus; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -49,7 +49,7 @@ public class IoTDBStatementTest { @Mock private TSFetchMetadataResp fetchMetadataResp; - private TSStatusType successStatus = new TSStatusType(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); + private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); private TSStatus Status_SUCCESS = new TSStatus(successStatus); private ZoneId zoneID = ZoneId.systemDefault(); diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java index c5fa18279995b..0b2b3a71600c6 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java @@ -21,7 +21,7 @@ import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.TSStatus; -import org.apache.iotdb.service.rpc.thrift.TSStatusType; +import org.apache.iotdb.service.rpc.thrift.TSStatus; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -103,15 +103,14 @@ public void testParseWrongPort() throws IoTDBURLException { @Test public void testVerifySuccess() { try { - TSStatusType successStatus = new TSStatusType(TSStatusCode.SUCCESS_STATUS.getStatusCode(), - ""); + TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); RpcUtils.verifySuccess(new TSStatus(successStatus)); } catch (Exception e) { fail(); } try { - TSStatusType errorStatus = new TSStatusType( + TSStatus errorStatus = new TSStatus( TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), ""); RpcUtils.verifySuccess(new TSStatus(errorStatus)); } catch (Exception e) { diff --git a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java index 18485dc21c639..372f70486bd6a 100644 --- a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java @@ -65,6 +65,7 @@ import org.apache.iotdb.db.service.ServiceType; import org.apache.iotdb.db.utils.FilePathUtils; import org.apache.iotdb.db.utils.UpgradeUtils; +import org.apache.iotdb.service.rpc.thrift.TSStatus; import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor; import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; @@ -276,7 +277,7 @@ public void insert(InsertPlan insertPlan) * * @return result of each row */ - public Integer[] insertBatch(BatchInsertPlan batchInsertPlan) throws StorageEngineException { + public TSStatus[] insertBatch(BatchInsertPlan batchInsertPlan) throws StorageEngineException { StorageGroupProcessor storageGroupProcessor; try { storageGroupProcessor = getProcessor(batchInsertPlan.getDeviceId()); diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java index e220f7cf99ec9..acc3475366d80 100755 --- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java @@ -80,7 +80,9 @@ import org.apache.iotdb.db.utils.CopyOnReadLinkedList; import org.apache.iotdb.db.utils.UpgradeUtils; import org.apache.iotdb.db.writelog.recover.TsFileRecoverPerformer; +import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; +import org.apache.iotdb.service.rpc.thrift.TSStatus; import org.apache.iotdb.tsfile.file.metadata.ChunkMetaData; import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; @@ -501,10 +503,10 @@ public void insert(InsertPlan insertPlan) throws QueryProcessException { } } - public Integer[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProcessException { + public TSStatus[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProcessException { writeLock(); try { - Integer[] results = new Integer[batchInsertPlan.getRowCount()]; + TSStatus[] results = new TSStatus[batchInsertPlan.getRowCount()]; /* * assume that batch has been sorted by client @@ -514,7 +516,8 @@ public Integer[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProces long currTime = batchInsertPlan.getTimes()[loc]; // skip points that do not satisfy TTL if (!checkTTL(currTime)) { - results[loc] = TSStatusCode.OUT_OF_TTL_ERROR.getStatusCode(); + results[loc] = RpcUtils.getStatus(TSStatusCode.OUT_OF_TTL_ERROR, + "time " + currTime + " in current line is out of TTL: " + dataTTL); loc++; } else { break; @@ -537,7 +540,7 @@ public Integer[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProces while (loc < batchInsertPlan.getRowCount()) { long time = batchInsertPlan.getTimes()[loc]; long curTimePartition = StorageEngine.fromTimeToTimePartition(time); - results[loc] = TSStatusCode.SUCCESS_STATUS.getStatusCode(); + results[loc] = RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); // start next partition if (curTimePartition != beforeTimePartition) { // insert last time partition @@ -593,18 +596,18 @@ private boolean checkTTL(long time) { * @param timePartitionId time partition id */ private void insertBatchToTsFileProcessor(BatchInsertPlan batchInsertPlan, - int start, int end, boolean sequence, Integer[] results, long timePartitionId) + int start, int end, boolean sequence, TSStatus[] results, long timePartitionId) throws QueryProcessException { // return when start <= end if (start >= end) { return; } - TsFileProcessor tsFileProcessor = getOrCreateTsFileProcessor(timePartitionId, - sequence); + TsFileProcessor tsFileProcessor = getOrCreateTsFileProcessor(timePartitionId, sequence); if (tsFileProcessor == null) { for (int i = start; i < end; i++) { - results[i] = TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(); + results[i] = RpcUtils.getStatus(TSStatusCode.INTERNAL_SERVER_ERROR, + "can not create TsFileProcessor, timePartitionId: " + timePartitionId); } return; } diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java index 6bce17457cc6a..3b9622e22d49c 100644 --- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java @@ -54,7 +54,9 @@ import org.apache.iotdb.db.utils.QueryUtils; import org.apache.iotdb.db.writelog.manager.MultiFileLogNodeManager; import org.apache.iotdb.db.writelog.node.WriteLogNode; +import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; +import org.apache.iotdb.service.rpc.thrift.TSStatus; import org.apache.iotdb.tsfile.file.metadata.ChunkMetaData; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding; @@ -183,7 +185,7 @@ public boolean insert(InsertPlan insertPlan) throws QueryProcessException { } public boolean insertBatch(BatchInsertPlan batchInsertPlan, int start, int end, - Integer[] results) throws QueryProcessException { + TSStatus[] results) throws QueryProcessException { if (workMemTable == null) { workMemTable = MemTablePool.getInstance().getAvailableMemTable(this); @@ -201,7 +203,7 @@ public boolean insertBatch(BatchInsertPlan batchInsertPlan, int start, int end, logger.error("{}: {} write WAL failed", storageGroupName, tsFileResource.getFile().getName(), e); for (int i = start; i < end; i++) { - results[i] = TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(); + results[i] = RpcUtils.getStatus(TSStatusCode.INTERNAL_SERVER_ERROR, e.getMessage()); } return false; } diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsPage.java b/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsPage.java index 6380150b4de92..f325a254c1473 100644 --- a/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsPage.java +++ b/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsPage.java @@ -100,8 +100,8 @@ public StringBuilder sqlRow() { for (int i = (list.size() - 1); i >= 0; i--) { sqlArgument = list.get(i); resp = sqlArgument.getTSExecuteStatementResp(); - errMsg = resp.getStatus().getStatusType().getMessage(); - statusCode = resp.getStatus().getStatusType().getCode(); + errMsg = resp.getStatus().message; + statusCode = resp.getStatus().code; String status; if (statusCode == 200) { status = "FINISHED"; diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/IPlanExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/IPlanExecutor.java index b2466dbcda823..cf09d6a9a71cd 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/executor/IPlanExecutor.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/IPlanExecutor.java @@ -28,6 +28,7 @@ import org.apache.iotdb.db.qp.physical.crud.DeletePlan; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; import org.apache.iotdb.db.query.context.QueryContext; +import org.apache.iotdb.service.rpc.thrift.TSStatus; import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException; import org.apache.iotdb.tsfile.read.common.Path; import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet; @@ -90,5 +91,5 @@ void update(Path path, long startTime, long endTime, String value) * * @return result of each row */ - Integer[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProcessException; + TSStatus[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProcessException; } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java index d0c1251a047f7..f62f22229850e 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java @@ -107,6 +107,7 @@ import org.apache.iotdb.db.utils.FileLoaderUtils; import org.apache.iotdb.db.utils.TypeInferenceUtils; import org.apache.iotdb.db.utils.UpgradeUtils; +import org.apache.iotdb.service.rpc.thrift.TSStatus; import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor; import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException; import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException; @@ -762,7 +763,7 @@ private TSEncoding getDefaultEncoding(TSDataType dataType) { } @Override - public Integer[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProcessException { + public TSStatus[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProcessException { try { String[] measurementList = batchInsertPlan.getMeasurements(); String deviceId = batchInsertPlan.getDeviceId(); @@ -780,14 +781,10 @@ public Integer[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProces } Path path = new Path(deviceId, measurementList[i]); TSDataType dataType = dataTypes[i]; - boolean result = mManager - .createTimeseries(path.getFullPath(), dataType, getDefaultEncoding(dataType), - TSFileDescriptor.getInstance().getConfig().getCompressor(), - Collections.emptyMap()); - if (result) { - StorageEngine.getInstance() - .addTimeSeries(path, dataType, getDefaultEncoding(dataType)); - } + mManager.createTimeseries(path.getFullPath(), dataType, getDefaultEncoding(dataType), + TSFileDescriptor.getInstance().getConfig().getCompressor(), + Collections.emptyMap()); + StorageEngine.getInstance().addTimeSeries(path, dataType, getDefaultEncoding(dataType)); } MNode measurementNode = node.getChild(measurementList[i]); if (measurementNode instanceof InternalMNode) { diff --git a/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java b/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java index 441a73dfbe6cd..26fe5f8349ddc 100644 --- a/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java +++ b/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java @@ -36,10 +36,10 @@ import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_USER; import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VALUE; import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VERSION; - import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementResp; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; @@ -131,7 +131,7 @@ private static TSExecuteStatementResp getNoTimeExecuteResp(List columns, private static TSExecuteStatementResp getExecuteResp(List columns, List dataTypes, boolean ignoreTimeStamp) { TSExecuteStatementResp resp = - TSServiceImpl.getTSExecuteStatementResp(TSServiceImpl.getStatus(TSStatusCode.SUCCESS_STATUS)); + RpcUtils.getTSExecuteStatementResp(TSStatusCode.SUCCESS_STATUS); resp.setIgnoreTimeStamp(ignoreTimeStamp); resp.setColumns(columns); resp.setDataTypeList(dataTypes); 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 409112e3b7326..535ade435ab34 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 @@ -18,13 +18,9 @@ */ package org.apache.iotdb.db.service; -import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES; -import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VALUE; - import java.io.IOException; import java.nio.ByteBuffer; import java.sql.SQLException; -import java.sql.Statement; import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; @@ -84,6 +80,7 @@ import org.apache.iotdb.db.tools.watermark.WatermarkEncoder; import org.apache.iotdb.db.utils.QueryDataSetUtils; import org.apache.iotdb.db.utils.SchemaUtils; +import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.ServerProperties; import org.apache.iotdb.service.rpc.thrift.TSBatchInsertionReq; @@ -94,7 +91,6 @@ import org.apache.iotdb.service.rpc.thrift.TSDeleteDataReq; import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementReq; import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementResp; -import org.apache.iotdb.service.rpc.thrift.TSExecuteInsertRowInBatchResp; import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementReq; import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementResp; import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataReq; @@ -112,7 +108,6 @@ import org.apache.iotdb.service.rpc.thrift.TSQueryNonAlignDataSet; import org.apache.iotdb.service.rpc.thrift.TSSetTimeZoneReq; import org.apache.iotdb.service.rpc.thrift.TSStatus; -import org.apache.iotdb.service.rpc.thrift.TSStatusType; import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException; import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException; import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; @@ -197,7 +192,7 @@ public TSOpenSessionResp openSession(TSOpenSessionReq req) throws TException { //check the version compatibility boolean compatible = checkCompatibility(req.getClient_protocol()); if (!compatible) { - tsStatus = getStatus(TSStatusCode.INCOMPATIBLE_VERSION, + tsStatus = RpcUtils.getStatus(TSStatusCode.INCOMPATIBLE_VERSION, "The version is incompatible, please upgrade to " + IoTDBConstant.VERSION); TSOpenSessionResp resp = new TSOpenSessionResp(tsStatus, TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2); @@ -205,21 +200,19 @@ public TSOpenSessionResp openSession(TSOpenSessionReq req) throws TException { return resp; } - tsStatus = getStatus(TSStatusCode.SUCCESS_STATUS, "Login successfully"); + tsStatus = RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS, "Login successfully"); sessionId = sessionIdGenerator.incrementAndGet(); sessionIdUsernameMap.put(sessionId, req.getUsername()); sessionIdZoneIdMap.put(sessionId, config.getZoneID()); currSessionId.set(sessionId); } else { - tsStatus = getStatus(TSStatusCode.WRONG_LOGIN_PASSWORD_ERROR); + tsStatus = RpcUtils.getStatus(TSStatusCode.WRONG_LOGIN_PASSWORD_ERROR); } TSOpenSessionResp resp = new TSOpenSessionResp(tsStatus, TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2); resp.setSessionId(sessionId); logger.info( - "{}: Login status: {}. User : {}", - IoTDBConstant.GLOBAL_DB_NAME, - tsStatus.getStatusType().getMessage(), + "{}: Login status: {}. User : {}", IoTDBConstant.GLOBAL_DB_NAME, tsStatus.message, req.getUsername()); return resp; @@ -235,9 +228,9 @@ public TSStatus closeSession(TSCloseSessionReq req) { long sessionId = req.getSessionId(); TSStatus tsStatus; if (sessionIdUsernameMap.remove(sessionId) == null) { - tsStatus = getStatus(TSStatusCode.NOT_LOGIN_ERROR); + tsStatus = RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR); } else { - tsStatus = getStatus(TSStatusCode.SUCCESS_STATUS); + tsStatus = RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); } sessionIdZoneIdMap.remove(sessionId); @@ -260,7 +253,7 @@ public TSStatus closeSession(TSCloseSessionReq req) { } if (!exceptions.isEmpty()) { return new TSStatus( - getStatus( + RpcUtils.getStatus( TSStatusCode.CLOSE_OPERATION_ERROR, String.format( "%d errors in closeOperation, see server logs for detail", exceptions.size()))); @@ -272,7 +265,7 @@ public TSStatus closeSession(TSCloseSessionReq req) { @Override public TSStatus cancelOperation(TSCancelOperationReq req) { // TODO implement - return getStatus(TSStatusCode.QUERY_NOT_ALLOWED, "Cancellation is not implemented"); + return RpcUtils.getStatus(TSStatusCode.QUERY_NOT_ALLOWED, "Cancellation is not implemented"); } @Override @@ -280,7 +273,7 @@ public TSStatus closeOperation(TSCloseOperationReq req) { logger.info("{}: receive close operation", IoTDBConstant.GLOBAL_DB_NAME); if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getStatus(TSStatusCode.NOT_LOGIN_ERROR); + return RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR); } try { // statement close @@ -299,42 +292,21 @@ public TSStatus closeOperation(TSCloseOperationReq req) { } catch (Exception e) { logger.error("Error in closeOperation : ", e); - return getStatus(TSStatusCode.CLOSE_OPERATION_ERROR, "Error in closeOperation"); + return RpcUtils.getStatus(TSStatusCode.CLOSE_OPERATION_ERROR, "Error in closeOperation"); } - return getStatus(TSStatusCode.SUCCESS_STATUS); + return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); } /** * release single operation resource */ - protected void releaseQueryResource(long queryId) throws StorageEngineException { + private void releaseQueryResource(long queryId) throws StorageEngineException { // remove the corresponding Physical Plan queryId2DataSet.remove(queryId); QueryResourceManager.getInstance().endQuery(queryId); } - /** - * convert from TSStatusCode to TSStatus according to status code and status message - * - * @param statusType status type - */ - static TSStatus getStatus(TSStatusCode statusType) { - TSStatusType statusCodeAndMessage = new TSStatusType(statusType.getStatusCode(), ""); - return new TSStatus(statusCodeAndMessage); - } - - /** - * convert from TSStatusCode to TSStatus, which has message appending with existed status message - * - * @param statusType status type - * @param appendMessage appending message - */ - private TSStatus getStatus(TSStatusCode statusType, String appendMessage) { - TSStatusType statusCodeAndMessage = new TSStatusType(statusType.getStatusCode(), appendMessage); - return new TSStatus(statusCodeAndMessage); - } - - protected TSDataType getSeriesType(String path) throws QueryProcessException, MetadataException { + private TSDataType getSeriesType(String path) throws QueryProcessException { try { return SchemaUtils.getSeriesType(path); } catch (MetadataException e) { @@ -347,7 +319,7 @@ public TSFetchMetadataResp fetchMetadata(TSFetchMetadataReq req) { TSStatus status; if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - status = getStatus(TSStatusCode.NOT_LOGIN_ERROR); + status = RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR); return new TSFetchMetadataResp(status); } @@ -357,24 +329,24 @@ public TSFetchMetadataResp fetchMetadata(TSFetchMetadataReq req) { case "METADATA_IN_JSON": String metadataInJson = getMetadataInString(); resp.setMetadataInJson(metadataInJson); - status = getStatus(TSStatusCode.SUCCESS_STATUS); + status = RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); break; case "COLUMN": resp.setDataType(getSeriesType(req.getColumnPath()).toString()); - status = getStatus(TSStatusCode.SUCCESS_STATUS); + status = RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); break; case "ALL_COLUMNS": resp.setColumnsList(getPaths(req.getColumnPath())); - status = getStatus(TSStatusCode.SUCCESS_STATUS); + status = RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); break; default: - status = getStatus(TSStatusCode.METADATA_ERROR, req.getType()); + status = RpcUtils.getStatus(TSStatusCode.METADATA_ERROR, req.getType()); break; } } catch (MetadataException | OutOfMemoryError | QueryProcessException e) { logger.error( String.format("Failed to fetch timeseries %s's metadata", req.getColumnPath()), e); - status = getStatus(TSStatusCode.METADATA_ERROR, e.getMessage()); + status = RpcUtils.getStatus(TSStatusCode.METADATA_ERROR, e.getMessage()); resp.setStatus(status); return resp; } @@ -447,31 +419,28 @@ private void execFlush(String statement) throws StorageGroupNotSetException { @Override public TSExecuteBatchStatementResp executeBatchStatement(TSExecuteBatchStatementReq req) { long t1 = System.currentTimeMillis(); - List result = new ArrayList<>(); + List result = new ArrayList<>(); try { if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getTSBatchExecuteStatementResp(getStatus(TSStatusCode.NOT_LOGIN_ERROR), null); + return RpcUtils.getTSBatchExecuteStatementResp(TSStatusCode.NOT_LOGIN_ERROR); } List statements = req.getStatements(); boolean isAllSuccessful = true; - StringBuilder batchErrorMessage = new StringBuilder(); for (String statement : statements) { long t2 = System.currentTimeMillis(); isAllSuccessful = - executeStatementInBatch(statement, batchErrorMessage, result, req.getSessionId()) + executeStatementInBatch(statement, result, req.getSessionId()) && isAllSuccessful; Measurement.INSTANCE.addOperationLatency(Operation.EXECUTE_ONE_SQL_IN_BATCH, t2); } if (isAllSuccessful) { - return getTSBatchExecuteStatementResp( - getStatus(TSStatusCode.SUCCESS_STATUS, "Execute batch statements successfully"), - result); + return RpcUtils.getTSBatchExecuteStatementResp( + TSStatusCode.SUCCESS_STATUS, "Execute batch statements successfully"); } else { - return getTSBatchExecuteStatementResp( - getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR, batchErrorMessage.toString()), result); + return RpcUtils.getTSBatchExecuteStatementResp(result); } } finally { Measurement.INSTANCE.addOperationLatency(Operation.EXECUTE_JDBC_BATCH, t1); @@ -480,8 +449,7 @@ public TSExecuteBatchStatementResp executeBatchStatement(TSExecuteBatchStatement // execute one statement of a batch. Currently, query is not allowed in a batch statement and // on finding queries in a batch, such query will be ignored and an error will be generated - private boolean executeStatementInBatch( - String statement, StringBuilder batchErrorMessage, List result, long sessionId) { + private boolean executeStatementInBatch(String statement, List result, long sessionId) { try { PhysicalPlan physicalPlan = processor.parseSQLToPhysicalPlan(statement, sessionIdZoneIdMap.get(sessionId)); @@ -489,36 +457,33 @@ private boolean executeStatementInBatch( throw new QueryInBatchStatementException(statement); } TSExecuteStatementResp resp = executeUpdateStatement(physicalPlan, sessionId); - if (resp.getStatus().getStatusType().getCode() - == TSStatusCode.SUCCESS_STATUS.getStatusCode()) { - result.add(Statement.SUCCESS_NO_INFO); + if (resp.getStatus().code == TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + result.add(resp.status); } else { - result.add(Statement.EXECUTE_FAILED); - batchErrorMessage.append(resp.getStatus().getStatusType().getCode()).append("\n"); + result.add(resp.status); return false; } } catch (ParseCancellationException e) { logger.debug(e.getMessage()); - result.add(Statement.EXECUTE_FAILED); - batchErrorMessage.append(TSStatusCode.SQL_PARSE_ERROR.getStatusCode()).append("\n"); + result.add(RpcUtils.getStatus(TSStatusCode.SQL_PARSE_ERROR, + "Statement format is not right: " + e.getMessage())); return false; } catch (SQLParserException e) { logger.error("Error occurred when executing {}, check metadata error: ", statement, e); - result.add(Statement.EXECUTE_FAILED); - batchErrorMessage.append(TSStatusCode.METADATA_ERROR.getStatusCode()).append("\n"); + result.add(RpcUtils.getStatus( + TSStatusCode.SQL_PARSE_ERROR, "Statement format is not right: " + e.getMessage())); return false; } catch (QueryProcessException e) { logger.info( "Error occurred when executing {}, meet error while parsing SQL to physical plan: {}", - statement, - e.getMessage()); - result.add(Statement.EXECUTE_FAILED); - batchErrorMessage.append(TSStatusCode.SQL_PARSE_ERROR.getStatusCode()).append("\n"); + statement, e.getMessage()); + result.add(RpcUtils.getStatus( + TSStatusCode.QUERY_PROCESS_ERROR, "Meet error in query process: " + e.getMessage())); return false; } catch (QueryInBatchStatementException e) { logger.info("Error occurred when executing {}, query statement not allowed: ", statement, e); - result.add(Statement.EXECUTE_FAILED); - batchErrorMessage.append(TSStatusCode.QUERY_NOT_ALLOWED.getStatusCode()).append("\n"); + result.add( + RpcUtils.getStatus(TSStatusCode.QUERY_NOT_ALLOWED, "query statement not allowed: " + statement)); return false; } return true; @@ -532,13 +497,13 @@ public TSExecuteStatementResp executeStatement(TSExecuteStatementReq req) { try { if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getTSExecuteStatementResp(getStatus(TSStatusCode.NOT_LOGIN_ERROR)); + return RpcUtils.getTSExecuteStatementResp(TSStatusCode.NOT_LOGIN_ERROR); } String statement = req.getStatement(); if (execAdminCommand(statement, req.getSessionId())) { - return getTSExecuteStatementResp( - getStatus(TSStatusCode.SUCCESS_STATUS, "ADMIN_COMMAND_SUCCESS")); + return RpcUtils.getTSExecuteStatementResp( + RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS, "ADMIN_COMMAND_SUCCESS")); } PhysicalPlan physicalPlan = processor.parseSQLToPhysicalPlan(statement, sessionIdZoneIdMap.get(req.getSessionId())); @@ -561,20 +526,20 @@ public TSExecuteStatementResp executeStatement(TSExecuteStatementReq req) { } } catch (ParseCancellationException e) { logger.debug(e.getMessage()); - return getTSExecuteStatementResp(getStatus(TSStatusCode.SQL_PARSE_ERROR, e.getMessage())); + return RpcUtils.getTSExecuteStatementResp(TSStatusCode.SQL_PARSE_ERROR, e.getMessage()); } catch (SQLParserException e) { logger.error("check metadata error: ", e); - return getTSExecuteStatementResp( - getStatus(TSStatusCode.METADATA_ERROR, "Check metadata error: " + e.getMessage())); + return RpcUtils.getTSExecuteStatementResp( + TSStatusCode.METADATA_ERROR, "Check metadata error: " + e.getMessage()); } catch (QueryProcessException e) { logger.info(ERROR_PARSING_SQL, e.getMessage()); - return getTSExecuteStatementResp( - getStatus( - TSStatusCode.SQL_PARSE_ERROR, "Statement format is not right: " + e.getMessage())); + return RpcUtils.getTSExecuteStatementResp( + RpcUtils.getStatus(TSStatusCode.QUERY_PROCESS_ERROR, + "Meet error in query process: " + e.getMessage())); } catch (StorageEngineException e) { logger.info(ERROR_PARSING_SQL, e.getMessage()); - return getTSExecuteStatementResp( - getStatus(TSStatusCode.READ_ONLY_SYSTEM_ERROR, e.getMessage())); + return RpcUtils.getTSExecuteStatementResp( + RpcUtils.getStatus(TSStatusCode.READ_ONLY_SYSTEM_ERROR, e.getMessage())); } } @@ -587,7 +552,7 @@ public TSExecuteStatementResp executeQueryStatement(TSExecuteStatementReq req) { if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getTSExecuteStatementResp(getStatus(TSStatusCode.NOT_LOGIN_ERROR)); + return RpcUtils.getTSExecuteStatementResp(TSStatusCode.NOT_LOGIN_ERROR); } String statement = req.getStatement(); @@ -597,12 +562,12 @@ public TSExecuteStatementResp executeQueryStatement(TSExecuteStatementReq req) { processor.parseSQLToPhysicalPlan(statement, sessionIdZoneIdMap.get(req.getSessionId())); } catch (QueryProcessException | SQLParserException e) { logger.info(ERROR_PARSING_SQL, e.getMessage()); - return getTSExecuteStatementResp(getStatus(TSStatusCode.SQL_PARSE_ERROR, e.getMessage())); + return RpcUtils.getTSExecuteStatementResp(TSStatusCode.SQL_PARSE_ERROR, e.getMessage()); } if (!physicalPlan.isQuery()) { - return getTSExecuteStatementResp( - getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR, "Statement is not a query statement.")); + return RpcUtils.getTSExecuteStatementResp( + TSStatusCode.EXECUTE_STATEMENT_ERROR, "Statement is not a query statement."); } resp = internalExecuteQueryStatement( @@ -617,12 +582,12 @@ public TSExecuteStatementResp executeQueryStatement(TSExecuteStatementReq req) { return resp; } catch (ParseCancellationException e) { logger.debug(e.getMessage()); - return getTSExecuteStatementResp(getStatus(TSStatusCode.SQL_PARSE_ERROR, - "Statement format is not right: " + e.getMessage())); + return RpcUtils.getTSExecuteStatementResp(TSStatusCode.SQL_PARSE_ERROR, + "Statement format is not right: " + e.getMessage()); } catch (SQLParserException e) { logger.error("check metadata error: ", e); - return getTSExecuteStatementResp( - getStatus(TSStatusCode.METADATA_ERROR, "Check metadata error: " + e.getMessage())); + return RpcUtils.getTSExecuteStatementResp( + TSStatusCode.METADATA_ERROR, "Check metadata error: " + e.getMessage()); } } @@ -670,8 +635,7 @@ private TSExecuteStatementResp internalExecuteQueryStatement( return resp; } catch (Exception e) { logger.error("{}: Internal server error: ", IoTDBConstant.GLOBAL_DB_NAME, e); - return getTSExecuteStatementResp( - getStatus(TSStatusCode.INTERNAL_SERVER_ERROR, e.getMessage())); + return RpcUtils.getTSExecuteStatementResp(TSStatusCode.INTERNAL_SERVER_ERROR, e.getMessage()); } finally { Measurement.INSTANCE.addOperationLatency(Operation.EXECUTE_QUERY, t1); } @@ -734,9 +698,8 @@ private TSExecuteStatementResp getAuthQueryColumnHeaders(PhysicalPlan plan) { case LIST_USER_PRIVILEGE: return StaticResps.LIST_USER_PRIVILEGE_RESP; default: - return getTSExecuteStatementResp( - getStatus( - TSStatusCode.SQL_PARSE_ERROR, + return RpcUtils.getTSExecuteStatementResp( + RpcUtils.getStatus(TSStatusCode.SQL_PARSE_ERROR, String.format("%s is not an auth query", authorPlan.getAuthorType()))); } } @@ -752,13 +715,13 @@ private TSExecuteStatementResp getQueryColumnHeaders(PhysicalPlan physicalPlan, // check permissions if (!checkAuthorization(physicalPlan.getPaths(), physicalPlan, username)) { - return getTSExecuteStatementResp( - getStatus( - TSStatusCode.NO_PERMISSION_ERROR, + return RpcUtils.getTSExecuteStatementResp( + RpcUtils.getStatus(TSStatusCode.NO_PERMISSION_ERROR, "No permissions for this operation " + physicalPlan.getOperatorType())); } - TSExecuteStatementResp resp = getTSExecuteStatementResp(getStatus(TSStatusCode.SUCCESS_STATUS)); + TSExecuteStatementResp resp = RpcUtils + .getTSExecuteStatementResp(TSStatusCode.SUCCESS_STATUS); // align by device query QueryPlan plan = (QueryPlan) physicalPlan; @@ -805,11 +768,7 @@ private void getWideQueryHeaders( } for (String column : respColumns) { - try { - columnTypes.add(getSeriesType(column).toString()); - } catch (MetadataException e) { - throw new QueryProcessException(e); - } + columnTypes.add(getSeriesType(column).toString()); } } @@ -856,25 +815,17 @@ private void getAlignByDeviceQueryHeaders( plan.setPaths(null); } - private void getLastQueryHeaders( - QueryPlan plan, List respColumns, List columnTypes) - throws TException, QueryProcessException { - respColumns.add(COLUMN_TIMESERIES); - respColumns.add(COLUMN_VALUE); - columnTypes.add(TSDataType.TEXT.toString()); - columnTypes.add(TSDataType.TEXT.toString()); - } @Override public TSFetchResultsResp fetchResults(TSFetchResultsReq req) { try { if (!checkLogin(req.getSessionId())) { - return getTSFetchResultsResp(getStatus(TSStatusCode.NOT_LOGIN_ERROR)); + return RpcUtils.getTSFetchResultsResp(TSStatusCode.NOT_LOGIN_ERROR); } if (!queryId2DataSet.containsKey(req.queryId)) { - return getTSFetchResultsResp( - getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR, "Has not executed query")); + return RpcUtils.getTSFetchResultsResp( + RpcUtils.getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR, "Has not executed query")); } QueryDataSet queryDataSet = queryId2DataSet.get(req.queryId); @@ -886,11 +837,8 @@ public TSFetchResultsResp fetchResults(TSFetchResultsReq req) { QueryResourceManager.getInstance().endQuery(req.queryId); queryId2DataSet.remove(req.queryId); } - TSFetchResultsResp resp = - getTSFetchResultsResp( - getStatus( - TSStatusCode.SUCCESS_STATUS, - "FetchResult successfully. Has more result: " + hasResultSet)); + TSFetchResultsResp resp = RpcUtils.getTSFetchResultsResp( + TSStatusCode.SUCCESS_STATUS, "FetchResult successfully. Has more result: " + hasResultSet); resp.setHasResultSet(hasResultSet); resp.setQueryDataSet(result); resp.setIsAlign(true); @@ -910,10 +858,8 @@ public TSFetchResultsResp fetchResults(TSFetchResultsReq req) { queryId2DataSet.remove(req.queryId); } TSFetchResultsResp resp = - getTSFetchResultsResp( - getStatus( - TSStatusCode.SUCCESS_STATUS, - "FetchResult successfully. Has more result: " + hasResultSet)); + RpcUtils.getTSFetchResultsResp(TSStatusCode.SUCCESS_STATUS, + "FetchResult successfully. Has more result: " + hasResultSet); resp.setHasResultSet(hasResultSet); resp.setNonAlignQueryDataSet(nonAlignResult); resp.setIsAlign(false); @@ -921,7 +867,7 @@ public TSFetchResultsResp fetchResults(TSFetchResultsReq req) { } } catch (Exception e) { logger.error("{}: Internal server error: ", IoTDBConstant.GLOBAL_DB_NAME, e); - return getTSFetchResultsResp(getStatus(TSStatusCode.INTERNAL_SERVER_ERROR, e.getMessage())); + return RpcUtils.getTSFetchResultsResp(TSStatusCode.INTERNAL_SERVER_ERROR, e.getMessage()); } } @@ -1002,7 +948,7 @@ private QueryDataSet createQueryDataSet(long queryId, PhysicalPlan physicalPlan) return queryDataSet; } - protected QueryContext genQueryContext(long queryId) { + private QueryContext genQueryContext(long queryId) { return new QueryContext(queryId); } @@ -1011,14 +957,14 @@ public TSExecuteStatementResp executeUpdateStatement(TSExecuteStatementReq req) try { if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getTSExecuteStatementResp(getStatus(TSStatusCode.NOT_LOGIN_ERROR)); + return RpcUtils.getTSExecuteStatementResp(TSStatusCode.NOT_LOGIN_ERROR); } String statement = req.getStatement(); return executeUpdateStatement(statement, req.getSessionId()); } catch (Exception e) { logger.error("{}: server Internal Error: ", IoTDBConstant.GLOBAL_DB_NAME, e); - return getTSExecuteStatementResp( - getStatus(TSStatusCode.INTERNAL_SERVER_ERROR, e.getMessage())); + return RpcUtils.getTSExecuteStatementResp( + RpcUtils.getStatus(TSStatusCode.INTERNAL_SERVER_ERROR, e.getMessage())); } } @@ -1029,7 +975,7 @@ private TSExecuteStatementResp executeUpdateStatement(PhysicalPlan plan, long se } status = executePlan(plan); - TSExecuteStatementResp resp = getTSExecuteStatementResp(status); + TSExecuteStatementResp resp = RpcUtils.getTSExecuteStatementResp(status); long queryId = generateQueryId(false); resp.setQueryId(queryId); return resp; @@ -1050,12 +996,12 @@ private TSExecuteStatementResp executeUpdateStatement(String statement, long ses physicalPlan = processor.parseSQLToPhysicalPlan(statement, sessionIdZoneIdMap.get(sessionId)); } catch (QueryProcessException | SQLParserException e) { logger.info(ERROR_PARSING_SQL, e.getMessage()); - return getTSExecuteStatementResp(getStatus(TSStatusCode.SQL_PARSE_ERROR, e.getMessage())); + return RpcUtils.getTSExecuteStatementResp(TSStatusCode.SQL_PARSE_ERROR, e.getMessage()); } if (physicalPlan.isQuery()) { - return getTSExecuteStatementResp( - getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR, "Statement is a query statement.")); + return RpcUtils.getTSExecuteStatementResp( + TSStatusCode.EXECUTE_STATEMENT_ERROR, "Statement is a query statement."); } return executeUpdateStatement(physicalPlan, sessionId); @@ -1079,30 +1025,7 @@ private boolean checkAuthorization(List paths, PhysicalPlan plan, String u return AuthorityChecker.check(username, paths, plan.getOperatorType(), targetUser); } - static TSExecuteStatementResp getTSExecuteStatementResp(TSStatus status) { - TSExecuteStatementResp resp = new TSExecuteStatementResp(); - TSStatus tsStatus = new TSStatus(status); - resp.setStatus(tsStatus); - return resp; - } - - private TSExecuteBatchStatementResp getTSBatchExecuteStatementResp( - TSStatus status, List result) { - TSExecuteBatchStatementResp resp = new TSExecuteBatchStatementResp(); - TSStatus tsStatus = new TSStatus(status); - resp.setStatus(tsStatus); - resp.setResult(result); - return resp; - } - - private TSFetchResultsResp getTSFetchResultsResp(TSStatus status) { - TSFetchResultsResp resp = new TSFetchResultsResp(); - TSStatus tsStatus = new TSStatus(status); - resp.setStatus(tsStatus); - return resp; - } - - protected void handleClientExit() { + void handleClientExit() { Long sessionId = currSessionId.get(); if (sessionId != null) { TSCloseSessionReq req = new TSCloseSessionReq(sessionId); @@ -1115,14 +1038,14 @@ public TSGetTimeZoneResp getTimeZone(long sessionId) { TSStatus tsStatus; TSGetTimeZoneResp resp = null; try { - tsStatus = getStatus(TSStatusCode.SUCCESS_STATUS); + tsStatus = RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); ZoneId zoneId = sessionIdZoneIdMap.get(sessionId); if (zoneId != null) { resp = new TSGetTimeZoneResp(tsStatus, zoneId.toString()); } } catch (Exception e) { logger.error("meet error while generating time zone.", e); - tsStatus = getStatus(TSStatusCode.GENERATE_TIME_ZONE_ERROR); + tsStatus = RpcUtils.getStatus(TSStatusCode.GENERATE_TIME_ZONE_ERROR); resp = new TSGetTimeZoneResp(tsStatus, "Unknown time zone"); } return resp; @@ -1134,10 +1057,10 @@ public TSStatus setTimeZone(TSSetTimeZoneReq req) { try { String timeZoneID = req.getTimeZone(); sessionIdZoneIdMap.put(req.getSessionId(), ZoneId.of(timeZoneID)); - tsStatus = getStatus(TSStatusCode.SUCCESS_STATUS); + tsStatus = RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); } catch (Exception e) { logger.error("meet error while setting time zone.", e); - tsStatus = getStatus(TSStatusCode.SET_TIME_ZONE_ERROR); + tsStatus = RpcUtils.getStatus(TSStatusCode.SET_TIME_ZONE_ERROR); } return new TSStatus(tsStatus); } @@ -1155,11 +1078,11 @@ public ServerProperties getProperties() { } @Override - public TSExecuteInsertRowInBatchResp insertRowInBatch(TSInsertInBatchReq req) { - TSExecuteInsertRowInBatchResp resp = new TSExecuteInsertRowInBatchResp(); + public TSExecuteBatchStatementResp insertRowInBatch(TSInsertInBatchReq req) { + TSExecuteBatchStatementResp resp = new TSExecuteBatchStatementResp(); if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - resp.addToStatusList(getStatus(TSStatusCode.NOT_LOGIN_ERROR)); + resp.addToStatusList(RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR)); return resp; } @@ -1171,7 +1094,7 @@ public TSExecuteInsertRowInBatchResp insertRowInBatch(TSInsertInBatchReq req) { plan.setValues(req.getValuesList().get(i).toArray(new String[0])); TSStatus status = checkAuthority(plan, req.getSessionId()); if (status != null) { - resp.addToStatusList(new TSStatus(status)); + resp.addToStatusList(status); } else { resp.addToStatusList(executePlan(plan)); } @@ -1183,32 +1106,26 @@ public TSExecuteInsertRowInBatchResp insertRowInBatch(TSInsertInBatchReq req) { @Override public TSExecuteBatchStatementResp testInsertBatch(TSBatchInsertionReq req) { logger.debug("Test insert batch request receive."); - TSExecuteBatchStatementResp resp = new TSExecuteBatchStatementResp(); - resp.setStatus(getStatus(TSStatusCode.SUCCESS_STATUS)); - resp.setResult(Collections.emptyList()); - return resp; + return RpcUtils.getTSBatchExecuteStatementResp(TSStatusCode.SUCCESS_STATUS); } @Override public TSStatus testInsertRow(TSInsertReq req) { logger.debug("Test insert row request receive."); - return getStatus(TSStatusCode.SUCCESS_STATUS); + return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); } @Override - public TSExecuteInsertRowInBatchResp testInsertRowInBatch(TSInsertInBatchReq req) { + public TSExecuteBatchStatementResp testInsertRowInBatch(TSInsertInBatchReq req) { logger.debug("Test insert row in batch request receive."); - - TSExecuteInsertRowInBatchResp resp = new TSExecuteInsertRowInBatchResp(); - resp.addToStatusList(getStatus(TSStatusCode.SUCCESS_STATUS)); - return resp; + return RpcUtils.getTSBatchExecuteStatementResp(TSStatusCode.SUCCESS_STATUS); } @Override public TSStatus insert(TSInsertReq req) { if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getStatus(TSStatusCode.NOT_LOGIN_ERROR); + return RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR); } InsertPlan plan = new InsertPlan(); @@ -1219,16 +1136,16 @@ public TSStatus insert(TSInsertReq req) { TSStatus status = checkAuthority(plan, req.getSessionId()); if (status != null) { - return new TSStatus(status); + return status; } - return new TSStatus(executePlan(plan)); + return executePlan(plan); } @Override public TSStatus deleteData(TSDeleteDataReq req) { if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getStatus(TSStatusCode.NOT_LOGIN_ERROR); + return RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR); } DeletePlan plan = new DeletePlan(); @@ -1252,7 +1169,7 @@ public TSExecuteBatchStatementResp insertBatch(TSBatchInsertionReq req) { try { if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getTSBatchExecuteStatementResp(getStatus(TSStatusCode.NOT_LOGIN_ERROR), null); + return RpcUtils.getTSBatchExecuteStatementResp(TSStatusCode.NOT_LOGIN_ERROR); } BatchInsertPlan batchInsertPlan = new BatchInsertPlan(req.deviceId, req.measurements); @@ -1266,30 +1183,30 @@ public TSExecuteBatchStatementResp insertBatch(TSBatchInsertionReq req) { boolean isAllSuccessful = true; TSStatus status = checkAuthority(batchInsertPlan, req.getSessionId()); if (status != null) { - return new TSExecuteBatchStatementResp(status); + return RpcUtils.getTSBatchExecuteStatementResp(status); } - Integer[] results = executor.insertBatch(batchInsertPlan); + TSStatus[] tsStatusArray = executor.insertBatch(batchInsertPlan); - for (Integer result : results) { - if (result != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + for (TSStatus tsStatus : tsStatusArray) { + if (tsStatus.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { isAllSuccessful = false; break; } } if (isAllSuccessful) { - logger.debug("Insert one RowBatch successfully"); - return getTSBatchExecuteStatementResp( - getStatus(TSStatusCode.SUCCESS_STATUS), Arrays.asList(results)); + if (logger.isDebugEnabled()) { + logger.debug("Insert one RowBatch successfully"); + } + return RpcUtils.getTSBatchExecuteStatementResp(TSStatusCode.SUCCESS_STATUS); } else { logger.debug("Insert one RowBatch failed!"); - return getTSBatchExecuteStatementResp( - getStatus(TSStatusCode.INTERNAL_SERVER_ERROR), Arrays.asList(results)); + return RpcUtils.getTSBatchExecuteStatementResp(Arrays.asList(tsStatusArray)); } } catch (Exception e) { logger.info("{}: error occurs when executing statements", IoTDBConstant.GLOBAL_DB_NAME, e); - return getTSBatchExecuteStatementResp( - getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR, e.getMessage()), null); + return RpcUtils + .getTSBatchExecuteStatementResp(TSStatusCode.EXECUTE_STATEMENT_ERROR, e.getMessage()); } finally { Measurement.INSTANCE.addOperationLatency(Operation.EXECUTE_RPC_BATCH_INSERT, t1); } @@ -1299,7 +1216,7 @@ public TSExecuteBatchStatementResp insertBatch(TSBatchInsertionReq req) { public TSStatus setStorageGroup(long sessionId, String storageGroup) { if (!checkLogin(sessionId)) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getStatus(TSStatusCode.NOT_LOGIN_ERROR); + return RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR); } SetStorageGroupPlan plan = new SetStorageGroupPlan(new Path(storageGroup)); @@ -1314,7 +1231,7 @@ public TSStatus setStorageGroup(long sessionId, String storageGroup) { public TSStatus deleteStorageGroups(long sessionId, List storageGroups) { if (!checkLogin(sessionId)) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getStatus(TSStatusCode.NOT_LOGIN_ERROR); + return RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR); } List storageGroupList = new ArrayList<>(); for (String storageGroup : storageGroups) { @@ -1332,7 +1249,7 @@ public TSStatus deleteStorageGroups(long sessionId, List storageGroups) public TSStatus createTimeseries(TSCreateTimeseriesReq req) { if (!checkLogin(req.getSessionId())) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getStatus(TSStatusCode.NOT_LOGIN_ERROR); + return RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR); } CreateTimeSeriesPlan plan = new CreateTimeSeriesPlan( @@ -1352,7 +1269,7 @@ public TSStatus createTimeseries(TSCreateTimeseriesReq req) { public TSStatus deleteTimeseries(long sessionId, List paths) { if (!checkLogin(sessionId)) { logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME); - return getStatus(TSStatusCode.NOT_LOGIN_ERROR); + return RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR); } List pathList = new ArrayList<>(); for (String path : paths) { @@ -1377,29 +1294,29 @@ private TSStatus checkAuthority(PhysicalPlan plan, long sessionId) { List paths = plan.getPaths(); try { if (!checkAuthorization(paths, plan, sessionIdUsernameMap.get(sessionId))) { - return getStatus( + return RpcUtils.getStatus( TSStatusCode.NO_PERMISSION_ERROR, "No permissions for this operation " + plan.getOperatorType().toString()); } } catch (AuthException e) { logger.error("meet error while checking authorization.", e); - return getStatus(TSStatusCode.UNINITIALIZED_AUTH_ERROR, e.getMessage()); + return RpcUtils.getStatus(TSStatusCode.UNINITIALIZED_AUTH_ERROR, e.getMessage()); } return null; } - protected TSStatus executePlan(PhysicalPlan plan) { + private TSStatus executePlan(PhysicalPlan plan) { boolean execRet; try { execRet = executeNonQuery(plan); } catch (QueryProcessException e) { logger.debug("meet error while processing non-query. ", e); - return new TSStatus(new TSStatusType(e.getErrorCode(), e.getMessage())); + return new TSStatus(e.getErrorCode(), e.getMessage()); } return execRet - ? getStatus(TSStatusCode.SUCCESS_STATUS, "Execute successfully") - : getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR); + ? RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS, "Execute successfully") + : RpcUtils.getStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR); } private long generateQueryId(boolean isDataQuery) { 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 70a9e72f9f0d7..1f377c55ce5a8 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 void loadTsFileTestWithAutoCreateSchema() throws SQLException { } catch (Exception e) { hasError = true; Assert.assertEquals( - "401: Statement format is not right: Please check the statement: load [FILE] true/false [storage group level]", + "411: Meet error in query process: 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 a10d9f3c34536..2189c7b1d8ccd 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 @@ -413,7 +413,7 @@ public void selectWhereUnknownTimeSeries() throws ClassNotFoundException { fail("not throw exception when unknown time series in where clause"); } catch (SQLException e) { assertEquals( - "401: Statement format is not right: Filter has some time series don't correspond to any known time series", + "411: Meet error in query process: Filter has some time series don't correspond to any known time series", e.getMessage()); } } @@ -431,7 +431,7 @@ public void selectWhereUnknownTimeSeriesFromRoot() throws ClassNotFoundException } catch (SQLException e) { e.printStackTrace(); assertEquals( - "401: Statement format is not right: org.apache.iotdb.db.exception.metadata.PathNotExistException: Path [root.vehicle.d0.s10] does not exist", + "411: Meet error in query process: org.apache.iotdb.db.exception.metadata.PathNotExistException: Path [root.vehicle.d0.s10] does not exist", e.getMessage()); } } diff --git a/service-rpc/src/main/java/org/apache/iotdb/rpc/BatchExecutionException.java b/service-rpc/src/main/java/org/apache/iotdb/rpc/BatchExecutionException.java new file mode 100644 index 0000000000000..bce1d268f8e0e --- /dev/null +++ b/service-rpc/src/main/java/org/apache/iotdb/rpc/BatchExecutionException.java @@ -0,0 +1,45 @@ +/* + * 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. + */ +package org.apache.iotdb.rpc; + +import java.util.List; +import org.apache.iotdb.service.rpc.thrift.TSStatus; + +public class BatchExecutionException extends Exception{ + + private List statusList; + + public BatchExecutionException(String message) { + super(message); + } + + public BatchExecutionException(List statusList) { + this.statusList = statusList; + } + + public BatchExecutionException(List statusList, String message) { + super(message); + this.statusList = statusList; + } + + public List getStatusList() { + return statusList; + } + +} 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 8b2e956d419f0..1e909b3c8beaa 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 @@ -19,6 +19,10 @@ package org.apache.iotdb.rpc; import java.lang.reflect.Proxy; +import java.util.List; +import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementResp; +import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementResp; +import org.apache.iotdb.service.rpc.thrift.TSFetchResultsResp; import org.apache.iotdb.service.rpc.thrift.TSIService; import org.apache.iotdb.service.rpc.thrift.TSStatus; @@ -35,11 +39,93 @@ public static TSIService.Iface newSynchronizedClient(TSIService.Iface client) { * @param status -status */ public static void verifySuccess(TSStatus status) throws StatementExecutionException { - if (status.getStatusType().getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + if (status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { throw new StatementExecutionException(String.format("%d: %s", - status.getStatusType().getCode(), - status.getStatusType().getMessage())); + status.code, status.message)); } } + public static void verifySuccess(List statuses) throws BatchExecutionException { + for (TSStatus status : statuses) { + if (status.code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + throw new BatchExecutionException(statuses, status.message); + } + } + } + + /** + * convert from TSStatusCode to TSStatus according to status code and status message + */ + public static TSStatus getStatus(TSStatusCode tsStatusCode) { + return new TSStatus(tsStatusCode.getStatusCode(), ""); + } + + /** + * convert from TSStatusCode to TSStatus, which has message appending with existed status message + * + * @param tsStatusCode status type + * @param message appending message + */ + public static TSStatus getStatus(TSStatusCode tsStatusCode, String message) { + return new TSStatus(tsStatusCode.getStatusCode(), message); + } + + public static TSExecuteStatementResp getTSExecuteStatementResp(TSStatusCode tsStatusCode) { + TSStatus status = getStatus(tsStatusCode); + return getTSExecuteStatementResp(status); + } + + public static TSExecuteStatementResp getTSExecuteStatementResp(TSStatusCode tsStatusCode, String message) { + TSStatus status = getStatus(tsStatusCode, message); + return getTSExecuteStatementResp(status); + } + + public static TSExecuteStatementResp getTSExecuteStatementResp(TSStatus status) { + TSExecuteStatementResp resp = new TSExecuteStatementResp(); + TSStatus tsStatus = new TSStatus(status); + resp.setStatus(tsStatus); + return resp; + } + + + public static TSExecuteBatchStatementResp getTSBatchExecuteStatementResp(TSStatusCode tsStatusCode) { + TSStatus status = getStatus(tsStatusCode); + return getTSBatchExecuteStatementResp(status); + } + + public static TSExecuteBatchStatementResp getTSBatchExecuteStatementResp(TSStatusCode tsStatusCode, String message) { + TSStatus status = getStatus(tsStatusCode, message); + return getTSBatchExecuteStatementResp(status); + } + + public static TSExecuteBatchStatementResp getTSBatchExecuteStatementResp(TSStatus status) { + TSExecuteBatchStatementResp resp = new TSExecuteBatchStatementResp(); + resp.addToStatusList(status); + return resp; + } + + public static TSExecuteBatchStatementResp getTSBatchExecuteStatementResp(List statusList) { + TSExecuteBatchStatementResp resp = new TSExecuteBatchStatementResp(); + resp.setStatusList(statusList); + return resp; + } + + + public static TSFetchResultsResp getTSFetchResultsResp(TSStatusCode tsStatusCode) { + TSStatus status = getStatus(tsStatusCode); + return getTSFetchResultsResp(status); + } + + public static TSFetchResultsResp getTSFetchResultsResp(TSStatusCode tsStatusCode, String appendMessage) { + TSStatus status = getStatus(tsStatusCode, appendMessage); + return getTSFetchResultsResp(status); + } + + public static TSFetchResultsResp getTSFetchResultsResp(TSStatus status) { + TSFetchResultsResp resp = new TSFetchResultsResp(); + TSStatus tsStatus = new TSStatus(status); + resp.setStatus(tsStatus); + return resp; + } + } diff --git a/service-rpc/src/main/thrift/rpc.thrift b/service-rpc/src/main/thrift/rpc.thrift index fb96f02d3fc13..091316bfcdce5 100644 --- a/service-rpc/src/main/thrift/rpc.thrift +++ b/service-rpc/src/main/thrift/rpc.thrift @@ -19,18 +19,11 @@ namespace java org.apache.iotdb.service.rpc.thrift // The return status code and message in each response. -struct TSStatusType { +struct TSStatus { 1: required i32 code 2: required string message } -// The return status of a remote request -struct TSStatus { - 1: required TSStatusType statusType - 2: optional list infoMessages - 3: optional string sqlState // as defined in the ISO/IEF CLIENT specification -} - struct TSExecuteStatementResp { 1: required TSStatus status 2: optional i64 queryId @@ -97,17 +90,11 @@ struct TSExecuteStatementReq { 4: optional i32 fetchSize } -struct TSExecuteInsertRowInBatchResp{ +struct TSExecuteBatchStatementResp{ 1: required i64 sessionId 2: required list statusList } -struct TSExecuteBatchStatementResp{ - 1: required TSStatus status - // For each value in result, Statement.SUCCESS_NO_INFO represents success, Statement.EXECUTE_FAILED represents fail otherwise. - 2: optional list result -} - struct TSExecuteBatchStatementReq{ // The session to execute the statement against 1: required i64 sessionId @@ -280,13 +267,13 @@ service TSIService { TSExecuteBatchStatementResp insertBatch(1:TSBatchInsertionReq req); - TSExecuteInsertRowInBatchResp insertRowInBatch(1:TSInsertInBatchReq req); + TSExecuteBatchStatementResp insertRowInBatch(1:TSInsertInBatchReq req); TSExecuteBatchStatementResp testInsertBatch(1:TSBatchInsertionReq req); TSStatus testInsertRow(1:TSInsertReq req); - TSExecuteInsertRowInBatchResp testInsertRowInBatch(1:TSInsertInBatchReq req); + TSExecuteBatchStatementResp testInsertRowInBatch(1:TSInsertInBatchReq req); TSStatus deleteData(1:TSDeleteDataReq req); 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 3b5ba5bc4e838..5bc52915382ad 100644 --- a/session/src/main/java/org/apache/iotdb/session/Session.java +++ b/session/src/main/java/org/apache/iotdb/session/Session.java @@ -23,18 +23,16 @@ import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; import java.util.List; +import org.apache.iotdb.rpc.BatchExecutionException; import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.StatementExecutionException; -import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.TSBatchInsertionReq; import org.apache.iotdb.service.rpc.thrift.TSCloseSessionReq; import org.apache.iotdb.service.rpc.thrift.TSCreateTimeseriesReq; import org.apache.iotdb.service.rpc.thrift.TSDeleteDataReq; -import org.apache.iotdb.service.rpc.thrift.TSExecuteBatchStatementResp; import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementReq; import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementResp; import org.apache.iotdb.service.rpc.thrift.TSGetTimeZoneResp; @@ -201,8 +199,8 @@ private boolean checkSorted(RowBatch rowBatch){ * * @param rowBatch data batch */ - private TSExecuteBatchStatementResp insertSortedBatchIntern(RowBatch rowBatch) - throws IoTDBConnectionException { + private void insertSortedBatchIntern(RowBatch rowBatch) + throws IoTDBConnectionException, BatchExecutionException { TSBatchInsertionReq request = new TSBatchInsertionReq(); request.setSessionId(sessionId); request.deviceId = rowBatch.deviceId; @@ -215,7 +213,7 @@ private TSExecuteBatchStatementResp insertSortedBatchIntern(RowBatch rowBatch) request.setSize(rowBatch.batchSize); try { - return checkAndReturn(client.insertBatch(request)); + RpcUtils.verifySuccess(client.insertBatch(request).statusList); } catch (TException e) { throw new IoTDBConnectionException(e); } @@ -227,12 +225,12 @@ private TSExecuteBatchStatementResp insertSortedBatchIntern(RowBatch rowBatch) * * @param rowBatch data batch */ - public TSExecuteBatchStatementResp insertSortedBatch(RowBatch rowBatch) - throws StatementExecutionException, IoTDBConnectionException { + public void insertSortedBatch(RowBatch rowBatch) + throws BatchExecutionException, IoTDBConnectionException { if(!checkSorted(rowBatch)){ - throw new StatementExecutionException("Row batch has't been sorted when calling insertSortedBatch"); + throw new BatchExecutionException("Row batch has't been sorted when calling insertSortedBatch"); } - return insertSortedBatchIntern(rowBatch); + insertSortedBatchIntern(rowBatch); } /** @@ -240,18 +238,19 @@ public TSExecuteBatchStatementResp insertSortedBatch(RowBatch rowBatch) * * @param rowBatch data batch */ - public TSExecuteBatchStatementResp insertBatch(RowBatch rowBatch) throws IoTDBConnectionException { + public void insertBatch(RowBatch rowBatch) + throws IoTDBConnectionException, BatchExecutionException { sortRowBatch(rowBatch); - return insertSortedBatchIntern(rowBatch); + insertSortedBatchIntern(rowBatch); } private void sortRowBatch(RowBatch rowBatch){ /* - * following part of code sort the batch data by time, - * so we can insert continuous data in value list to get a better performance - */ + * following part of code sort the batch data by time, + * so we can insert continuous data in value list to get a better performance + */ // sort to get index, and use index to sort value list Integer[] index = new Integer[rowBatch.batchSize]; for (int i = 0; i < rowBatch.batchSize; i++) { @@ -329,9 +328,9 @@ private Object sortList(Object valueList, TSDataType dataType, Integer[] index) * * @see Session#insertBatch(RowBatch) */ - public List insertInBatch(List deviceIds, List times, + public void insertInBatch(List deviceIds, List times, List> measurementsList, List> valuesList) - throws IoTDBConnectionException { + throws IoTDBConnectionException, BatchExecutionException { // check params size int len = deviceIds.size(); if (len != times.size() || len != measurementsList.size() || len != valuesList.size()) { @@ -347,11 +346,7 @@ public List insertInBatch(List deviceIds, List times, request.setValuesList(valuesList); try { - List result = new ArrayList<>(); - for (TSStatus cur : client.insertRowInBatch(request).getStatusList()) { - result.add(checkAndReturn(cur)); - } - return result; + RpcUtils.verifySuccess(client.insertRowInBatch(request).statusList); } catch (TException e) { throw new IoTDBConnectionException(e); } @@ -364,8 +359,8 @@ public List insertInBatch(List deviceIds, List times, * @see Session#insertInBatch(List, List, List, List) * @see Session#insertBatch(RowBatch) */ - public TSStatus insert(String deviceId, long time, List measurements, - List values) throws IoTDBConnectionException { + public void insert(String deviceId, long time, List measurements, + List values) throws IoTDBConnectionException, StatementExecutionException { TSInsertReq request = new TSInsertReq(); request.setSessionId(sessionId); request.setDeviceId(deviceId); @@ -374,7 +369,7 @@ public TSStatus insert(String deviceId, long time, List measurements, request.setValues(values); try { - return checkAndReturn(client.insert(request)); + RpcUtils.verifySuccess(client.insert(request)); } catch (TException e) { throw new IoTDBConnectionException(e); } @@ -384,8 +379,8 @@ public TSStatus insert(String deviceId, long time, List measurements, * This method NOT insert data into database and the server just return after accept the request, * this method should be used to test other time cost in client */ - public TSExecuteBatchStatementResp testInsertBatch(RowBatch rowBatch) - throws IoTDBConnectionException { + public void testInsertBatch(RowBatch rowBatch) + throws IoTDBConnectionException, BatchExecutionException { TSBatchInsertionReq request = new TSBatchInsertionReq(); request.setSessionId(sessionId); request.deviceId = rowBatch.deviceId; @@ -398,7 +393,7 @@ public TSExecuteBatchStatementResp testInsertBatch(RowBatch rowBatch) request.setSize(rowBatch.batchSize); try { - return client.testInsertBatch(request); + RpcUtils.verifySuccess(client.testInsertBatch(request).statusList); } catch (TException e) { throw new IoTDBConnectionException(e); } @@ -408,9 +403,9 @@ public TSExecuteBatchStatementResp testInsertBatch(RowBatch rowBatch) * This method NOT insert data into database and the server just return after accept the request, * this method should be used to test other time cost in client */ - public List testInsertInBatch(List deviceIds, List times, + public void testInsertInBatch(List deviceIds, List times, List> measurementsList, List> valuesList) - throws IoTDBConnectionException { + throws IoTDBConnectionException, BatchExecutionException { // check params size int len = deviceIds.size(); if (len != times.size() || len != measurementsList.size() || len != valuesList.size()) { @@ -426,8 +421,7 @@ public List testInsertInBatch(List deviceIds, List times request.setValuesList(valuesList); try { - client.testInsertRowInBatch(request); - return Collections.emptyList(); + RpcUtils.verifySuccess(client.testInsertRowInBatch(request).statusList); } catch (TException e) { throw new IoTDBConnectionException(e); } @@ -437,8 +431,8 @@ public List testInsertInBatch(List deviceIds, List times * This method NOT insert data into database and the server just return after accept the request, * this method should be used to test other time cost in client */ - public TSStatus testInsert(String deviceId, long time, List measurements, - List values) throws IoTDBConnectionException { + public void testInsert(String deviceId, long time, List measurements, + List values) throws IoTDBConnectionException, StatementExecutionException { TSInsertReq request = new TSInsertReq(); request.setSessionId(sessionId); request.setDeviceId(deviceId); @@ -447,7 +441,7 @@ public TSStatus testInsert(String deviceId, long time, List measurements request.setValues(values); try { - return client.testInsertRow(request); + RpcUtils.verifySuccess(client.testInsertRow(request)); } catch (TException e) { throw new IoTDBConnectionException(e); } @@ -458,10 +452,11 @@ public TSStatus testInsert(String deviceId, long time, List measurements * * @param path timeseries to delete, should be a whole path */ - public TSStatus deleteTimeseries(String path) throws IoTDBConnectionException { + public void deleteTimeseries(String path) + throws IoTDBConnectionException, StatementExecutionException { List paths = new ArrayList<>(); paths.add(path); - return deleteTimeseries(paths); + deleteTimeseries(paths); } /** @@ -469,9 +464,10 @@ public TSStatus deleteTimeseries(String path) throws IoTDBConnectionException { * * @param paths timeseries to delete, should be a whole path */ - public TSStatus deleteTimeseries(List paths) throws IoTDBConnectionException { + public void deleteTimeseries(List paths) + throws IoTDBConnectionException, StatementExecutionException { try { - return checkAndReturn(client.deleteTimeseries(sessionId, paths)); + RpcUtils.verifySuccess(client.deleteTimeseries(sessionId, paths)); } catch (TException e) { throw new IoTDBConnectionException(e); } @@ -483,10 +479,11 @@ public TSStatus deleteTimeseries(List paths) throws IoTDBConnectionExcep * @param path data in which time series to delete * @param time data with time stamp less than or equal to time will be deleted */ - public TSStatus deleteData(String path, long time) throws IoTDBConnectionException { + public void deleteData(String path, long time) + throws IoTDBConnectionException, StatementExecutionException { List paths = new ArrayList<>(); paths.add(path); - return deleteData(paths, time); + deleteData(paths, time); } /** @@ -495,45 +492,48 @@ public TSStatus deleteData(String path, long time) throws IoTDBConnectionExcepti * @param paths data in which time series to delete * @param time data with time stamp less than or equal to time will be deleted */ - public TSStatus deleteData(List paths, long time) throws IoTDBConnectionException { + public void deleteData(List paths, long time) + throws IoTDBConnectionException, StatementExecutionException { TSDeleteDataReq request = new TSDeleteDataReq(); request.setSessionId(sessionId); request.setPaths(paths); request.setTimestamp(time); try { - return checkAndReturn(client.deleteData(request)); + RpcUtils.verifySuccess(client.deleteData(request)); } catch (TException e) { throw new IoTDBConnectionException(e); } } - public TSStatus setStorageGroup(String storageGroupId) + public void setStorageGroup(String storageGroupId) throws IoTDBConnectionException, StatementExecutionException { checkPathValidity(storageGroupId); try { - return checkAndReturn(client.setStorageGroup(sessionId, storageGroupId)); + RpcUtils.verifySuccess(client.setStorageGroup(sessionId, storageGroupId)); } catch (TException e) { throw new IoTDBConnectionException(e); } } - public TSStatus deleteStorageGroup(String storageGroup) throws IoTDBConnectionException { + public void deleteStorageGroup(String storageGroup) + throws IoTDBConnectionException, StatementExecutionException { List groups = new ArrayList<>(); groups.add(storageGroup); - return deleteStorageGroups(groups); + deleteStorageGroups(groups); } - public TSStatus deleteStorageGroups(List storageGroup) throws IoTDBConnectionException { + public void deleteStorageGroups(List storageGroup) + throws IoTDBConnectionException, StatementExecutionException { try { - return checkAndReturn(client.deleteStorageGroups(sessionId, storageGroup)); + RpcUtils.verifySuccess(client.deleteStorageGroups(sessionId, storageGroup)); } catch (TException e) { throw new IoTDBConnectionException(e); } } - public TSStatus createTimeseries(String path, TSDataType dataType, + public void createTimeseries(String path, TSDataType dataType, TSEncoding encoding, CompressionType compressor) throws IoTDBConnectionException, StatementExecutionException { checkPathValidity(path); @@ -545,7 +545,7 @@ public TSStatus createTimeseries(String path, TSDataType dataType, request.setCompressor(compressor.ordinal()); try { - return checkAndReturn(client.createTimeseries(request)); + RpcUtils.verifySuccess(client.createTimeseries(request)); } catch (TException e) { throw new IoTDBConnectionException(e); } @@ -561,20 +561,6 @@ public boolean checkTimeseriesExists(String path) } } - private TSStatus checkAndReturn(TSStatus resp) { - if (resp.statusType.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { - logger.error(resp.statusType.getMessage()); - } - return resp; - } - - private TSExecuteBatchStatementResp checkAndReturn(TSExecuteBatchStatementResp resp) { - if (resp.status.statusType.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { - logger.error(resp.status.statusType.getMessage()); - } - return resp; - } - private synchronized String getTimeZone() throws StatementExecutionException, IoTDBConnectionException { if (zoneId != null) { diff --git a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java index f9e3a9fd06327..f3d67ba1ecf5e 100644 --- a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java +++ b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java @@ -19,6 +19,8 @@ package org.apache.iotdb.session; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.File; import java.sql.Connection; @@ -34,6 +36,7 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.utils.EnvironmentUtils; import org.apache.iotdb.jdbc.Config; +import org.apache.iotdb.rpc.BatchExecutionException; import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.rpc.StatementExecutionException; import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; @@ -66,8 +69,8 @@ public void tearDown() throws Exception { } @Test - public void testAlignByDevice() - throws SQLException, IoTDBConnectionException, StatementExecutionException { + public void testAlignByDevice() throws IoTDBConnectionException, + StatementExecutionException, BatchExecutionException { session = new Session("127.0.0.1", 6667, "root", "root"); session.open(); @@ -82,7 +85,8 @@ public void testAlignByDevice() } // it's will output too much to travis, so ignore it - public void testTime() throws IoTDBConnectionException, StatementExecutionException { + public void testTime() + throws IoTDBConnectionException, StatementExecutionException, BatchExecutionException { session = new Session("127.0.0.1", 6667, "root", "root"); session.open(); @@ -94,8 +98,8 @@ public void testTime() throws IoTDBConnectionException, StatementExecutionExcept } @Test - public void testBatchInsertSeqAndUnseq() - throws SQLException, ClassNotFoundException, IoTDBConnectionException, StatementExecutionException { + public void testBatchInsertSeqAndUnseq() throws SQLException, ClassNotFoundException, + IoTDBConnectionException, StatementExecutionException, BatchExecutionException { session = new Session("127.0.0.1", 6667, "root", "root"); session.open(); @@ -118,8 +122,8 @@ public void testBatchInsertSeqAndUnseq() } @Test - public void testBatchInsert() - throws StatementExecutionException, SQLException, ClassNotFoundException, IoTDBConnectionException { + public void testBatchInsert() throws StatementExecutionException, SQLException, + ClassNotFoundException, IoTDBConnectionException, BatchExecutionException { session = new Session("127.0.0.1", 6667, "root", "root"); session.open(); @@ -132,12 +136,14 @@ public void testBatchInsert() queryForBatch(); } - public void testTestMethod() throws StatementExecutionException, IoTDBConnectionException { + public void testTestMethod() + throws StatementExecutionException, IoTDBConnectionException, BatchExecutionException { session = new Session("127.0.0.1", 6667, "root", "root"); session.open(); session.setStorageGroup("root.sg1"); + String deviceId = "root.sg1.d1"; createTimeseries(); @@ -152,7 +158,6 @@ public void testTestMethod() throws StatementExecutionException, IoTDBConnection session.testInsertBatch(rowBatch); // test insert row - String deviceId = "root.sg1.d1"; List measurements = new ArrayList<>(); measurements.add("s1"); measurements.add("s2"); @@ -199,7 +204,7 @@ public void testTestMethod() throws StatementExecutionException, IoTDBConnection @Test public void test() throws ClassNotFoundException, SQLException, - IoTDBConnectionException, StatementExecutionException { + IoTDBConnectionException, StatementExecutionException, BatchExecutionException { session = new Session("127.0.0.1", 6667, "root", "root"); try { session.open(); @@ -312,7 +317,7 @@ private void createTimeseries() throws StatementExecutionException, IoTDBConnect CompressionType.SNAPPY); } - private void insertInBatch() throws IoTDBConnectionException { + private void insertInBatch() throws IoTDBConnectionException, BatchExecutionException { String deviceId = "root.sg1.d2"; List measurements = new ArrayList<>(); measurements.add("s1"); @@ -345,7 +350,7 @@ private void insertInBatch() throws IoTDBConnectionException { session.insertInBatch(deviceIds, timestamps, measurementsList, valuesList); } - private void insert() throws IoTDBConnectionException { + private void insert() throws IoTDBConnectionException, StatementExecutionException { String deviceId = "root.sg1.d1"; List measurements = new ArrayList<>(); measurements.add("s1"); @@ -360,7 +365,8 @@ private void insert() throws IoTDBConnectionException { } } - private void insertRowBatchTest1(String deviceId) throws IoTDBConnectionException { + private void insertRowBatchTest1(String deviceId) + throws IoTDBConnectionException, BatchExecutionException { Schema schema = new Schema(); schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE)); schema.registerMeasurement(new MeasurementSchema("s2", TSDataType.INT64, TSEncoding.RLE)); @@ -390,7 +396,7 @@ private void insertRowBatchTest1(String deviceId) throws IoTDBConnectionExceptio } } - private void deleteData() throws IoTDBConnectionException { + private void deleteData() throws IoTDBConnectionException, StatementExecutionException { String path1 = "root.sg1.d1.s1"; String path2 = "root.sg1.d1.s2"; String path3 = "root.sg1.d1.s3"; @@ -403,12 +409,8 @@ private void deleteData() throws IoTDBConnectionException { session.deleteData(paths, deleteTime); } - private void deleteTimeseries() throws IoTDBConnectionException { + private void deleteTimeseries() throws IoTDBConnectionException, StatementExecutionException { session.deleteTimeseries("root.sg1.d1.s1"); - session.deleteTimeseries("root.laptop.d1.1_2"); - session.deleteTimeseries("root.laptop.d1.\"1.2.3\""); - session.deleteTimeseries("root.laptop.d1.\'1.2.4\'"); - session.deleteTimeseries("root.1.2.3"); } private void query() throws ClassNotFoundException, SQLException { @@ -424,7 +426,7 @@ private void query() throws ClassNotFoundException, SQLException { final int colCount = metaData.getColumnCount(); StringBuilder resultStr = new StringBuilder(); for (int i = 0; i < colCount; i++) { - resultStr.append(metaData.getColumnLabel(i + 1) + "\n"); + resultStr.append(metaData.getColumnLabel(i + 1)).append("\n"); } while (resultSet.next()) { for (int i = 1; i <= colCount; i++) { @@ -436,8 +438,7 @@ private void query() throws ClassNotFoundException, SQLException { } } - private void queryForAlignByDevice() - throws SQLException, StatementExecutionException, IoTDBConnectionException { + private void queryForAlignByDevice() throws StatementExecutionException, IoTDBConnectionException { SessionDataSet sessionDataSet = session .executeQueryStatement("select '11', s1, '11' from root.sg1.d1 align by device"); sessionDataSet.setBatchSize(1024); @@ -455,8 +456,7 @@ private void queryForAlignByDevice() sessionDataSet.closeOperationHandle(); } - private void queryForAlignByDevice2() - throws SQLException, IoTDBConnectionException, StatementExecutionException { + private void queryForAlignByDevice2() throws IoTDBConnectionException, StatementExecutionException { SessionDataSet sessionDataSet = session.executeQueryStatement( "select '11', s1, '11', s5, s1, s5 from root.sg1.d1 align by device"); sessionDataSet.setBatchSize(1024); @@ -488,7 +488,7 @@ private void query2() throws ClassNotFoundException, SQLException { final int colCount = metaData.getColumnCount(); StringBuilder resultStr = new StringBuilder(); for (int i = 0; i < colCount; i++) { - resultStr.append(metaData.getColumnLabel(i + 1) + "\n"); + resultStr.append(metaData.getColumnLabel(i + 1)).append("\n"); } while (resultSet.next()) { for (int i = 1; i <= colCount; i++) { @@ -504,12 +504,12 @@ public void deleteStorageGroupTest() throws ClassNotFoundException, SQLException IoTDBConnectionException, StatementExecutionException { try { session.deleteStorageGroup("root.sg1.d1.s1"); - } catch (IoTDBConnectionException e) { - assertEquals("The path root.sg1.d1.s1 is not a deletable storage group", e.getMessage()); + } catch (StatementExecutionException e) { + assertTrue(e.getMessage().contains("Path [root.sg1.d1.s1] does not exist")); } session.deleteStorageGroup("root.sg1"); File folder = new File("data/system/storage_groups/root.sg1/"); - assertEquals(folder.exists(), false); + assertFalse(folder.exists()); session.setStorageGroup("root.sg1.d1"); session.createTimeseries("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY); @@ -524,7 +524,7 @@ public void deleteStorageGroupTest() throws ClassNotFoundException, SQLException final int colCount = metaData.getColumnCount(); StringBuilder resultStr = new StringBuilder(); for (int i = 0; i < colCount; i++) { - resultStr.append(metaData.getColumnLabel(i + 1) + "\n"); + resultStr.append(metaData.getColumnLabel(i + 1)).append("\n"); } while (resultSet.next()) { for (int i = 1; i <= colCount; i++) { @@ -635,7 +635,8 @@ private void checkCreateTimeseries(Session session, String timeseries, boolean c assertEquals(correctStatus, status); } - private void insertRowBatchTest2(String deviceId) throws IoTDBConnectionException { + private void insertRowBatchTest2(String deviceId) + throws IoTDBConnectionException, BatchExecutionException { Schema schema = new Schema(); schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE)); schema.registerMeasurement(new MeasurementSchema("s2", TSDataType.INT64, TSEncoding.RLE)); @@ -665,7 +666,8 @@ private void insertRowBatchTest2(String deviceId) throws IoTDBConnectionExceptio } } - private void insertRowBatchTest3(String deviceId) throws IoTDBConnectionException { + private void insertRowBatchTest3(String deviceId) + throws IoTDBConnectionException, BatchExecutionException { Schema schema = new Schema(); schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE)); schema.registerMeasurement(new MeasurementSchema("s2", TSDataType.INT64, TSEncoding.RLE)); @@ -695,15 +697,15 @@ private void insertRowBatchTest3(String deviceId) throws IoTDBConnectionExceptio } } - private void insertRowBatchTestForTime(String deviceId) throws IoTDBConnectionException { + private void insertRowBatchTestForTime(String deviceId) + throws IoTDBConnectionException, BatchExecutionException { Schema schema = new Schema(); schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE)); schema.registerMeasurement(new MeasurementSchema("s2", TSDataType.INT64, TSEncoding.RLE)); schema.registerMeasurement(new MeasurementSchema("s3", TSDataType.INT64, TSEncoding.RLE)); - schema.registerMeasurement(new MeasurementSchema("s4", TSDataType.INT64, TSEncoding.RLE)); - schema.registerMeasurement(new MeasurementSchema("s5", TSDataType.INT64, TSEncoding.RLE)); - schema.registerMeasurement(new MeasurementSchema("s6", TSDataType.INT64, TSEncoding.RLE)); - long countTime = 0; + schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE)); + schema.registerMeasurement(new MeasurementSchema("s2", TSDataType.INT64, TSEncoding.RLE)); + schema.registerMeasurement(new MeasurementSchema("s3", TSDataType.INT64, TSEncoding.RLE)); long count = 10000000; long begin = 0; //long begin = 1579414903000L; @@ -724,13 +726,11 @@ private void insertRowBatchTestForTime(String deviceId) throws IoTDBConnectionEx long start = System.currentTimeMillis(); session.insertBatch(rowBatch); long val = System.currentTimeMillis() - start; - countTime += val; rowBatch.reset(); } } if (rowBatch.batchSize != 0) { - long start = System.currentTimeMillis(); session.insertBatch(rowBatch); rowBatch.reset(); } @@ -750,7 +750,7 @@ private void queryForBatch() throws ClassNotFoundException, SQLException { final int colCount = metaData.getColumnCount(); StringBuilder resultStr = new StringBuilder(); for (int i = 0; i < colCount; i++) { - resultStr.append(metaData.getColumnLabel(i + 1) + "\n"); + resultStr.append(metaData.getColumnLabel(i + 1)).append("\n"); } int count = 0; @@ -778,7 +778,7 @@ public void queryForBatchCheckOrder() throws ClassNotFoundException, SQLExceptio final int colCount = metaData.getColumnCount(); StringBuilder resultStr = new StringBuilder(); for (int i = 0; i < colCount; i++) { - resultStr.append(metaData.getColumnLabel(i + 1) + "\n"); + resultStr.append(metaData.getColumnLabel(i + 1)).append("\n"); } int count = 0; @@ -818,7 +818,7 @@ private void queryForBatchSeqAndUnseq() throws ClassNotFoundException, SQLExcept final int colCount = metaData.getColumnCount(); StringBuilder resultStr = new StringBuilder(); for (int i = 0; i < colCount; i++) { - resultStr.append(metaData.getColumnLabel(i + 1) + "\n"); + resultStr.append(metaData.getColumnLabel(i + 1)).append("\n"); } int count = 0; From 8d143f287c165b23b4fce123d29fcfc6fa20f5e6 Mon Sep 17 00:00:00 2001 From: qiaojialin <646274302@qq.com> Date: Mon, 9 Mar 2020 21:03:47 +0800 Subject: [PATCH 2/8] add rpc change list --- service-rpc/rpc-changelist.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/service-rpc/rpc-changelist.md b/service-rpc/rpc-changelist.md index 971df2c98c621..203882db64159 100644 --- a/service-rpc/rpc-changelist.md +++ b/service-rpc/rpc-changelist.md @@ -101,6 +101,7 @@ Last Updated on November 12th, 2019 by Tian Jiang. | Latest Changes | Related Committers | | ---------------------------------- | ------------------ | | Remove TS_SessionHandle,TSHandleIdentifier | Tian Jiang | +| Remove TSStatus,TSExecuteInsertRowInBatchResp | Jialin Qiao| ## 2. Add New @@ -114,4 +115,5 @@ Last Updated on November 12th, 2019 by Tian Jiang. | Latest Changes | Related Committers | | ------------------------------------------------------------ | ---------------------- | | Replace TS_SessionHandles with SessionIds, TSOperationHandle with queryIds | Tian Jiang | -| Add optional TSQueryNonAlignDataSet in TSExecuteStatementResp, TSFetchResultsResp and required bool isAlign in TSFetchResultsReq | Haonan Hou | \ No newline at end of file +| Add optional TSQueryNonAlignDataSet in TSExecuteStatementResp, TSFetchResultsResp and required bool isAlign in TSFetchResultsReq | Haonan Hou | +| Rename TSStatusType to TSStatus | Jialin Qiao | \ No newline at end of file From 991cba9fbafe573f616dfa738de6c1d94527ff48 Mon Sep 17 00:00:00 2001 From: qiaojialin <646274302@qq.com> Date: Tue, 10 Mar 2020 09:45:34 +0800 Subject: [PATCH 3/8] fix review --- .../org/apache/iotdb/jdbc/IoTDBStatement.java | 3 -- .../java/org/apache/iotdb/jdbc/BatchTest.java | 7 ++--- .../iotdb/jdbc/IoTDBConnectionTest.java | 8 +++--- .../jdbc/IoTDBPreparedStatementTest.java | 2 +- .../iotdb/jdbc/IoTDBQueryResultSetTest.java | 12 ++++---- .../apache/iotdb/jdbc/IoTDBStatementTest.java | 5 ++-- .../java/org/apache/iotdb/jdbc/UtilsTest.java | 8 ++---- .../apache/iotdb/db/engine/StorageEngine.java | 3 +- .../iotdb/db/engine/memtable/IMemTable.java | 3 ++ .../db/engine/memtable/IWritableMemChunk.java | 3 ++ .../storagegroup/StorageGroupProcessor.java | 16 +++++------ .../engine/storagegroup/TsFileProcessor.java | 28 +++++++++++++------ ...eption.java => WriteProcessException.java} | 9 ++++-- .../iotdb/db/service/TSServiceImpl.java | 9 ++---- .../modification/DeletionQueryTest.java | 1 - .../FileNodeManagerBenchmark.java | 1 - .../StorageGroupProcessorTest.java | 3 +- .../db/metadata/MManagerAdvancedTest.java | 6 ++-- .../db/metadata/MManagerImproveTest.java | 10 +++---- .../iotdb/db/writelog/PerformanceTest.java | 4 +-- service-rpc/rpc-changelist.md | 3 +- .../java/org/apache/iotdb/rpc/RpcUtils.java | 14 ++++++++-- service-rpc/src/main/thrift/rpc.thrift | 5 ++-- 23 files changed, 92 insertions(+), 71 deletions(-) rename server/src/main/java/org/apache/iotdb/db/exception/storageGroup/{StorageGroupException.java => WriteProcessException.java} (81%) diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java index f0debfd99a720..a4a7c08e8d691 100644 --- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java +++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java @@ -261,9 +261,6 @@ private int[] executeBatchSQL() throws TException, BatchUpdateException { isCancelled = false; TSExecuteBatchStatementReq execReq = new TSExecuteBatchStatementReq(sessionId, batchSQLList); TSExecuteBatchStatementResp execResp = client.executeBatchStatement(execReq); - if (execResp.statusList == null) { - - } int[] result = new int[execResp.statusList.size()]; boolean allSuccess = true; String message = ""; diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java index 953f5a82e4b8c..c3f290dd2bb36 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java @@ -51,10 +51,7 @@ public class BatchTest { private long sessionId; @Mock private IoTDBStatement statement; - private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); - private TSStatus errorStatus = new TSStatus(TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), ""); - private TSStatus Status_SUCCESS = new TSStatus(successStatus); - private TSStatus Status_ERROR = new TSStatus(errorStatus); + private TSStatus errorStatus = RpcUtils.getStatus(TSStatusCode.INTERNAL_SERVER_ERROR); private TSExecuteBatchStatementResp resp; private ZoneId zoneID = ZoneId.systemDefault(); @@ -133,7 +130,7 @@ public void testExecuteBatchSQL2() throws SQLException, TException { @Test public void testExecuteBatchSQL3() throws SQLException, TException { Statement statement = connection.createStatement(); - resp = RpcUtils.getTSBatchExecuteStatementResp(Status_ERROR); + resp = RpcUtils.getTSBatchExecuteStatementResp(errorStatus); List resExpected = new ArrayList() { { add(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS)); diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java index 7f936146ceff1..43dea9b023d5b 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java @@ -23,6 +23,7 @@ import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; +import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.*; import org.apache.thrift.TException; @@ -38,8 +39,7 @@ public class IoTDBConnectionTest { private TSIService.Iface client; private IoTDBConnection connection = new IoTDBConnection(); - private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); - private TSStatus Status_SUCCESS = new TSStatus(successStatus); + private TSStatus successStatus = RpcUtils.SUCCESS_STATUS; private long sessionId; @Before @@ -55,7 +55,7 @@ public void tearDown() throws Exception { public void testSetTimeZone() throws TException, IoTDBSQLException { String timeZone = "Asia/Shanghai"; when(client.setTimeZone(any(TSSetTimeZoneReq.class))) - .thenReturn(new TSStatus(Status_SUCCESS)); + .thenReturn(new TSStatus(successStatus)); connection.setClient(client); connection.setTimeZone(timeZone); assertEquals(connection.getTimeZone(), timeZone); @@ -65,7 +65,7 @@ public void testSetTimeZone() throws TException, IoTDBSQLException { public void testGetTimeZone() throws IoTDBSQLException, TException { String timeZone = "GMT+:08:00"; sessionId = connection.getSessionId(); - when(client.getTimeZone(sessionId)).thenReturn(new TSGetTimeZoneResp(Status_SUCCESS, timeZone)); + when(client.getTimeZone(sessionId)).thenReturn(new TSGetTimeZoneResp(successStatus, timeZone)); connection.setClient(client); assertEquals(connection.getTimeZone(), timeZone); } diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java index 2ee1b1f0b8df1..180f1f35ab1b1 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java @@ -48,7 +48,7 @@ public class IoTDBPreparedStatementTest { @Mock private Iface client; @Mock - private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); + private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()); private TSStatus Status_SUCCESS = new TSStatus(successStatus); private long queryId; private long sessionId; diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBQueryResultSetTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBQueryResultSetTest.java index 7f1fa242c8615..e686db4bbd171 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBQueryResultSetTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBQueryResultSetTest.java @@ -36,6 +36,7 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.TSCloseOperationReq; import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementReq; @@ -117,8 +118,7 @@ public class IoTDBQueryResultSetTest { @Mock private TSFetchResultsResp fetchResultsResp; - private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); - private TSStatus Status_SUCCESS = new TSStatus(successStatus); + private TSStatus successStatus = RpcUtils.SUCCESS_STATUS; private ZoneId zoneID = ZoneId.systemDefault(); @Before @@ -132,15 +132,15 @@ public void before() throws Exception { when(connection.isClosed()).thenReturn(false); when(client.executeStatement(any(TSExecuteStatementReq.class))).thenReturn(execResp); when(execResp.getQueryId()).thenReturn(queryId); - when(execResp.getStatus()).thenReturn(Status_SUCCESS); + when(execResp.getStatus()).thenReturn(successStatus); when(client.fetchMetadata(any(TSFetchMetadataReq.class))).thenReturn(fetchMetadataResp); - when(fetchMetadataResp.getStatus()).thenReturn(Status_SUCCESS); + when(fetchMetadataResp.getStatus()).thenReturn(successStatus); when(client.fetchResults(any(TSFetchResultsReq.class))).thenReturn(fetchResultsResp); - when(fetchResultsResp.getStatus()).thenReturn(Status_SUCCESS); + when(fetchResultsResp.getStatus()).thenReturn(successStatus); - TSStatus closeResp = Status_SUCCESS; + TSStatus closeResp = successStatus; when(client.closeOperation(any(TSCloseOperationReq.class))).thenReturn(closeResp); } diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java index 31ccd997db7b2..e957b1792af93 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java @@ -24,6 +24,7 @@ import java.sql.SQLException; import java.time.ZoneId; +import org.apache.iotdb.rpc.RpcUtils; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataReq; import org.apache.iotdb.service.rpc.thrift.TSFetchMetadataResp; @@ -49,8 +50,6 @@ public class IoTDBStatementTest { @Mock private TSFetchMetadataResp fetchMetadataResp; - private TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); - private TSStatus Status_SUCCESS = new TSStatus(successStatus); private ZoneId zoneID = ZoneId.systemDefault(); @Before @@ -59,7 +58,7 @@ public void setUp() throws Exception { when(connection.getMetaData()).thenReturn(new IoTDBDatabaseMetadata(connection, client, sessionId)); when(connection.isClosed()).thenReturn(false); when(client.fetchMetadata(any(TSFetchMetadataReq.class))).thenReturn(fetchMetadataResp); - when(fetchMetadataResp.getStatus()).thenReturn(Status_SUCCESS); + when(fetchMetadataResp.getStatus()).thenReturn(RpcUtils.SUCCESS_STATUS); } @After diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java index 0b2b3a71600c6..1aafa974d8a68 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/UtilsTest.java @@ -103,16 +103,14 @@ public void testParseWrongPort() throws IoTDBURLException { @Test public void testVerifySuccess() { try { - TSStatus successStatus = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode(), ""); - RpcUtils.verifySuccess(new TSStatus(successStatus)); + RpcUtils.verifySuccess(RpcUtils.SUCCESS_STATUS); } catch (Exception e) { fail(); } try { - TSStatus errorStatus = new TSStatus( - TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), ""); - RpcUtils.verifySuccess(new TSStatus(errorStatus)); + TSStatus errorStatus = new TSStatus(TSStatusCode.INTERNAL_SERVER_ERROR.getStatusCode()); + RpcUtils.verifySuccess(errorStatus); } catch (Exception e) { return; } diff --git a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java index 372f70486bd6a..75d0a6c4488a1 100644 --- a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java @@ -55,6 +55,7 @@ import org.apache.iotdb.db.exception.query.QueryProcessException; import org.apache.iotdb.db.exception.runtime.StorageEngineFailureException; import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; import org.apache.iotdb.db.metadata.MManager; import org.apache.iotdb.db.metadata.mnode.StorageGroupMNode; import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan; @@ -291,7 +292,7 @@ public TSStatus[] insertBatch(BatchInsertPlan batchInsertPlan) throws StorageEng // TODO monitor: update statistics try { return storageGroupProcessor.insertBatch(batchInsertPlan); - } catch (QueryProcessException e) { + } catch (WriteProcessException e) { throw new StorageEngineException(e); } } diff --git a/server/src/main/java/org/apache/iotdb/db/engine/memtable/IMemTable.java b/server/src/main/java/org/apache/iotdb/db/engine/memtable/IMemTable.java index f7caf2308451b..1ffd5f0bafebb 100644 --- a/server/src/main/java/org/apache/iotdb/db/engine/memtable/IMemTable.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/memtable/IMemTable.java @@ -56,6 +56,9 @@ void write(String deviceId, String measurement, TSDataType dataType, void insert(InsertPlan insertPlan) throws QueryProcessException; + /** + * [start, end) + */ void insertBatch(BatchInsertPlan batchInsertPlan, int start, int end) throws QueryProcessException; diff --git a/server/src/main/java/org/apache/iotdb/db/engine/memtable/IWritableMemChunk.java b/server/src/main/java/org/apache/iotdb/db/engine/memtable/IWritableMemChunk.java index 45b7e6028dd48..3d06a204d90d4 100644 --- a/server/src/main/java/org/apache/iotdb/db/engine/memtable/IWritableMemChunk.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/memtable/IWritableMemChunk.java @@ -63,6 +63,9 @@ public interface IWritableMemChunk { void write(long insertTime, Object objectValue); + /** + * [start, end) + */ void write(long[] times, Object valueList, TSDataType dataType, int start, int end); long count(); diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java index acc3475366d80..af3eec800261a 100755 --- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java @@ -69,6 +69,7 @@ import org.apache.iotdb.db.exception.query.OutOfTTLException; import org.apache.iotdb.db.exception.query.QueryProcessException; import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; import org.apache.iotdb.db.metadata.MManager; import org.apache.iotdb.db.metadata.mnode.LeafMNode; import org.apache.iotdb.db.metadata.mnode.MNode; @@ -503,7 +504,7 @@ public void insert(InsertPlan insertPlan) throws QueryProcessException { } } - public TSStatus[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProcessException { + public TSStatus[] insertBatch(BatchInsertPlan batchInsertPlan) throws WriteProcessException { writeLock(); try { TSStatus[] results = new TSStatus[batchInsertPlan.getRowCount()]; @@ -540,7 +541,7 @@ public TSStatus[] insertBatch(BatchInsertPlan batchInsertPlan) throws QueryProce while (loc < batchInsertPlan.getRowCount()) { long time = batchInsertPlan.getTimes()[loc]; long curTimePartition = StorageEngine.fromTimeToTimePartition(time); - results[loc] = RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS); + results[loc] = RpcUtils.SUCCESS_STATUS; // start next partition if (curTimePartition != beforeTimePartition) { // insert last time partition @@ -597,7 +598,7 @@ private boolean checkTTL(long time) { */ private void insertBatchToTsFileProcessor(BatchInsertPlan batchInsertPlan, int start, int end, boolean sequence, TSStatus[] results, long timePartitionId) - throws QueryProcessException { + throws WriteProcessException { // return when start <= end if (start >= end) { return; @@ -612,13 +613,12 @@ private void insertBatchToTsFileProcessor(BatchInsertPlan batchInsertPlan, return; } - boolean result = tsFileProcessor.insertBatch(batchInsertPlan, start, end, results); + tsFileProcessor.insertBatch(batchInsertPlan, start, end, results); latestTimeForEachDevice.computeIfAbsent(timePartitionId, t -> new HashMap<>()) .putIfAbsent(batchInsertPlan.getDeviceId(), Long.MIN_VALUE); // try to update the latest time of the device of this tsRecord - if (sequence && result - && latestTimeForEachDevice.get(timePartitionId).get(batchInsertPlan.getDeviceId()) + if (sequence && latestTimeForEachDevice.get(timePartitionId).get(batchInsertPlan.getDeviceId()) < batchInsertPlan.getTimes()[end - 1]) { latestTimeForEachDevice.get(timePartitionId) .put(batchInsertPlan.getDeviceId(), batchInsertPlan.getTimes()[end - 1]); @@ -638,7 +638,7 @@ private void insertBatchToTsFileProcessor(BatchInsertPlan batchInsertPlan, } public void tryToUpdateBatchInsertLastCache(BatchInsertPlan plan, Long latestFlushedTime) - throws QueryProcessException { + throws WriteProcessException { try { MNode node = MManager.getInstance().getDeviceNodeWithAutoCreateStorageGroup(plan.getDeviceId()); @@ -650,7 +650,7 @@ public void tryToUpdateBatchInsertLastCache(BatchInsertPlan plan, Long latestFlu .updateCachedLast(plan.composeLastTimeValuePair(i), true, latestFlushedTime); } } catch (MetadataException e) { - throw new QueryProcessException(e); + throw new WriteProcessException(e); } } diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java index 3b9622e22d49c..8dfbcfac737c2 100644 --- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java @@ -46,6 +46,7 @@ import org.apache.iotdb.db.engine.version.VersionController; import org.apache.iotdb.db.exception.TsFileProcessorException; import org.apache.iotdb.db.exception.query.QueryProcessException; +import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; import org.apache.iotdb.db.qp.constant.DatetimeUtils; import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; @@ -184,15 +185,23 @@ public boolean insert(InsertPlan insertPlan) throws QueryProcessException { return true; } - public boolean insertBatch(BatchInsertPlan batchInsertPlan, int start, int end, - TSStatus[] results) throws QueryProcessException { + public void insertBatch(BatchInsertPlan batchInsertPlan, int start, int end, + TSStatus[] results) throws WriteProcessException { if (workMemTable == null) { workMemTable = MemTablePool.getInstance().getAvailableMemTable(this); } // insert insertPlan to the work memtable - workMemTable.insertBatch(batchInsertPlan, start, end); + try { + workMemTable.insertBatch(batchInsertPlan, start, end); + for (int i = start; i < end; i++) { + results[i] = RpcUtils.SUCCESS_STATUS; + } + } catch (Exception e) { + setErrorResult(start, end, results, e); + return; + } if (IoTDBDescriptor.getInstance().getConfig().isEnableWal()) { try { @@ -202,10 +211,7 @@ public boolean insertBatch(BatchInsertPlan batchInsertPlan, int start, int end, } catch (IOException e) { logger.error("{}: {} write WAL failed", storageGroupName, tsFileResource.getFile().getName(), e); - for (int i = start; i < end; i++) { - results[i] = RpcUtils.getStatus(TSStatusCode.INTERNAL_SERVER_ERROR, e.getMessage()); - } - return false; + setErrorResult(start, end, results, e); } } @@ -218,8 +224,14 @@ public boolean insertBatch(BatchInsertPlan batchInsertPlan, int start, int end, tsFileResource .updateEndTime(batchInsertPlan.getDeviceId(), batchInsertPlan.getTimes()[end - 1]); } + } - return true; + private void setErrorResult(int start, int end, TSStatus[] results, Exception e) + throws WriteProcessException { + for (int i = start; i < end; i++) { + results[i] = RpcUtils.getStatus(TSStatusCode.INTERNAL_SERVER_ERROR, e.getMessage()); + } + throw new WriteProcessException(e); } /** diff --git a/server/src/main/java/org/apache/iotdb/db/exception/storageGroup/StorageGroupException.java b/server/src/main/java/org/apache/iotdb/db/exception/storageGroup/WriteProcessException.java similarity index 81% rename from server/src/main/java/org/apache/iotdb/db/exception/storageGroup/StorageGroupException.java rename to server/src/main/java/org/apache/iotdb/db/exception/storageGroup/WriteProcessException.java index 57ad13a880c99..809d5038d6496 100644 --- a/server/src/main/java/org/apache/iotdb/db/exception/storageGroup/StorageGroupException.java +++ b/server/src/main/java/org/apache/iotdb/db/exception/storageGroup/WriteProcessException.java @@ -22,11 +22,16 @@ import org.apache.iotdb.db.exception.IoTDBException; import org.apache.iotdb.rpc.TSStatusCode; -public class StorageGroupException extends IoTDBException { +public class WriteProcessException extends IoTDBException { private static final long serialVersionUID = 7082567513626836322L; - public StorageGroupException(String message) { + public WriteProcessException(String message) { super(message, TSStatusCode.STORAGE_GROUP_ERROR.getStatusCode()); } + + public WriteProcessException(Exception exception) { + super(exception, TSStatusCode.STORAGE_GROUP_PROCESSOR_ERROR.getStatusCode()); + } + } 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 535ade435ab34..f83e57a201f84 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 @@ -837,8 +837,7 @@ public TSFetchResultsResp fetchResults(TSFetchResultsReq req) { QueryResourceManager.getInstance().endQuery(req.queryId); queryId2DataSet.remove(req.queryId); } - TSFetchResultsResp resp = RpcUtils.getTSFetchResultsResp( - TSStatusCode.SUCCESS_STATUS, "FetchResult successfully. Has more result: " + hasResultSet); + TSFetchResultsResp resp = RpcUtils.getTSFetchResultsResp(TSStatusCode.SUCCESS_STATUS); resp.setHasResultSet(hasResultSet); resp.setQueryDataSet(result); resp.setIsAlign(true); @@ -857,9 +856,7 @@ public TSFetchResultsResp fetchResults(TSFetchResultsReq req) { if (!hasResultSet) { queryId2DataSet.remove(req.queryId); } - TSFetchResultsResp resp = - RpcUtils.getTSFetchResultsResp(TSStatusCode.SUCCESS_STATUS, - "FetchResult successfully. Has more result: " + hasResultSet); + TSFetchResultsResp resp = RpcUtils.getTSFetchResultsResp(TSStatusCode.SUCCESS_STATUS); resp.setHasResultSet(hasResultSet); resp.setNonAlignQueryDataSet(nonAlignResult); resp.setIsAlign(false); @@ -1311,7 +1308,7 @@ private TSStatus executePlan(PhysicalPlan plan) { execRet = executeNonQuery(plan); } catch (QueryProcessException e) { logger.debug("meet error while processing non-query. ", e); - return new TSStatus(e.getErrorCode(), e.getMessage()); + return RpcUtils.getStatus(e.getErrorCode(), e.getMessage()); } return execRet diff --git a/server/src/test/java/org/apache/iotdb/db/engine/modification/DeletionQueryTest.java b/server/src/test/java/org/apache/iotdb/db/engine/modification/DeletionQueryTest.java index ce79cebbd5f59..9d195d704aa65 100644 --- a/server/src/test/java/org/apache/iotdb/db/engine/modification/DeletionQueryTest.java +++ b/server/src/test/java/org/apache/iotdb/db/engine/modification/DeletionQueryTest.java @@ -31,7 +31,6 @@ import org.apache.iotdb.db.exception.StorageEngineException; import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupException; import org.apache.iotdb.db.metadata.MManager; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; import org.apache.iotdb.db.qp.physical.crud.RawDataQueryPlan; diff --git a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/FileNodeManagerBenchmark.java b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/FileNodeManagerBenchmark.java index fc8d93aa8853f..7a773a78a556b 100644 --- a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/FileNodeManagerBenchmark.java +++ b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/FileNodeManagerBenchmark.java @@ -25,7 +25,6 @@ import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.StorageEngineException; import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupException; import org.apache.iotdb.db.metadata.MManager; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; import org.apache.iotdb.db.utils.EnvironmentUtils; diff --git a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java index 7617ab527459f..16e6928d1e04c 100644 --- a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java +++ b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java @@ -28,6 +28,7 @@ import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.query.QueryProcessException; import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; import org.apache.iotdb.db.query.context.QueryContext; @@ -150,7 +151,7 @@ public void testSequenceSyncClose() throws QueryProcessException { } @Test - public void testIoTDBRowBatchWriteAndSyncClose() throws QueryProcessException { + public void testIoTDBRowBatchWriteAndSyncClose() throws WriteProcessException { String[] measurements = new String[2]; measurements[0] = "s0"; diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java index 45beeb171144c..f01f732bbbd21 100644 --- a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java +++ b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java @@ -24,7 +24,7 @@ import java.io.IOException; import java.util.List; import org.apache.iotdb.db.exception.metadata.MetadataException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupException; +import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; import org.apache.iotdb.db.metadata.mnode.LeafMNode; import org.apache.iotdb.db.metadata.mnode.MNode; import org.apache.iotdb.db.utils.EnvironmentUtils; @@ -104,7 +104,7 @@ public void test() { } @Test - public void testCache() throws MetadataException, IOException, StorageGroupException { + public void testCache() throws MetadataException, IOException, WriteProcessException { mmanager.createTimeseries("root.vehicle.d2.s0", "DOUBLE", "RLE"); mmanager.createTimeseries("root.vehicle.d2.s1", "BOOLEAN", "PLAIN"); mmanager.createTimeseries("root.vehicle.d2.s2.g0", "TEXT", "PLAIN"); @@ -123,7 +123,7 @@ public void testCache() throws MetadataException, IOException, StorageGroupExcep @Test public void testCachedLastTimeValue() - throws MetadataException, IOException, StorageGroupException { + throws MetadataException, IOException, WriteProcessException { mmanager.createTimeseries("root.vehicle.d2.s0", "DOUBLE", "RLE"); TimeValuePair tv1 = new TimeValuePair(1000, TsPrimitiveType.getByType(TSDataType.DOUBLE, 1.0)); diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java index bc4cf4ab90d7b..b54ee42e4db68 100644 --- a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java +++ b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java @@ -27,7 +27,7 @@ import java.util.List; import org.apache.iotdb.db.exception.StorageEngineException; import org.apache.iotdb.db.exception.metadata.MetadataException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupException; +import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; import org.apache.iotdb.db.metadata.mnode.LeafMNode; import org.apache.iotdb.db.metadata.mnode.MNode; import org.apache.iotdb.db.utils.EnvironmentUtils; @@ -77,7 +77,7 @@ public void checkSetUp() { } @Test - public void analyseTimeCost() throws MetadataException, StorageGroupException { + public void analyseTimeCost() throws MetadataException, WriteProcessException { mManager = MManager.getInstance(); long startTime, endTime; @@ -115,7 +115,7 @@ public void analyseTimeCost() throws MetadataException, StorageGroupException { } private void doOriginTest(String deviceId, List measurementList) - throws MetadataException, StorageGroupException { + throws MetadataException, WriteProcessException { for (String measurement : measurementList) { String path = deviceId + "." + measurement; assertTrue(mManager.isPathExist(path)); @@ -125,7 +125,7 @@ private void doOriginTest(String deviceId, List measurementList) } private void doPathLoopOnceTest(String deviceId, List measurementList) - throws MetadataException, StorageGroupException { + throws MetadataException, WriteProcessException { for (String measurement : measurementList) { String path = deviceId + "." + measurement; TSDataType dataType = mManager.getSeriesType(path); @@ -146,7 +146,7 @@ private void doCacheTest(String deviceId, List measurementList) } @Test - public void improveTest() throws MetadataException, StorageGroupException, CacheException { + public void improveTest() throws MetadataException, WriteProcessException, CacheException { mManager = MManager.getInstance(); long startTime, endTime; diff --git a/server/src/test/java/org/apache/iotdb/db/writelog/PerformanceTest.java b/server/src/test/java/org/apache/iotdb/db/writelog/PerformanceTest.java index 109a454203c27..9e6a38f2197b4 100644 --- a/server/src/test/java/org/apache/iotdb/db/writelog/PerformanceTest.java +++ b/server/src/test/java/org/apache/iotdb/db/writelog/PerformanceTest.java @@ -23,7 +23,7 @@ import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.exception.metadata.MetadataException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupException; +import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; import org.apache.iotdb.db.metadata.MManager; import org.apache.iotdb.db.qp.physical.crud.DeletePlan; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; @@ -114,7 +114,7 @@ public void writeLogTest() throws IOException { @Test public void recoverTest() - throws IOException, MetadataException, StorageGroupException { + throws IOException, MetadataException, WriteProcessException { // this test insert 1000000 * 3 logs , recover from them and report elapsed time if (skip) { return; diff --git a/service-rpc/rpc-changelist.md b/service-rpc/rpc-changelist.md index 203882db64159..dd0ad7b85635c 100644 --- a/service-rpc/rpc-changelist.md +++ b/service-rpc/rpc-changelist.md @@ -116,4 +116,5 @@ Last Updated on November 12th, 2019 by Tian Jiang. | ------------------------------------------------------------ | ---------------------- | | Replace TS_SessionHandles with SessionIds, TSOperationHandle with queryIds | Tian Jiang | | Add optional TSQueryNonAlignDataSet in TSExecuteStatementResp, TSFetchResultsResp and required bool isAlign in TSFetchResultsReq | Haonan Hou | -| Rename TSStatusType to TSStatus | Jialin Qiao | \ No newline at end of file +| Rename TSStatusType to TSStatus | Jialin Qiao | +| Remove sessionId in TSExecuteBatchStatementResp | Jialin Qiao | \ No newline at end of file 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 1e909b3c8beaa..44f4a556227bc 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 @@ -28,6 +28,8 @@ public class RpcUtils { + public static TSStatus SUCCESS_STATUS = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()); + public static TSIService.Iface newSynchronizedClient(TSIService.Iface client) { return (TSIService.Iface) Proxy.newProxyInstance(RpcUtils.class.getClassLoader(), new Class[]{TSIService.Iface.class}, new SynchronizedHandler(client)); @@ -57,7 +59,7 @@ public static void verifySuccess(List statuses) throws BatchExecutionE * convert from TSStatusCode to TSStatus according to status code and status message */ public static TSStatus getStatus(TSStatusCode tsStatusCode) { - return new TSStatus(tsStatusCode.getStatusCode(), ""); + return new TSStatus(tsStatusCode.getStatusCode()); } /** @@ -67,7 +69,15 @@ public static TSStatus getStatus(TSStatusCode tsStatusCode) { * @param message appending message */ public static TSStatus getStatus(TSStatusCode tsStatusCode, String message) { - return new TSStatus(tsStatusCode.getStatusCode(), message); + TSStatus status = new TSStatus(tsStatusCode.getStatusCode()); + status.setMessage(message); + return status; + } + + public static TSStatus getStatus(int code, String message) { + TSStatus status = new TSStatus(code); + status.setMessage(message); + return status; } public static TSExecuteStatementResp getTSExecuteStatementResp(TSStatusCode tsStatusCode) { diff --git a/service-rpc/src/main/thrift/rpc.thrift b/service-rpc/src/main/thrift/rpc.thrift index 091316bfcdce5..df19372dca20f 100644 --- a/service-rpc/src/main/thrift/rpc.thrift +++ b/service-rpc/src/main/thrift/rpc.thrift @@ -21,7 +21,7 @@ namespace java org.apache.iotdb.service.rpc.thrift // The return status code and message in each response. struct TSStatus { 1: required i32 code - 2: required string message + 2: optional string message } struct TSExecuteStatementResp { @@ -91,8 +91,7 @@ struct TSExecuteStatementReq { } struct TSExecuteBatchStatementResp{ - 1: required i64 sessionId - 2: required list statusList + 1: required list statusList } struct TSExecuteBatchStatementReq{ From 0fbcd75fbb156ba88cd9b191a10716955e109a66 Mon Sep 17 00:00:00 2001 From: qiaojialin <646274302@qq.com> Date: Tue, 10 Mar 2020 14:51:01 +0800 Subject: [PATCH 4/8] fix example --- .../main/java/org/apache/iotdb/SessionExample.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/example/session/src/main/java/org/apache/iotdb/SessionExample.java b/example/session/src/main/java/org/apache/iotdb/SessionExample.java index 1b40b416b1710..66b10b86f59dc 100644 --- a/example/session/src/main/java/org/apache/iotdb/SessionExample.java +++ b/example/session/src/main/java/org/apache/iotdb/SessionExample.java @@ -18,6 +18,7 @@ */ package org.apache.iotdb; +import org.apache.iotdb.rpc.BatchExecutionException; import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.rpc.StatementExecutionException; import org.apache.iotdb.session.Session; @@ -36,7 +37,7 @@ public class SessionExample { private static Session session; public static void main(String[] args) - throws IoTDBConnectionException, StatementExecutionException { + throws IoTDBConnectionException, StatementExecutionException, BatchExecutionException { session = new Session("127.0.0.1", 6667, "root", "root"); session.open(); @@ -61,7 +62,7 @@ public static void main(String[] args) session.close(); } - private static void insert() throws IoTDBConnectionException { + private static void insert() throws IoTDBConnectionException, StatementExecutionException { String deviceId = "root.sg1.d1"; List measurements = new ArrayList<>(); measurements.add("s1"); @@ -76,7 +77,7 @@ private static void insert() throws IoTDBConnectionException { } } - private static void insertInBatch() throws IoTDBConnectionException { + private static void insertInBatch() throws IoTDBConnectionException, BatchExecutionException { String deviceId = "root.sg1.d1"; List measurements = new ArrayList<>(); measurements.add("s1"); @@ -123,7 +124,7 @@ private static void insertInBatch() throws IoTDBConnectionException { * Users need to control the count of RowBatch and write a batch when it reaches the maxBatchSize * */ - private static void insertRowBatch() throws IoTDBConnectionException { + private static void insertRowBatch() throws IoTDBConnectionException, BatchExecutionException { // The schema of sensors of one device Schema schema = new Schema(); schema.registerMeasurement(new MeasurementSchema("s1", TSDataType.INT64, TSEncoding.RLE)); @@ -154,13 +155,14 @@ private static void insertRowBatch() throws IoTDBConnectionException { } } - private static void deleteData() throws IoTDBConnectionException { + private static void deleteData() throws IoTDBConnectionException, StatementExecutionException { String path = "root.sg1.d1.s1"; long deleteTime = 99; session.deleteData(path, deleteTime); } - private static void deleteTimeseries() throws IoTDBConnectionException { + private static void deleteTimeseries() + throws IoTDBConnectionException, StatementExecutionException { List paths = new ArrayList<>(); paths.add("root.sg1.d1.s1"); paths.add("root.sg1.d1.s2"); From 8df0ba5f55c01b24839bd2fc0602de18ea5e6d54 Mon Sep 17 00:00:00 2001 From: qiaojialin <646274302@qq.com> Date: Tue, 10 Mar 2020 20:26:28 +0800 Subject: [PATCH 5/8] fix flink example --- .../org/apache/iotdb/flink/IoTDBSink.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java b/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java index 1f405d631d9fb..5e933a65ad4c5 100644 --- a/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java +++ b/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java @@ -116,9 +116,14 @@ public void invoke(IN input, Context context) throws Exception { } convertText(event.getDevice(), event.getMeasurements(), event.getValues()); - TSStatus status = session.insert(event.getDevice(), event.getTimestamp(), - event.getMeasurements(), event.getValues()); - LOG.debug("send event result: {}", status); + try { + session.insert(event.getDevice(), event.getTimestamp(), event.getMeasurements(), + event.getValues()); + } catch (Exception e) { + LOG.debug("send event meets error " + e.getMessage(), e); + throw e; + } + LOG.debug("send event successfully"); } public IoTDBSink withBatchSize(int batchSize) { @@ -177,8 +182,13 @@ private void flush() throws Exception { measurementsList.add(event.getMeasurements()); valuesList.add(event.getValues()); } - List statusList = session.insertInBatch(deviceIds, timestamps, measurementsList, valuesList); - LOG.debug("send events result: {}", statusList); + try { + session.insertInBatch(deviceIds, timestamps, measurementsList, valuesList); + } catch (Exception e) { + LOG.debug("send events error " + e.getMessage(), e); + throw e; + } + LOG.debug("send event successfully"); batchList.clear(); } } From 3a34b1022ee5cf1aa445dfd645c0ba5cc81385c7 Mon Sep 17 00:00:00 2001 From: qiaojialin <646274302@qq.com> Date: Tue, 10 Mar 2020 20:26:53 +0800 Subject: [PATCH 6/8] remove unused import --- .../src/main/java/org/apache/iotdb/flink/IoTDBSink.java | 1 - 1 file changed, 1 deletion(-) diff --git a/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java b/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java index 5e933a65ad4c5..6ff97da0b35d9 100644 --- a/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java +++ b/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java @@ -21,7 +21,6 @@ import com.google.common.base.Preconditions; import org.apache.flink.configuration.Configuration; import org.apache.flink.streaming.api.functions.sink.RichSinkFunction; -import org.apache.iotdb.service.rpc.thrift.TSStatus; import org.apache.iotdb.session.Session; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; import org.slf4j.Logger; From 6f1c3ff0088420cedc6501f6181032170f15490d Mon Sep 17 00:00:00 2001 From: qiaojialin <646274302@qq.com> Date: Tue, 10 Mar 2020 22:38:28 +0800 Subject: [PATCH 7/8] fix sonar --- .../java/org/apache/iotdb/flink/IoTDBSink.java | 14 ++------------ .../test/java/org/apache/iotdb/jdbc/BatchTest.java | 2 +- .../org/apache/iotdb/db/engine/StorageEngine.java | 4 ++-- .../engine/storagegroup/StorageGroupProcessor.java | 4 ++-- .../db/engine/storagegroup/TsFileProcessor.java | 2 +- .../StorageGroupProcessorException.java | 2 +- .../{storageGroup => }/WriteProcessException.java | 2 +- .../org/apache/iotdb/db/service/TSServiceImpl.java | 6 +++--- .../iotdb/db/writelog/recover/LogReplayer.java | 2 +- .../writelog/recover/TsFileRecoverPerformer.java | 2 +- .../storagegroup/StorageGroupProcessorTest.java | 4 ++-- .../iotdb/db/engine/storagegroup/TTLTest.java | 2 +- .../iotdb/db/metadata/MManagerAdvancedTest.java | 2 +- .../iotdb/db/metadata/MManagerImproveTest.java | 2 +- .../apache/iotdb/db/writelog/PerformanceTest.java | 2 +- .../iotdb/db/writelog/recover/LogReplayerTest.java | 2 +- .../db/writelog/recover/SeqTsFileRecoverTest.java | 2 +- .../writelog/recover/UnseqTsFileRecoverTest.java | 2 +- .../main/java/org/apache/iotdb/rpc/RpcUtils.java | 2 +- 19 files changed, 25 insertions(+), 35 deletions(-) rename server/src/main/java/org/apache/iotdb/db/exception/{storageGroup => }/StorageGroupProcessorException.java (96%) rename server/src/main/java/org/apache/iotdb/db/exception/{storageGroup => }/WriteProcessException.java (96%) diff --git a/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java b/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java index 6ff97da0b35d9..601bef22a939e 100644 --- a/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java +++ b/flink-iotdb-connector/src/main/java/org/apache/iotdb/flink/IoTDBSink.java @@ -115,13 +115,8 @@ public void invoke(IN input, Context context) throws Exception { } convertText(event.getDevice(), event.getMeasurements(), event.getValues()); - try { - session.insert(event.getDevice(), event.getTimestamp(), event.getMeasurements(), + session.insert(event.getDevice(), event.getTimestamp(), event.getMeasurements(), event.getValues()); - } catch (Exception e) { - LOG.debug("send event meets error " + e.getMessage(), e); - throw e; - } LOG.debug("send event successfully"); } @@ -181,12 +176,7 @@ private void flush() throws Exception { measurementsList.add(event.getMeasurements()); valuesList.add(event.getValues()); } - try { - session.insertInBatch(deviceIds, timestamps, measurementsList, valuesList); - } catch (Exception e) { - LOG.debug("send events error " + e.getMessage(), e); - throw e; - } + session.insertInBatch(deviceIds, timestamps, measurementsList, valuesList); LOG.debug("send event successfully"); batchList.clear(); } diff --git a/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java b/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java index c3f290dd2bb36..814ad125b435c 100644 --- a/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java +++ b/jdbc/src/test/java/org/apache/iotdb/jdbc/BatchTest.java @@ -75,7 +75,7 @@ public void testExecuteBatchSQL1() throws SQLException, TException { resp = RpcUtils.getTSBatchExecuteStatementResp(TSStatusCode.SUCCESS_STATUS); when(client.executeBatchStatement(any(TSExecuteBatchStatementReq.class))).thenReturn(resp); int[] result = statement.executeBatch(); - assertEquals(result.length, 1); + assertEquals(1, result.length); List resExpected = new ArrayList() { { diff --git a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java index 75d0a6c4488a1..9680f39128ae5 100644 --- a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java @@ -54,8 +54,8 @@ import org.apache.iotdb.db.exception.metadata.StorageGroupNotSetException; import org.apache.iotdb.db.exception.query.QueryProcessException; import org.apache.iotdb.db.exception.runtime.StorageEngineFailureException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; -import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; +import org.apache.iotdb.db.exception.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.WriteProcessException; import org.apache.iotdb.db.metadata.MManager; import org.apache.iotdb.db.metadata.mnode.StorageGroupMNode; import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan; diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java index af3eec800261a..16bfb4a295a6f 100755 --- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessor.java @@ -68,8 +68,8 @@ import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.query.OutOfTTLException; import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; -import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; +import org.apache.iotdb.db.exception.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.WriteProcessException; import org.apache.iotdb.db.metadata.MManager; import org.apache.iotdb.db.metadata.mnode.LeafMNode; import org.apache.iotdb.db.metadata.mnode.MNode; diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java index 8dfbcfac737c2..a770882e3d2e1 100644 --- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java +++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/TsFileProcessor.java @@ -46,7 +46,7 @@ import org.apache.iotdb.db.engine.version.VersionController; import org.apache.iotdb.db.exception.TsFileProcessorException; import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; +import org.apache.iotdb.db.exception.WriteProcessException; import org.apache.iotdb.db.qp.constant.DatetimeUtils; import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; diff --git a/server/src/main/java/org/apache/iotdb/db/exception/storageGroup/StorageGroupProcessorException.java b/server/src/main/java/org/apache/iotdb/db/exception/StorageGroupProcessorException.java similarity index 96% rename from server/src/main/java/org/apache/iotdb/db/exception/storageGroup/StorageGroupProcessorException.java rename to server/src/main/java/org/apache/iotdb/db/exception/StorageGroupProcessorException.java index 9bae99d3af1ad..e4a2236be73cb 100644 --- a/server/src/main/java/org/apache/iotdb/db/exception/storageGroup/StorageGroupProcessorException.java +++ b/server/src/main/java/org/apache/iotdb/db/exception/StorageGroupProcessorException.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.iotdb.db.exception.storageGroup; +package org.apache.iotdb.db.exception; import org.apache.iotdb.db.exception.IoTDBException; import org.apache.iotdb.rpc.TSStatusCode; diff --git a/server/src/main/java/org/apache/iotdb/db/exception/storageGroup/WriteProcessException.java b/server/src/main/java/org/apache/iotdb/db/exception/WriteProcessException.java similarity index 96% rename from server/src/main/java/org/apache/iotdb/db/exception/storageGroup/WriteProcessException.java rename to server/src/main/java/org/apache/iotdb/db/exception/WriteProcessException.java index 809d5038d6496..d5a0243bda97d 100644 --- a/server/src/main/java/org/apache/iotdb/db/exception/storageGroup/WriteProcessException.java +++ b/server/src/main/java/org/apache/iotdb/db/exception/WriteProcessException.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.iotdb.db.exception.storageGroup; +package org.apache.iotdb.db.exception; import org.apache.iotdb.db.exception.IoTDBException; import org.apache.iotdb.rpc.TSStatusCode; 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 f83e57a201f84..6e4b18b6c9f66 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 @@ -466,12 +466,12 @@ private boolean executeStatementInBatch(String statement, List result, } catch (ParseCancellationException e) { logger.debug(e.getMessage()); result.add(RpcUtils.getStatus(TSStatusCode.SQL_PARSE_ERROR, - "Statement format is not right: " + e.getMessage())); + ERROR_PARSING_SQL + e.getMessage())); return false; } catch (SQLParserException e) { logger.error("Error occurred when executing {}, check metadata error: ", statement, e); result.add(RpcUtils.getStatus( - TSStatusCode.SQL_PARSE_ERROR, "Statement format is not right: " + e.getMessage())); + TSStatusCode.SQL_PARSE_ERROR, ERROR_PARSING_SQL + e.getMessage())); return false; } catch (QueryProcessException e) { logger.info( @@ -583,7 +583,7 @@ public TSExecuteStatementResp executeQueryStatement(TSExecuteStatementReq req) { } catch (ParseCancellationException e) { logger.debug(e.getMessage()); return RpcUtils.getTSExecuteStatementResp(TSStatusCode.SQL_PARSE_ERROR, - "Statement format is not right: " + e.getMessage()); + ERROR_PARSING_SQL + e.getMessage()); } catch (SQLParserException e) { logger.error("check metadata error: ", e); return RpcUtils.getTSExecuteStatementResp( diff --git a/server/src/main/java/org/apache/iotdb/db/writelog/recover/LogReplayer.java b/server/src/main/java/org/apache/iotdb/db/writelog/recover/LogReplayer.java index e1298a5357af4..3d3b9770d45f5 100644 --- a/server/src/main/java/org/apache/iotdb/db/writelog/recover/LogReplayer.java +++ b/server/src/main/java/org/apache/iotdb/db/writelog/recover/LogReplayer.java @@ -29,7 +29,7 @@ import org.apache.iotdb.db.engine.storagegroup.TsFileResource; import org.apache.iotdb.db.engine.version.VersionController; import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.StorageGroupProcessorException; import org.apache.iotdb.db.qp.physical.PhysicalPlan; import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan; import org.apache.iotdb.db.qp.physical.crud.DeletePlan; diff --git a/server/src/main/java/org/apache/iotdb/db/writelog/recover/TsFileRecoverPerformer.java b/server/src/main/java/org/apache/iotdb/db/writelog/recover/TsFileRecoverPerformer.java index bd0c2d6c4299c..a2412683f4aa9 100644 --- a/server/src/main/java/org/apache/iotdb/db/writelog/recover/TsFileRecoverPerformer.java +++ b/server/src/main/java/org/apache/iotdb/db/writelog/recover/TsFileRecoverPerformer.java @@ -34,7 +34,7 @@ import org.apache.iotdb.db.engine.memtable.PrimitiveMemTable; import org.apache.iotdb.db.engine.storagegroup.TsFileResource; import org.apache.iotdb.db.engine.version.VersionController; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.StorageGroupProcessorException; import org.apache.iotdb.db.utils.FileLoaderUtils; import org.apache.iotdb.db.writelog.manager.MultiFileLogNodeManager; import org.apache.iotdb.tsfile.file.metadata.ChunkGroupMetaData; diff --git a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java index 16e6928d1e04c..e86a9851db541 100644 --- a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java +++ b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/StorageGroupProcessorTest.java @@ -27,8 +27,8 @@ import org.apache.iotdb.db.engine.querycontext.ReadOnlyMemChunk; import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; -import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; +import org.apache.iotdb.db.exception.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.WriteProcessException; import org.apache.iotdb.db.qp.physical.crud.BatchInsertPlan; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; import org.apache.iotdb.db.query.context.QueryContext; diff --git a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TTLTest.java b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TTLTest.java index 042a9fbf31c69..d28006bc9d4b1 100644 --- a/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TTLTest.java +++ b/server/src/test/java/org/apache/iotdb/db/engine/storagegroup/TTLTest.java @@ -39,7 +39,7 @@ import org.apache.iotdb.db.exception.metadata.MetadataException; import org.apache.iotdb.db.exception.query.OutOfTTLException; import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.StorageGroupProcessorException; import org.apache.iotdb.db.metadata.MManager; import org.apache.iotdb.db.metadata.mnode.StorageGroupMNode; import org.apache.iotdb.db.qp.Planner; diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java index f01f732bbbd21..b7e7ce711af5c 100644 --- a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java +++ b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerAdvancedTest.java @@ -24,7 +24,7 @@ import java.io.IOException; import java.util.List; import org.apache.iotdb.db.exception.metadata.MetadataException; -import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; +import org.apache.iotdb.db.exception.WriteProcessException; import org.apache.iotdb.db.metadata.mnode.LeafMNode; import org.apache.iotdb.db.metadata.mnode.MNode; import org.apache.iotdb.db.utils.EnvironmentUtils; diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java index b54ee42e4db68..f8f04ff652e5f 100644 --- a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java +++ b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerImproveTest.java @@ -27,7 +27,7 @@ import java.util.List; import org.apache.iotdb.db.exception.StorageEngineException; import org.apache.iotdb.db.exception.metadata.MetadataException; -import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; +import org.apache.iotdb.db.exception.WriteProcessException; import org.apache.iotdb.db.metadata.mnode.LeafMNode; import org.apache.iotdb.db.metadata.mnode.MNode; import org.apache.iotdb.db.utils.EnvironmentUtils; diff --git a/server/src/test/java/org/apache/iotdb/db/writelog/PerformanceTest.java b/server/src/test/java/org/apache/iotdb/db/writelog/PerformanceTest.java index 9e6a38f2197b4..432d527b4faef 100644 --- a/server/src/test/java/org/apache/iotdb/db/writelog/PerformanceTest.java +++ b/server/src/test/java/org/apache/iotdb/db/writelog/PerformanceTest.java @@ -23,7 +23,7 @@ import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.exception.metadata.MetadataException; -import org.apache.iotdb.db.exception.storageGroup.WriteProcessException; +import org.apache.iotdb.db.exception.WriteProcessException; import org.apache.iotdb.db.metadata.MManager; import org.apache.iotdb.db.qp.physical.crud.DeletePlan; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; diff --git a/server/src/test/java/org/apache/iotdb/db/writelog/recover/LogReplayerTest.java b/server/src/test/java/org/apache/iotdb/db/writelog/recover/LogReplayerTest.java index 5792fb693e482..2fdac8339d235 100644 --- a/server/src/test/java/org/apache/iotdb/db/writelog/recover/LogReplayerTest.java +++ b/server/src/test/java/org/apache/iotdb/db/writelog/recover/LogReplayerTest.java @@ -36,7 +36,7 @@ import org.apache.iotdb.db.engine.storagegroup.TsFileResource; import org.apache.iotdb.db.engine.version.VersionController; import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.StorageGroupProcessorException; import org.apache.iotdb.db.qp.physical.crud.DeletePlan; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; import org.apache.iotdb.db.writelog.manager.MultiFileLogNodeManager; diff --git a/server/src/test/java/org/apache/iotdb/db/writelog/recover/SeqTsFileRecoverTest.java b/server/src/test/java/org/apache/iotdb/db/writelog/recover/SeqTsFileRecoverTest.java index 0e5bbbe9821ce..bec0cf85aad2c 100644 --- a/server/src/test/java/org/apache/iotdb/db/writelog/recover/SeqTsFileRecoverTest.java +++ b/server/src/test/java/org/apache/iotdb/db/writelog/recover/SeqTsFileRecoverTest.java @@ -34,7 +34,7 @@ import org.apache.iotdb.db.engine.flush.pool.FlushSubTaskPoolManager; import org.apache.iotdb.db.engine.storagegroup.TsFileResource; import org.apache.iotdb.db.engine.version.VersionController; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.StorageGroupProcessorException; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; import org.apache.iotdb.db.writelog.manager.MultiFileLogNodeManager; import org.apache.iotdb.db.writelog.node.WriteLogNode; diff --git a/server/src/test/java/org/apache/iotdb/db/writelog/recover/UnseqTsFileRecoverTest.java b/server/src/test/java/org/apache/iotdb/db/writelog/recover/UnseqTsFileRecoverTest.java index f6ff4efc9f333..57c9359cba204 100644 --- a/server/src/test/java/org/apache/iotdb/db/writelog/recover/UnseqTsFileRecoverTest.java +++ b/server/src/test/java/org/apache/iotdb/db/writelog/recover/UnseqTsFileRecoverTest.java @@ -25,7 +25,7 @@ import org.apache.iotdb.db.engine.flush.pool.FlushSubTaskPoolManager; import org.apache.iotdb.db.engine.storagegroup.TsFileResource; import org.apache.iotdb.db.engine.version.VersionController; -import org.apache.iotdb.db.exception.storageGroup.StorageGroupProcessorException; +import org.apache.iotdb.db.exception.StorageGroupProcessorException; import org.apache.iotdb.db.qp.physical.crud.InsertPlan; import org.apache.iotdb.db.query.reader.chunk.ChunkDataIterator; import org.apache.iotdb.db.query.reader.universal.PriorityMergeReader; 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 44f4a556227bc..df2761ec82f25 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 @@ -28,7 +28,7 @@ public class RpcUtils { - public static TSStatus SUCCESS_STATUS = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()); + public static final TSStatus SUCCESS_STATUS = new TSStatus(TSStatusCode.SUCCESS_STATUS.getStatusCode()); public static TSIService.Iface newSynchronizedClient(TSIService.Iface client) { return (TSIService.Iface) Proxy.newProxyInstance(RpcUtils.class.getClassLoader(), From 12226d9ee38839d7490b1f2f67ebb18113afe966 Mon Sep 17 00:00:00 2001 From: qiaojialin <646274302@qq.com> Date: Tue, 10 Mar 2020 22:39:11 +0800 Subject: [PATCH 8/8] remove unused import --- .../iotdb/db/exception/StorageGroupProcessorException.java | 1 - .../org/apache/iotdb/db/exception/WriteProcessException.java | 1 - 2 files changed, 2 deletions(-) diff --git a/server/src/main/java/org/apache/iotdb/db/exception/StorageGroupProcessorException.java b/server/src/main/java/org/apache/iotdb/db/exception/StorageGroupProcessorException.java index e4a2236be73cb..9a29e7ad7c92c 100644 --- a/server/src/main/java/org/apache/iotdb/db/exception/StorageGroupProcessorException.java +++ b/server/src/main/java/org/apache/iotdb/db/exception/StorageGroupProcessorException.java @@ -18,7 +18,6 @@ */ package org.apache.iotdb.db.exception; -import org.apache.iotdb.db.exception.IoTDBException; import org.apache.iotdb.rpc.TSStatusCode; public class StorageGroupProcessorException extends IoTDBException { diff --git a/server/src/main/java/org/apache/iotdb/db/exception/WriteProcessException.java b/server/src/main/java/org/apache/iotdb/db/exception/WriteProcessException.java index d5a0243bda97d..9ae88efd8d9dd 100644 --- a/server/src/main/java/org/apache/iotdb/db/exception/WriteProcessException.java +++ b/server/src/main/java/org/apache/iotdb/db/exception/WriteProcessException.java @@ -19,7 +19,6 @@ package org.apache.iotdb.db.exception; -import org.apache.iotdb.db.exception.IoTDBException; import org.apache.iotdb.rpc.TSStatusCode; public class WriteProcessException extends IoTDBException {