You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2019/12/06 00:41:38 UTC

[incubator-iotdb] branch master updated: [IOTDB-343] Add test method in session (#629)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 87f54a4  [IOTDB-343] Add test method in session (#629)
87f54a4 is described below

commit 87f54a4681aaf7cf5114dfe81692bcf0962e7d37
Author: SilverNarcissus <15...@smail.nju.edu.cn>
AuthorDate: Thu Dec 5 18:41:12 2019 -0600

    [IOTDB-343] Add test method in session (#629)
---
 .../UserGuide/4-Client/3-Programming - Session.md  | 12 ++++
 .../org/apache/iotdb/db/service/TSServiceImpl.java | 34 ++++++++--
 service-rpc/rpc-changelist.md                      |  3 +
 service-rpc/src/main/thrift/rpc.thrift             | 10 ++-
 .../java/org/apache/iotdb/session/Session.java     | 79 +++++++++++++++++++++-
 .../org/apache/iotdb/session/IoTDBSessionIT.java   | 63 +++++++++++++++++
 6 files changed, 194 insertions(+), 7 deletions(-)

diff --git a/docs/Documentation/UserGuide/4-Client/3-Programming - Session.md b/docs/Documentation/UserGuide/4-Client/3-Programming - Session.md
index 87d949a..83261c0 100644
--- a/docs/Documentation/UserGuide/4-Client/3-Programming - Session.md	
+++ b/docs/Documentation/UserGuide/4-Client/3-Programming - Session.md	
@@ -112,6 +112,18 @@ Here we show the commonly used interfaces and their parameters in the Session:
 * Batch insertion into timeseries
 
   ​	TSExecuteBatchStatementResp insertBatch(RowBatch rowBatch)
+  
+* Test Insert data into existing timeseries in batch. This method NOT insert data into database and server just return after accept the request, this method should be used to test other time cost in client
+ 
+   ​	TSStatus testInsertInBatch(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList)
+
+* Insert data into existing timeseries. This method NOT insert data into database and server just return after accept the request, this method should be used to test other time cost in client
+
+  ​	TSStatus testInsert(String deviceId, long time, List<String> measurements, List<String> values)
+
+* Batch insertion into timeseries. This method NOT insert data into database and server just return after accept the request, this method should be used to test other time cost in client
+
+  ​	TSExecuteBatchStatementResp testInsertBatch(RowBatch rowBatch)
 
 #### Sample code
 
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 03bca46..881ae39 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
@@ -34,6 +34,7 @@ import java.sql.Statement;
 import java.time.ZoneId;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -636,7 +637,8 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
   }
 
   /**
-   * @param plan must be a plan for Query: FillQueryPlan, AggregationPlan, GroupByPlan, some AuthorPlan
+   * @param plan must be a plan for Query: FillQueryPlan, AggregationPlan, GroupByPlan, some
+   * AuthorPlan
    */
   private TSExecuteStatementResp executeQueryStatement(long statementId, PhysicalPlan plan) {
     long t1 = System.currentTimeMillis();
@@ -1173,9 +1175,8 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
       plan.setValues(req.getValuesList().get(i).toArray(new String[0]));
       TSStatus status = checkAuthority(plan);
       if (status != null) {
-          resp.addToStatusList(new TSStatus(status));
-      }
-      else{
+        resp.addToStatusList(new TSStatus(status));
+      } else {
         resp.addToStatusList(executePlan(plan));
       }
     }
@@ -1183,6 +1184,31 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     return resp;
   }
 
+  @Override
+  public TSExecuteBatchStatementResp testInsertBatch(TSBatchInsertionReq req) throws TException {
+    logger.debug("Test insert batch request receive.");
+    TSExecuteBatchStatementResp resp = new TSExecuteBatchStatementResp();
+    resp.setStatus(getStatus(TSStatusCode.SUCCESS_STATUS));
+    resp.setResult(Collections.emptyList());
+    return resp;
+  }
+
+  @Override
+  public TSStatus testInsertRow(TSInsertReq req) throws TException {
+    logger.debug("Test insert row request receive.");
+    return getStatus(TSStatusCode.SUCCESS_STATUS);
+  }
+
+  @Override
+  public TSExecuteInsertRowInBatchResp testInsertRowInBatch(TSInsertInBatchReq req)
+      throws TException {
+    logger.debug("Test insert row in batch request receive.");
+
+    TSExecuteInsertRowInBatchResp resp = new TSExecuteInsertRowInBatchResp();
+    resp.addToStatusList(getStatus(TSStatusCode.SUCCESS_STATUS));
+    return resp;
+  }
+
 
   @Override
   public TSStatus insertRow(TSInsertReq req) {
diff --git a/service-rpc/rpc-changelist.md b/service-rpc/rpc-changelist.md
index 6425a98..0b0194b 100644
--- a/service-rpc/rpc-changelist.md
+++ b/service-rpc/rpc-changelist.md
@@ -53,6 +53,9 @@ Last Updated on October 27th, 2019 by Lei Rui.
 | Add method TSStatus deleteStorageGroups(1:list\<string> storageGroup) | Yi Tao                             |
 | Add Struct TSExecuteInsertRowInBatchResp                     | Kaifeng Xue |
 | Add method insertRowInBatch(1:TSInsertInBatchReq req);       | Kaifeng Xue |
+| Add method testInsertRowInBatch(1:TSInsertInBatchReq req);   | Kaifeng Xue |
+| Add method testInsertRow(1:TSInsertReq req);                 | Kaifeng Xue |
+| Add method testInsertBatch(1:TSBatchInsertionReq req);       | Kaifeng Xue |
 
 
 ## 3. Update
diff --git a/service-rpc/src/main/thrift/rpc.thrift b/service-rpc/src/main/thrift/rpc.thrift
index 6ad4e34..bf716a3 100644
--- a/service-rpc/src/main/thrift/rpc.thrift
+++ b/service-rpc/src/main/thrift/rpc.thrift
@@ -299,8 +299,6 @@ service TSIService {
 
 	TSExecuteStatementResp insert(1:TSInsertionReq req);
 
-	TSExecuteBatchStatementResp insertBatch(1:TSBatchInsertionReq req);
-
 	TSStatus setStorageGroup(1:string storageGroup);
 
 	TSStatus createTimeseries(1:TSCreateTimeseriesReq req);
@@ -309,10 +307,18 @@ service TSIService {
 
   TSStatus deleteStorageGroups(1:list<string> storageGroup);
 
+  TSExecuteBatchStatementResp insertBatch(1:TSBatchInsertionReq req);
+
 	TSStatus insertRow(1:TSInsertReq req);
 
 	TSExecuteInsertRowInBatchResp insertRowInBatch(1:TSInsertInBatchReq req);
 
+	TSExecuteBatchStatementResp testInsertBatch(1:TSBatchInsertionReq req);
+
+  TSStatus testInsertRow(1:TSInsertReq req);
+
+  TSExecuteInsertRowInBatchResp testInsertRowInBatch(1:TSInsertInBatchReq req);
+
 	TSStatus deleteData(1:TSDeleteDataReq req);
 
 	i64 requestStatementId();
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 e2a8213..2f464dc 100644
--- a/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -22,6 +22,7 @@ import static org.apache.iotdb.session.Config.PATH_MATCHER;
 
 import java.time.ZoneId;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.regex.Pattern;
 import org.apache.commons.lang.StringEscapeUtils;
@@ -192,7 +193,11 @@ public class Session {
   }
 
   /**
-   * insert data in batch format, which can reduce the overhead of network
+   * Insert data in batch format, which can reduce the overhead of network. This method is just like
+   * jdbc batch insert, we pack some insert request in batch and send them to server If you want
+   * improve your performance, please see insertBatch method
+   *
+   * @see Session#insertBatch(RowBatch)
    */
   public List<TSStatus> insertInBatch(List<String> deviceIds, List<Long> times,
       List<List<String>> measurementsList,
@@ -246,6 +251,78 @@ public class Session {
   }
 
   /**
+   * 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 IoTDBSessionException {
+    TSBatchInsertionReq request = new TSBatchInsertionReq();
+    request.deviceId = rowBatch.deviceId;
+    for (MeasurementSchema measurementSchema : rowBatch.measurements) {
+      request.addToMeasurements(measurementSchema.getMeasurementId());
+      request.addToTypes(measurementSchema.getType().ordinal());
+    }
+    request.setTimestamps(SessionUtils.getTimeBuffer(rowBatch));
+    request.setValues(SessionUtils.getValueBuffer(rowBatch));
+    request.setSize(rowBatch.batchSize);
+
+    try {
+      return client.testInsertBatch(request);
+    } catch (TException e) {
+      throw new IoTDBSessionException(e);
+    }
+  }
+
+  /**
+   * 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<TSStatus> testInsertInBatch(List<String> deviceIds, List<Long> times,
+      List<List<String>> measurementsList,
+      List<List<String>> valuesList)
+      throws IoTDBSessionException {
+    // check params size
+    int len = deviceIds.size();
+    if (len != times.size() || len != measurementsList.size() || len != valuesList.size()) {
+      throw new IllegalArgumentException(
+          "deviceIds, times, measurementsList and valuesList's size should be equal");
+    }
+
+    TSInsertInBatchReq request = new TSInsertInBatchReq();
+    request.setDeviceIds(deviceIds);
+    request.setTimestamps(times);
+    request.setMeasurementsList(measurementsList);
+    request.setValuesList(valuesList);
+
+    try {
+      client.testInsertRowInBatch(request);
+      return Collections.emptyList();
+    } catch (TException e) {
+      throw new IoTDBSessionException(e);
+    }
+  }
+
+  /**
+   * 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<String> measurements,
+      List<String> values)
+      throws IoTDBSessionException {
+    TSInsertReq request = new TSInsertReq();
+    request.setDeviceId(deviceId);
+    request.setTimestamp(time);
+    request.setMeasurements(measurements);
+    request.setValues(values);
+
+    try {
+      return client.testInsertRow(request);
+    } catch (TException e) {
+      throw new IoTDBSessionException(e);
+    }
+  }
+
+  /**
    * delete a timeseries, including data and schema
    *
    * @param path timeseries to delete, should be a whole path
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 7c335bf..2669381 100644
--- a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
+++ b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
@@ -72,6 +72,69 @@ public class IoTDBSessionIT {
   }
 
   @Test
+  public void testTestMethod() throws IoTDBSessionException {
+    session = new Session("127.0.0.1", 6667, "root", "root");
+    session.open();
+
+    session.setStorageGroup("root.sg1");
+
+    // test insert batch
+    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));
+
+    RowBatch rowBatch = schema.createRowBatch("root.sg1.d1", 100);
+
+    session.testInsertBatch(rowBatch);
+
+    // test insert row
+    String deviceId = "root.sg1.d1";
+    List<String> measurements = new ArrayList<>();
+    measurements.add("s1");
+    measurements.add("s2");
+    measurements.add("s3");
+    for (long time = 0; time < 100; time++) {
+      List<String> values = new ArrayList<>();
+      values.add("1");
+      values.add("2");
+      values.add("3");
+      session.testInsert(deviceId, time, measurements, values);
+    }
+
+    // test insert row in batch
+    measurements = new ArrayList<>();
+    measurements.add("s1");
+    measurements.add("s2");
+    measurements.add("s3");
+    List<String> deviceIds = new ArrayList<>();
+    List<List<String>> measurementsList = new ArrayList<>();
+    List<List<String>> valuesList = new ArrayList<>();
+    List<Long> timestamps = new ArrayList<>();
+
+    for (long time = 0; time < 500; time++) {
+      List<String> values = new ArrayList<>();
+      values.add("1");
+      values.add("2");
+      values.add("3");
+
+      deviceIds.add(deviceId);
+      measurementsList.add(measurements);
+      valuesList.add(values);
+      timestamps.add(time);
+      if (time != 0 && time % 100 == 0) {
+        session.testInsertInBatch(deviceIds, timestamps, measurementsList, valuesList);
+        deviceIds.clear();
+        measurementsList.clear();
+        valuesList.clear();
+        timestamps.clear();
+      }
+    }
+
+    session.testInsertInBatch(deviceIds, timestamps, measurementsList, valuesList);
+  }
+
+  @Test
   public void test()
       throws ClassNotFoundException, SQLException, IoTDBSessionException, TException, IoTDBRPCException {
     session = new Session("127.0.0.1", 6667, "root", "root");