You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/08/06 04:44:28 UTC

[GitHub] [incubator-iotdb] qiaojialin opened a new pull request #1601: add a data migration example

qiaojialin opened a new pull request #1601:
URL: https://github.com/apache/incubator-iotdb/pull/1601


   Migrate data from one IoTDB to another IoTDB.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #1601: add a data migration example

Posted by GitBox <gi...@apache.org>.
qiaojialin commented on a change in pull request #1601:
URL: https://github.com/apache/incubator-iotdb/pull/1601#discussion_r467973679



##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;
+      Path currentPath = new Path(schemaIter.getString("timeseries"));
+      Future future = executorService.submit(new LoadThread(count, currentPath, TSDataType.valueOf(schemaIter.getString("dataType"))));

Review comment:
       Yes, it's my purpose. 
   awaitTermination() needs a timeout interval, which is hard to determine. We could return something using callable in the future, such as recording a log.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] sonarcloud[bot] commented on pull request #1601: add a data migration example

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on pull request #1601:
URL: https://github.com/apache/incubator-iotdb/pull/1601#issuecomment-671434206


   Kudos, SonarCloud Quality Gate passed!
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug.png' alt='Bug' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=BUG) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=BUG)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability.png' alt='Vulnerability' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=VULNERABILITY) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=VULNERABILITY) (and [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot.png' alt='Security Hotspot' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/i
 ssues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=SECURITY_HOTSPOT) to review)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell.png' alt='Code Smell' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=CODE_SMELL) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=CODE_SMELL)
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo.png' alt='No Coverage information' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=1601) No Coverage information  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3.png' alt='0.0%' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=1601&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=1601&metric=new_duplicated_lines_density&view=list)
   
   <img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/message_warning.png' alt='warning' width='16' height='16' /> The version of Java (1.8.0_252) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
   Read more [here](https://sonarcloud.io/documentation/upcoming/)
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] Alima777 commented on a change in pull request #1601: add a data migration example

Posted by GitBox <gi...@apache.org>.
Alima777 commented on a change in pull request #1601:
URL: https://github.com/apache/incubator-iotdb/pull/1601#discussion_r467982827



##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;
+      Path currentPath = new Path(schemaIter.getString("timeseries"));
+      Future future = executorService.submit(new LoadThread(count, currentPath, TSDataType.valueOf(schemaIter.getString("dataType"))));

Review comment:
       I agree with the point that if something can be reused as return value, callable will be better and it has to be.
   
   Then as an EXAMPLE, just keep this and add some comment here to show users more choices may be better. Anyway, maybe users can decide the timeout.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #1601: add a data migration example

Posted by GitBox <gi...@apache.org>.
qiaojialin commented on a change in pull request #1601:
URL: https://github.com/apache/incubator-iotdb/pull/1601#discussion_r467963582



##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;
+      Path currentPath = new Path(schemaIter.getString("timeseries"));
+      Future future = executorService.submit(new LoadThread(count, currentPath, TSDataType.valueOf(schemaIter.getString("dataType"))));
+      futureList.add(future);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+    for (Future future: futureList) {

Review comment:
       fixed

##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;

Review comment:
       fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] sonarcloud[bot] removed a comment on pull request #1601: add a data migration example

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] removed a comment on pull request #1601:
URL: https://github.com/apache/incubator-iotdb/pull/1601#issuecomment-669702961


   Kudos, SonarCloud Quality Gate passed!
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug.png' alt='Bug' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=BUG) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=BUG)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability.png' alt='Vulnerability' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=VULNERABILITY) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=VULNERABILITY) (and [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot.png' alt='Security Hotspot' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/i
 ssues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=SECURITY_HOTSPOT) to review)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell.png' alt='Code Smell' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=CODE_SMELL) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=CODE_SMELL)
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo.png' alt='No Coverage information' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=1601) No Coverage information  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3.png' alt='0.0%' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=1601&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=1601&metric=new_duplicated_lines_density&view=list)
   
   <img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/message_warning.png' alt='warning' width='16' height='16' /> The version of Java (1.8.0_252) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
   Read more [here](https://sonarcloud.io/documentation/upcoming/)
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] sonarcloud[bot] commented on pull request #1601: add a data migration example

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on pull request #1601:
URL: https://github.com/apache/incubator-iotdb/pull/1601#issuecomment-669702961


   Kudos, SonarCloud Quality Gate passed!
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug.png' alt='Bug' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=BUG) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=BUG)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability.png' alt='Vulnerability' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=VULNERABILITY) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=VULNERABILITY) (and [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot.png' alt='Security Hotspot' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/i
 ssues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=SECURITY_HOTSPOT) to review)  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell.png' alt='Code Smell' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=CODE_SMELL) [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A.png' alt='A' width='16' height='16' />](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=1601&resolved=false&types=CODE_SMELL)
   
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo.png' alt='No Coverage information' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=1601) No Coverage information  
   [<img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3.png' alt='0.0%' width='16' height='16' />](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=1601&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=1601&metric=new_duplicated_lines_density&view=list)
   
   <img src='https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/message_warning.png' alt='warning' width='16' height='16' /> The version of Java (1.8.0_252) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
   Read more [here](https://sonarcloud.io/documentation/upcoming/)
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] qiaojialin merged pull request #1601: add a data migration example

Posted by GitBox <gi...@apache.org>.
qiaojialin merged pull request #1601:
URL: https://github.com/apache/incubator-iotdb/pull/1601


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #1601: add a data migration example

Posted by GitBox <gi...@apache.org>.
qiaojialin commented on a change in pull request #1601:
URL: https://github.com/apache/incubator-iotdb/pull/1601#discussion_r467963768



##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;
+      Path currentPath = new Path(schemaIter.getString("timeseries"));
+      Future future = executorService.submit(new LoadThread(count, currentPath, TSDataType.valueOf(schemaIter.getString("dataType"))));
+      futureList.add(future);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+    for (Future future: futureList) {
+      future.get();
+    }
+    executorService.shutdown();
+
+    readerPool.close();
+    readerPool.close();

Review comment:
       fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-iotdb] Alima777 commented on a change in pull request #1601: add a data migration example

Posted by GitBox <gi...@apache.org>.
Alima777 commented on a change in pull request #1601:
URL: https://github.com/apache/incubator-iotdb/pull/1601#discussion_r467883864



##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;
+      Path currentPath = new Path(schemaIter.getString("timeseries"));
+      Future future = executorService.submit(new LoadThread(count, currentPath, TSDataType.valueOf(schemaIter.getString("dataType"))));

Review comment:
       Are you aimed at blocking the main thread until the end of writing thread using Callable and Future interface? If so, I think using Runnable and executorService.awaitTermination() instead of Future is better.

##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;

Review comment:
       ```suggestion
         count++;
   ```

##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;
+      Path currentPath = new Path(schemaIter.getString("timeseries"));
+      Future future = executorService.submit(new LoadThread(count, currentPath, TSDataType.valueOf(schemaIter.getString("dataType"))));
+      futureList.add(future);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+    for (Future future: futureList) {
+      future.get();
+    }
+    executorService.shutdown();
+
+    readerPool.close();
+    readerPool.close();

Review comment:
       writerPool.close()?

##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;

Review comment:
       Pay attention to the code style.

##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;
+      Path currentPath = new Path(schemaIter.getString("timeseries"));
+      Future future = executorService.submit(new LoadThread(count, currentPath, TSDataType.valueOf(schemaIter.getString("dataType"))));
+      futureList.add(future);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+    for (Future future: futureList) {

Review comment:
       ```suggestion
       for (Future future : futureList) {
   ```

##########
File path: example/session/src/main/java/org/apache/iotdb/DataMigrationExample.java
##########
@@ -0,0 +1,183 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.session.SessionDataSet.DataIterator;
+import org.apache.iotdb.session.pool.SessionDataSetWrapper;
+import org.apache.iotdb.session.pool.SessionPool;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.read.common.Path;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.apache.iotdb.tsfile.write.record.Tablet;
+import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
+
+
+/**
+ * Migrate all data belongs to a path from one IoTDB to another IoTDB
+ * Each thread migrate one series, the concurrent thread can be configured by concurrency
+ *
+ * This example is
+ * migrating all timeseries from a local IoTDB with 6667 port to a local IoTDB with 6668 port
+ */
+public class DataMigrationExample {
+
+  // used to read data from the source IoTDB
+  private static SessionPool readerPool;
+  // used to write data into the destination IoTDB
+  private static SessionPool writerPool;
+  // concurrent thread of loading timeseries data
+  private static int concurrency = 5;
+
+  public static void main(String[] args)
+      throws IoTDBConnectionException, StatementExecutionException, ExecutionException, InterruptedException {
+
+    ExecutorService executorService = Executors.newFixedThreadPool(2 * concurrency + 1);
+
+    String path = "root";
+
+    if (args.length != 0) {
+      path = args[0];
+    }
+
+    readerPool = new SessionPool("127.0.0.1", 6667, "root", "root", concurrency);
+    writerPool = new SessionPool("127.0.0.1", 6668, "root", "root", concurrency);
+
+    SessionDataSetWrapper schemaDataSet = readerPool.executeQueryStatement("count timeseries " + path);
+    DataIterator schemaIter = schemaDataSet.iterator();
+    int total;
+    if (schemaIter.next()) {
+      total = schemaIter.getInt(1);
+      System.out.println("Total timeseries: " + total);
+    } else {
+      System.out.println("Can not get timeseries schema");
+      System.exit(1);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+
+    schemaDataSet = readerPool
+        .executeQueryStatement("show timeseries " + path);
+    schemaIter = schemaDataSet.iterator();
+
+    List<Future> futureList = new ArrayList<>();
+    int count = 0;
+    while (schemaIter.next()) {
+      count ++;
+      Path currentPath = new Path(schemaIter.getString("timeseries"));
+      Future future = executorService.submit(new LoadThread(count, currentPath, TSDataType.valueOf(schemaIter.getString("dataType"))));
+      futureList.add(future);
+    }
+    readerPool.closeResultSet(schemaDataSet);
+
+    for (Future future: futureList) {
+      future.get();
+    }
+    executorService.shutdown();
+
+    readerPool.close();
+    readerPool.close();
+  }
+
+
+  static class LoadThread implements Callable<Void> {

Review comment:
       Same as before.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org