You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "2b3c511 (via GitHub)" <gi...@apache.org> on 2025/02/11 04:25:38 UTC

[PR] Replace ExportTsFile By SubscriptionTsFile [iotdb]

2b3c511 opened a new pull request, #14812:
URL: https://github.com/apache/iotdb/pull/14812

   Implementation of Replacing Export_tsfile Tool with Subscript_tsfile


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] Replace ExportTsFile By SubscriptionTsFile [iotdb]

Posted by "luoluoyuyu (via GitHub)" <gi...@apache.org>.
luoluoyuyu commented on code in PR #14812:
URL: https://github.com/apache/iotdb/pull/14812#discussion_r1958963525


##########
iotdb-client/cli/src/main/java/org/apache/iotdb/tool/tsfile/subscription/SubscriptionTableTsFile.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.tool.tsfile.subscription;
+
+import org.apache.iotdb.commons.utils.FileUtils;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.subscription.config.TopicConstant;
+import org.apache.iotdb.session.subscription.consumer.ISubscriptionTablePullConsumer;
+import org.apache.iotdb.session.subscription.consumer.table.SubscriptionTablePullConsumer;
+import org.apache.iotdb.session.subscription.consumer.table.SubscriptionTablePullConsumerBuilder;
+import org.apache.iotdb.session.subscription.model.Topic;
+import org.apache.iotdb.session.subscription.payload.SubscriptionMessage;
+import org.apache.iotdb.session.subscription.payload.SubscriptionTsFileHandler;
+import org.apache.iotdb.tool.common.Constants;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+
+import static java.lang.System.out;
+
+public class SubscriptionTableTsFile extends AbstractSubscriptionTsFile {
+
+  @Override
+  public void createTopics(String topicName)
+      throws IoTDBConnectionException, StatementExecutionException {
+    Properties properties = new Properties();
+    properties.put(TopicConstant.MODE_KEY, Constants.MODE);
+    properties.put(TopicConstant.FORMAT_KEY, Constants.HANDLER);
+    properties.put(TopicConstant.STRICT_KEY, Constants.STRICT);
+    properties.put(TopicConstant.LOOSE_RANGE_KEY, Constants.LOOSE_RANGE);
+    if (StringUtils.isNotBlank(commonParam.getStartTime()))
+      properties.put(TopicConstant.START_TIME_KEY, commonParam.getStartTime());
+    if (StringUtils.isNotBlank(commonParam.getEndTime()))
+      properties.put(TopicConstant.END_TIME_KEY, commonParam.getEndTime());
+    if (StringUtils.isNotBlank(commonParam.getDatabase())
+        || StringUtils.isNotBlank(commonParam.getTable())) {
+      properties.put(TopicConstant.DATABASE_KEY, commonParam.getDatabase());
+      properties.put(TopicConstant.TABLE_KEY, commonParam.getTable());
+    }
+    commonParam.getTableSubs().createTopic(topicName, properties);
+  }
+
+  @Override
+  public void doClean() throws Exception {
+    for (int i = commonParam.getStartIndex(); i < commonParam.getConsumerCount(); i++) {
+      SubscriptionTablePullConsumer consumer =
+          (SubscriptionTablePullConsumer) commonParam.getPullTableConsumers().get(i);
+      String path =
+          commonParam.getTargetDir()
+              + File.separator
+              + consumer.getConsumerGroupId()
+              + File.separator
+              + consumer.getConsumerId();
+      File file = new File(path);
+      if (file.exists()) {
+        FileUtils.deleteFileOrDirectory(file);
+      }
+    }
+    for (Topic topic : CommonParam.getTableSubs().getTopics()) {
+      commonParam.getTableSubs().dropTopicIfExists(topic.getTopicName());
+    }
+    commonParam.getTableSubs().getSubscriptions().forEach(out::println);
+    commonParam.getTableSubs().getTopics().forEach(out::println);
+    commonParam.getTableSubs().close();
+  }
+
+  @Override
+  public void createConsumers(String groupId) {
+    commonParam.setPullTableConsumers(new ArrayList<>(CommonParam.getConsumerCount()));
+    for (int i = commonParam.getStartIndex(); i < commonParam.getConsumerCount(); i++) {
+      commonParam
+          .getPullTableConsumers()
+          .add(
+              new SubscriptionTablePullConsumerBuilder()
+                  .host(commonParam.getSrcHost())
+                  .port(commonParam.getSrcPort())
+                  .consumerId(Constants.CONSUMER_NAME_PREFIX + i)
+                  .consumerGroupId(groupId)
+                  .autoCommit(Constants.AUTO_COMMIT)
+                  .autoCommitIntervalMs(Constants.AUTO_COMMIT_INTERVAL)
+                  .fileSaveDir(commonParam.getTargetDir())
+                  .buildTablePullConsumer());
+    }
+    for (ISubscriptionTablePullConsumer consumer : commonParam.getPullTableConsumers()) {
+      consumer.open();
+    }

Review Comment:
   I think there are some details that need to be dealt with here, such as whether the failure of a consumer.open will affect all consumers executing open, or the operation of the entire program.



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] Replace ExportTsFile By SubscriptionTsFile [iotdb]

Posted by "CritasWang (via GitHub)" <gi...@apache.org>.
CritasWang merged PR #14812:
URL: https://github.com/apache/iotdb/pull/14812


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] Replace ExportTsFile By SubscriptionTsFile [iotdb]

Posted by "CritasWang (via GitHub)" <gi...@apache.org>.
CritasWang commented on code in PR #14812:
URL: https://github.com/apache/iotdb/pull/14812#discussion_r1950215499


##########
integration-test/src/test/java/org/apache/iotdb/tools/it/ExportTsFileTestIT.java:
##########
@@ -102,7 +100,7 @@ protected void testOnWindows() throws IOException {
 
     prepareData();
 
-    final String[] output1 = {"Export completely!"};
+    final String[] output1 = {"Subscription TsFile Count:1"};

Review Comment:
   Export



##########
integration-test/src/test/java/org/apache/iotdb/tools/it/ExportTsFileTestIT.java:
##########
@@ -76,7 +76,7 @@ public void test() throws IOException {
 
   @Override
   protected void testOnWindows() throws IOException {
-    final String[] output = {"!!!Warning:Tablet is empty,no data can be exported."};
+    final String[] output = {"Subscription TsFile Count:0"};

Review Comment:
   Export



##########
integration-test/src/test/java/org/apache/iotdb/tools/it/ExportTsFileTestIT.java:
##########
@@ -129,7 +125,7 @@ protected void testOnWindows() throws IOException {
 
   @Override
   protected void testOnUnix() throws IOException {
-    final String[] output = {"!!!Warning:Tablet is empty,no data can be exported."};
+    final String[] output = {"Subscription TsFile Count:0"};

Review Comment:
   Export



##########
iotdb-client/cli/src/main/java/org/apache/iotdb/tool/common/Constants.java:
##########
@@ -253,6 +259,23 @@ public class Constants {
         "yyyy.MM.dd'T'HH:mm:ss"
       };
 
+  public static final String SUBSCRIPTION_CLI_PREFIX = "Subscription TsFile";

Review Comment:
   Export



##########
integration-test/src/test/java/org/apache/iotdb/tools/it/ExportTsFileTestIT.java:
##########
@@ -143,16 +139,14 @@ protected void testOnUnix() throws IOException {
             "root",
             "-pw",
             "root",
-            "-t",
-            "target",
-            "-q",
-            "select * from root.**");
+            "-path",
+            "root.**");
     builder.environment().put("CLASSPATH", libPath);
     testOutput(builder, output, 0);
 
     prepareData();
 
-    final String[] output1 = {"Export completely!"};
+    final String[] output1 = {"Subscription TsFile Count:1"};

Review Comment:
   Export



##########
iotdb-client/cli/src/main/java/org/apache/iotdb/tool/common/Constants.java:
##########
@@ -177,6 +178,8 @@ public class Constants {
   public static final String TARGET_DIR_NAME = "target";
   public static final String TARGET_DIR_ARGS_NAME = "target_directory";
   public static final String TARGET_DIR_DESC = "Target file directory (required)";
+  public static final String TARGET_DIR_SUBSCRIPTION_DESC =
+      "Target file directory.default ./target/out/ (optional)";

Review Comment:
   Target file directory.default ./target/ (optional)



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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