-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pipe: export tsfile sink #14111
base: dev/1.3
Are you sure you want to change the base?
Pipe: export tsfile sink #14111
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do nothing is better. |
||
} | ||
|
||
@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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Different regions, the same name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 客户目录检查下载文件的时候,会不会往子目录去检测?需要确认 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that sourceTsFile.getName() returns the name of pipe-pinned tsfiles, which include region id. |
||
|
||
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: {}", | ||
sourceTsFile.getAbsolutePath(), | ||
targetPath.getAbsolutePath(), | ||
e); | ||
} finally { | ||
event.decreaseReferenceCount(ExportTsFileConnector.class.getName(), false); | ||
} | ||
} | ||
|
||
@Override | ||
public void transfer(Event event) throws Exception { | ||
// Do nothing for generic events | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
// Do nothing | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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.commons.pipe.agent.plugin.builtin.connector.export; | ||
|
||
import org.apache.iotdb.commons.pipe.agent.plugin.builtin.connector.PlaceholderConnector; | ||
|
||
/** | ||
* This class is a placeholder and should not be initialized. It represents the Export TsFile | ||
* connector. There is a real implementation in the server module but cannot be imported here. The | ||
* pipe agent in the server module will replace this class with the real implementation when | ||
* initializing the Export TsFile connector. | ||
*/ | ||
public class ExportTsFileConnector extends PlaceholderConnector {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.