You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "DanielWang2035 (via GitHub)" <gi...@apache.org> on 2024/11/17 10:48:13 UTC

[PR] Pipe: export tsfile sink [iotdb]

DanielWang2035 opened a new pull request, #14111:
URL: https://github.com/apache/iotdb/pull/14111

   (no comment)


-- 
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] Pipe: export tsfile sink [iotdb]

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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/protocol/exportfile/ExportTsFileConnector.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.db.pipe.connector.protocol.exportfile;
+
+import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.PipeConnector;
+import org.apache.iotdb.pipe.api.customizer.configuration.PipeConnectorRuntimeConfiguration;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameterValidator;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameters;
+import org.apache.iotdb.pipe.api.event.Event;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TabletInsertionEvent;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.CONNECTOR_EXPORT_TSFILE_PATH_KEY;
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.SINK_EXPORT_TSFILE_PATH_KEY;
+
+public class ExportTsFileConnector implements PipeConnector {
+  private static final Logger LOGGER = LoggerFactory.getLogger(ExportTsFileConnector.class);
+
+  private File exportPath;
+
+  @Override
+  public void validate(PipeParameterValidator validator) throws Exception {
+    final PipeParameters parameters = validator.getParameters();
+    validator.validate(
+        args -> (boolean) args[0] || (boolean) args[1],
+        String.format(
+            "One of %s and %s must be specified",
+            CONNECTOR_EXPORT_TSFILE_PATH_KEY, SINK_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY));
+  }
+
+  @Override
+  public void customize(PipeParameters parameters, PipeConnectorRuntimeConfiguration configuration)
+      throws Exception {
+    if (parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(SINK_EXPORT_TSFILE_PATH_KEY));
+    } else if (parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(CONNECTOR_EXPORT_TSFILE_PATH_KEY));
+    } else {
+      // This should not happen
+      throw new PipeException("Export TsFile path not found in parameters");
+    }
+  }
+
+  @Override
+  public void handshake() throws Exception {
+    if (exportPath == null) {
+      throw new PipeException("Handshake should not take place before customize");
+    }
+
+    if (!exportPath.exists() && !exportPath.mkdirs()) {
+      throw new PipeException("Export TsFile path not exist and can't be created");
+    }
+
+    if (!exportPath.isDirectory()) {
+      throw new PipeException("Export TsFile path already exists and is not a directory");
+    }
+  }
+
+  @Override
+  public void heartbeat() throws Exception {
+    handshake();
+  }
+
+  @Override
+  public void transfer(TabletInsertionEvent tabletInsertionEvent) throws Exception {
+    LOGGER.warn(
+        "TabletInsertionEvent is not supported, will skip this event: {}", tabletInsertionEvent);
+  }
+
+  @Override
+  public void transfer(TsFileInsertionEvent tsFileInsertionEvent) throws Exception {
+    if (!(tsFileInsertionEvent instanceof PipeTsFileInsertionEvent)) {
+      LOGGER.warn(
+          "{} only supports PipeTsFileInsertionEvent", ExportTsFileConnector.class.getName());
+      return;
+    }
+
+    final PipeTsFileInsertionEvent event = (PipeTsFileInsertionEvent) tsFileInsertionEvent;
+    final File sourceTsFile = event.getTsFile();
+    final File targetPath = new File(exportPath, sourceTsFile.getName());

Review Comment:
   Different regions, the same name?



-- 
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] Pipe: export tsfile sink [iotdb]

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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/protocol/exportfile/ExportTsFileConnector.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.db.pipe.connector.protocol.exportfile;
+
+import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.PipeConnector;
+import org.apache.iotdb.pipe.api.customizer.configuration.PipeConnectorRuntimeConfiguration;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameterValidator;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameters;
+import org.apache.iotdb.pipe.api.event.Event;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TabletInsertionEvent;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.CONNECTOR_EXPORT_TSFILE_PATH_KEY;
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.SINK_EXPORT_TSFILE_PATH_KEY;
+
+public class ExportTsFileConnector implements PipeConnector {
+  private static final Logger LOGGER = LoggerFactory.getLogger(ExportTsFileConnector.class);
+
+  private File exportPath;
+
+  @Override
+  public void validate(PipeParameterValidator validator) throws Exception {
+    final PipeParameters parameters = validator.getParameters();
+    validator.validate(
+        args -> (boolean) args[0] || (boolean) args[1],
+        String.format(
+            "One of %s and %s must be specified",
+            CONNECTOR_EXPORT_TSFILE_PATH_KEY, SINK_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY));
+  }
+
+  @Override
+  public void customize(PipeParameters parameters, PipeConnectorRuntimeConfiguration configuration)
+      throws Exception {
+    if (parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(SINK_EXPORT_TSFILE_PATH_KEY));
+    } else if (parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(CONNECTOR_EXPORT_TSFILE_PATH_KEY));
+    } else {
+      // This should not happen
+      throw new PipeException("Export TsFile path not found in parameters");
+    }
+  }
+
+  @Override
+  public void handshake() throws Exception {
+    if (exportPath == null) {
+      throw new PipeException("Handshake should not take place before customize");
+    }
+
+    if (!exportPath.exists() && !exportPath.mkdirs()) {
+      throw new PipeException("Export TsFile path not exist and can't be created");
+    }
+
+    if (!exportPath.isDirectory()) {
+      throw new PipeException("Export TsFile path already exists and is not a directory");
+    }
+  }
+
+  @Override
+  public void heartbeat() throws Exception {
+    handshake();

Review Comment:
   do nothing is better.



-- 
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] Pipe: export tsfile sink [iotdb]

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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/protocol/exportfile/ExportTsFileConnector.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.db.pipe.connector.protocol.exportfile;
+
+import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.PipeConnector;
+import org.apache.iotdb.pipe.api.customizer.configuration.PipeConnectorRuntimeConfiguration;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameterValidator;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameters;
+import org.apache.iotdb.pipe.api.event.Event;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TabletInsertionEvent;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.CONNECTOR_EXPORT_TSFILE_PATH_KEY;
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.SINK_EXPORT_TSFILE_PATH_KEY;
+
+public class ExportTsFileConnector implements PipeConnector {
+  private static final Logger LOGGER = LoggerFactory.getLogger(ExportTsFileConnector.class);
+
+  private File exportPath;
+
+  @Override
+  public void validate(PipeParameterValidator validator) throws Exception {
+    final PipeParameters parameters = validator.getParameters();
+    validator.validate(
+        args -> (boolean) args[0] || (boolean) args[1],
+        String.format(
+            "One of %s and %s must be specified",
+            CONNECTOR_EXPORT_TSFILE_PATH_KEY, SINK_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY));
+  }
+
+  @Override
+  public void customize(PipeParameters parameters, PipeConnectorRuntimeConfiguration configuration)
+      throws Exception {
+    if (parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(SINK_EXPORT_TSFILE_PATH_KEY));
+    } else if (parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(CONNECTOR_EXPORT_TSFILE_PATH_KEY));
+    } else {
+      // This should not happen
+      throw new PipeException("Export TsFile path not found in parameters");
+    }
+  }
+
+  @Override
+  public void handshake() throws Exception {
+    if (exportPath == null) {
+      throw new PipeException("Handshake should not take place before customize");
+    }
+
+    if (!exportPath.exists() && !exportPath.mkdirs()) {
+      throw new PipeException("Export TsFile path not exist and can't be created");
+    }
+
+    if (!exportPath.isDirectory()) {
+      throw new PipeException("Export TsFile path already exists and is not a directory");
+    }
+  }
+
+  @Override
+  public void heartbeat() throws Exception {
+    handshake();
+  }
+
+  @Override
+  public void transfer(TabletInsertionEvent tabletInsertionEvent) throws Exception {
+    LOGGER.warn(
+        "TabletInsertionEvent is not supported, will skip this event: {}", tabletInsertionEvent);
+  }
+
+  @Override
+  public void transfer(TsFileInsertionEvent tsFileInsertionEvent) throws Exception {
+    if (!(tsFileInsertionEvent instanceof PipeTsFileInsertionEvent)) {
+      LOGGER.warn(
+          "{} only supports PipeTsFileInsertionEvent", ExportTsFileConnector.class.getName());
+      return;
+    }
+
+    final PipeTsFileInsertionEvent event = (PipeTsFileInsertionEvent) tsFileInsertionEvent;
+    final File sourceTsFile = event.getTsFile();
+    final File targetPath = new File(exportPath, sourceTsFile.getName());

Review Comment:
   客户目录检查下载文件的时候,会不会往子目录去检测?需要确认



-- 
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] Pipe: export tsfile sink [iotdb]

Posted by "CRZbulabula (via GitHub)" <gi...@apache.org>.
CRZbulabula closed pull request #14111: Pipe: export tsfile sink
URL: https://github.com/apache/iotdb/pull/14111


-- 
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] Pipe: export tsfile sink [iotdb]

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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/protocol/exportfile/ExportTsFileConnector.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.db.pipe.connector.protocol.exportfile;
+
+import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.PipeConnector;
+import org.apache.iotdb.pipe.api.customizer.configuration.PipeConnectorRuntimeConfiguration;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameterValidator;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameters;
+import org.apache.iotdb.pipe.api.event.Event;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TabletInsertionEvent;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.CONNECTOR_EXPORT_TSFILE_PATH_KEY;
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.SINK_EXPORT_TSFILE_PATH_KEY;
+
+public class ExportTsFileConnector implements PipeConnector {
+  private static final Logger LOGGER = LoggerFactory.getLogger(ExportTsFileConnector.class);
+
+  private File exportPath;
+
+  @Override
+  public void validate(PipeParameterValidator validator) throws Exception {
+    final PipeParameters parameters = validator.getParameters();
+    validator.validate(
+        args -> (boolean) args[0] || (boolean) args[1],
+        String.format(
+            "One of %s and %s must be specified",
+            CONNECTOR_EXPORT_TSFILE_PATH_KEY, SINK_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY));
+  }
+
+  @Override
+  public void customize(PipeParameters parameters, PipeConnectorRuntimeConfiguration configuration)
+      throws Exception {
+    if (parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(SINK_EXPORT_TSFILE_PATH_KEY));
+    } else if (parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(CONNECTOR_EXPORT_TSFILE_PATH_KEY));
+    } else {
+      // This should not happen
+      throw new PipeException("Export TsFile path not found in parameters");
+    }
+  }
+
+  @Override
+  public void handshake() throws Exception {
+    if (exportPath == null) {
+      throw new PipeException("Handshake should not take place before customize");
+    }
+
+    if (!exportPath.exists() && !exportPath.mkdirs()) {
+      throw new PipeException("Export TsFile path not exist and can't be created");
+    }
+
+    if (!exportPath.isDirectory()) {
+      throw new PipeException("Export TsFile path already exists and is not a directory");
+    }
+  }
+
+  @Override
+  public void heartbeat() throws Exception {
+    handshake();
+  }
+
+  @Override
+  public void transfer(TabletInsertionEvent tabletInsertionEvent) throws Exception {
+    LOGGER.warn(
+        "TabletInsertionEvent is not supported, will skip this event: {}", tabletInsertionEvent);
+  }
+
+  @Override
+  public void transfer(TsFileInsertionEvent tsFileInsertionEvent) throws Exception {
+    if (!(tsFileInsertionEvent instanceof PipeTsFileInsertionEvent)) {
+      LOGGER.warn(
+          "{} only supports PipeTsFileInsertionEvent", ExportTsFileConnector.class.getName());
+      return;
+    }
+
+    final PipeTsFileInsertionEvent event = (PipeTsFileInsertionEvent) tsFileInsertionEvent;
+    final File sourceTsFile = event.getTsFile();
+    final File targetPath = new File(exportPath, sourceTsFile.getName());
+
+    if (!event.increaseReferenceCount(ExportTsFileConnector.class.getName())) {
+      return;
+    }
+    try {
+      Files.copy(sourceTsFile.toPath(), targetPath.toPath());
+    } catch (final IOException e) {
+      LOGGER.warn(
+          "File renaming failed when exporting tsfile. Origin: {}, Target: {}",

Review Comment:
   renaming?



-- 
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] Pipe: export tsfile sink [iotdb]

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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/protocol/exportfile/ExportTsFileConnector.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.db.pipe.connector.protocol.exportfile;
+
+import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.PipeConnector;
+import org.apache.iotdb.pipe.api.customizer.configuration.PipeConnectorRuntimeConfiguration;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameterValidator;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameters;
+import org.apache.iotdb.pipe.api.event.Event;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TabletInsertionEvent;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.CONNECTOR_EXPORT_TSFILE_PATH_KEY;
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.SINK_EXPORT_TSFILE_PATH_KEY;
+
+public class ExportTsFileConnector implements PipeConnector {
+  private static final Logger LOGGER = LoggerFactory.getLogger(ExportTsFileConnector.class);
+
+  private File exportPath;
+
+  @Override
+  public void validate(PipeParameterValidator validator) throws Exception {
+    final PipeParameters parameters = validator.getParameters();
+    validator.validate(
+        args -> (boolean) args[0] || (boolean) args[1],
+        String.format(
+            "One of %s and %s must be specified",
+            CONNECTOR_EXPORT_TSFILE_PATH_KEY, SINK_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY));
+  }
+
+  @Override
+  public void customize(PipeParameters parameters, PipeConnectorRuntimeConfiguration configuration)
+      throws Exception {
+    if (parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(SINK_EXPORT_TSFILE_PATH_KEY));
+    } else if (parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(CONNECTOR_EXPORT_TSFILE_PATH_KEY));
+    } else {
+      // This should not happen
+      throw new PipeException("Export TsFile path not found in parameters");
+    }
+  }
+
+  @Override
+  public void handshake() throws Exception {
+    if (exportPath == null) {
+      throw new PipeException("Handshake should not take place before customize");
+    }
+
+    if (!exportPath.exists() && !exportPath.mkdirs()) {
+      throw new PipeException("Export TsFile path not exist and can't be created");
+    }

Review Comment:
   ```suggestion
   		synchornized (ExportTsFileConnector.class) {
   	    if (!exportPath.exists() && !exportPath.mkdirs()) {
   	      throw new PipeException("Export TsFile path not exist and can't be created");
   	    }
   		}
   ```



-- 
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] Pipe: export tsfile sink [iotdb]

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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/protocol/exportfile/ExportTsFileConnector.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.db.pipe.connector.protocol.exportfile;
+
+import org.apache.iotdb.db.pipe.event.common.tsfile.PipeTsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.PipeConnector;
+import org.apache.iotdb.pipe.api.customizer.configuration.PipeConnectorRuntimeConfiguration;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameterValidator;
+import org.apache.iotdb.pipe.api.customizer.parameter.PipeParameters;
+import org.apache.iotdb.pipe.api.event.Event;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TabletInsertionEvent;
+import org.apache.iotdb.pipe.api.event.dml.insertion.TsFileInsertionEvent;
+import org.apache.iotdb.pipe.api.exception.PipeException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.CONNECTOR_EXPORT_TSFILE_PATH_KEY;
+import static org.apache.iotdb.commons.pipe.config.constant.PipeConnectorConstant.SINK_EXPORT_TSFILE_PATH_KEY;
+
+public class ExportTsFileConnector implements PipeConnector {
+  private static final Logger LOGGER = LoggerFactory.getLogger(ExportTsFileConnector.class);
+
+  private File exportPath;
+
+  @Override
+  public void validate(PipeParameterValidator validator) throws Exception {
+    final PipeParameters parameters = validator.getParameters();
+    validator.validate(
+        args -> (boolean) args[0] || (boolean) args[1],
+        String.format(
+            "One of %s and %s must be specified",
+            CONNECTOR_EXPORT_TSFILE_PATH_KEY, SINK_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY),
+        parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY));
+  }
+
+  @Override
+  public void customize(PipeParameters parameters, PipeConnectorRuntimeConfiguration configuration)
+      throws Exception {
+    if (parameters.hasAttribute(SINK_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(SINK_EXPORT_TSFILE_PATH_KEY));
+    } else if (parameters.hasAttribute(CONNECTOR_EXPORT_TSFILE_PATH_KEY)) {
+      exportPath = new File(parameters.getString(CONNECTOR_EXPORT_TSFILE_PATH_KEY));
+    } else {
+      // This should not happen
+      throw new PipeException("Export TsFile path not found in parameters");
+    }
+  }
+
+  @Override
+  public void handshake() throws Exception {
+    if (exportPath == null) {
+      throw new PipeException("Handshake should not take place before customize");
+    }
+
+    if (!exportPath.exists() && !exportPath.mkdirs()) {
+      throw new PipeException("Export TsFile path not exist and can't be created");
+    }
+
+    if (!exportPath.isDirectory()) {
+      throw new PipeException("Export TsFile path already exists and is not a directory");
+    }
+  }
+
+  @Override
+  public void heartbeat() throws Exception {
+    handshake();
+  }
+
+  @Override
+  public void transfer(TabletInsertionEvent tabletInsertionEvent) throws Exception {
+    LOGGER.warn(
+        "TabletInsertionEvent is not supported, will skip this event: {}", tabletInsertionEvent);
+  }
+
+  @Override
+  public void transfer(TsFileInsertionEvent tsFileInsertionEvent) throws Exception {
+    if (!(tsFileInsertionEvent instanceof PipeTsFileInsertionEvent)) {
+      LOGGER.warn(
+          "{} only supports PipeTsFileInsertionEvent", ExportTsFileConnector.class.getName());
+      return;
+    }
+
+    final PipeTsFileInsertionEvent event = (PipeTsFileInsertionEvent) tsFileInsertionEvent;
+    final File sourceTsFile = event.getTsFile();
+    final File targetPath = new File(exportPath, sourceTsFile.getName());

Review Comment:
   It seems that sourceTsFile.getName() returns the name of pipe-pinned tsfiles, which include region id.



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