pratyakshsharma commented on a change in pull request #4645:
URL: https://github.com/apache/hudi/pull/4645#discussion_r810615551
##########
File path:
hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/HoodieMultiTableDeltaStreamer.java
##########
@@ -370,50 +441,124 @@ public static void main(String[] args) throws
IOException {
private static String resetTarget(Config configuration, String database,
String tableName) {
String basePathPrefix = configuration.basePathPrefix;
basePathPrefix = basePathPrefix.charAt(basePathPrefix.length() - 1) == '/'
? basePathPrefix.substring(0, basePathPrefix.length() - 1) : basePathPrefix;
- String targetBasePath = basePathPrefix + Constants.FILE_DELIMITER +
database + Constants.FILE_DELIMITER + tableName;
- configuration.targetTableName = database + Constants.DELIMITER + tableName;
+ String targetBasePath = basePathPrefix + Constants.PATH_SEPARATOR +
database + Constants.PATH_SEPARATOR + tableName;
+ configuration.targetTableName = database + Constants.PATH_CUR_DIR +
tableName;
return targetBasePath;
}
/**
* Creates actual HoodieDeltaStreamer objects for every table/topic and does
incremental sync.
*/
public void sync() {
+ List<HoodieDeltaStreamer> hdsObjectList = new ArrayList<>();
+
+ // The sync function is not executed when multiple sources update the same
target.
for (TableExecutionContext context : tableExecutionContexts) {
try {
- new HoodieDeltaStreamer(context.getConfig(), jssc,
Option.ofNullable(context.getProperties())).sync();
+ HoodieDeltaStreamer hds = new HoodieDeltaStreamer(context.getConfig(),
jssc, Option.ofNullable(context.getProperties()));
+
+ // Add object of HoodieDeltaStreamer temporarily to hdsObjectList when
multiple sources update the same target.
+ if
(!StringUtils.isNullOrEmpty(context.getProperties().getProperty(Constants.SOURCES_TO_BE_BOUND)))
{
+ hdsObjectList.add(hds);
+ continue;
+ }
+
+ hds.sync();
successTables.add(Helpers.getTableWithDatabase(context));
} catch (Exception e) {
- logger.error("error while running MultiTableDeltaStreamer for table: "
+ context.getTableName(), e);
+ logger.error("Error while running MultiTableDeltaStreamer for table: "
+ context.getTableName(), e);
failedTables.add(Helpers.getTableWithDatabase(context));
}
}
- logger.info("Ingestion was successful for topics: " + successTables);
- if (!failedTables.isEmpty()) {
- logger.info("Ingestion failed for topics: " + failedTables);
+ // If hdsObjectList is empty, it indicates that all source sync operations
have been completed. In this case, directly return.
+ if (hdsObjectList.isEmpty()) {
+ logger.info("Ingestion was successful for topics: " + successTables);
+ if (!failedTables.isEmpty()) {
+ logger.info("Ingestion failed for topics: " + failedTables);
+ }
+ return;
}
+
+ // The sync function is executing here when multiple sources update the
same target.
+ boolean isContinuousMode = hdsObjectList.get(0).cfg.continuousMode;
+ do {
+ // Executing sync function by traversing hdsObjectList when multiple
sources update the same target.
+ for (int i = 0; i < hdsObjectList.size(); i++) {
+ // Threads cannot be started when multiple sources update the same
target.
+ if (isContinuousMode) {
+ hdsObjectList.get(i).cfg.continuousMode = false;
+ }
+
+ try {
+ hdsObjectList.get(i).sync();
+
successTables.add(Helpers.getTableWithDatabase(tableExecutionContexts.get(i)));
+ } catch (Exception e) {
+ logger.error("Error while running MultiTableDeltaStreamer for table:
"
+ + tableExecutionContexts.get(i).getTableName(), e);
+
failedTables.add(Helpers.getTableWithDatabase(tableExecutionContexts.get(i)));
+ break;
+ }
+ }
+
+ logger.info("Ingestion was successful for topics: " + successTables);
+ if (!failedTables.isEmpty()) {
+ logger.info("Ingestion failed for topics: " + failedTables);
+ break;
+ }
+ successTables.clear();
+ } while (isContinuousMode);
Review comment:
from what I understand, you want to do the ingestion for tables which
are bound to multiple source tables here. I guess that can be done using a
simple for loop. That will make it more simple and eliminate the need to
`isContinuousMode` variable.
Since MultiTableDeltaStreamer does serial execution, we can simply set the
continuousMode as false for every table. LMK what you think.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]