loukey-lj commented on a change in pull request #2434: URL: https://github.com/apache/hudi/pull/2434#discussion_r559543409
########## File path: hudi-flink/src/main/java/org/apache/hudi/operator/InstantGenerateOperator.java ########## @@ -102,65 +109,79 @@ public void open() throws Exception { // Hadoop FileSystem fs = FSUtils.getFs(cfg.targetBasePath, serializableHadoopConf.get()); - TaskContextSupplier taskContextSupplier = new FlinkTaskContextSupplier(null); + if (isMain) { + TaskContextSupplier taskContextSupplier = new FlinkTaskContextSupplier(runtimeContext); - // writeClient - writeClient = new HoodieFlinkWriteClient(new HoodieFlinkEngineContext(taskContextSupplier), StreamerUtil.getHoodieClientConfig(cfg), true); + // writeClient + writeClient = new HoodieFlinkWriteClient(new HoodieFlinkEngineContext(taskContextSupplier), StreamerUtil.getHoodieClientConfig(cfg), true); - // init table, create it if not exists. - initTable(); + // init table, create it if not exists. + initTable(); + + // create instant marker directory + createInstantMarkerDir(); + } } @Override public void prepareSnapshotPreBarrier(long checkpointId) throws Exception { super.prepareSnapshotPreBarrier(checkpointId); - // check whether the last instant is completed, if not, wait 10s and then throws an exception - if (!StringUtils.isNullOrEmpty(latestInstant)) { - doCheck(); - // last instant completed, set it empty - latestInstant = ""; - } + String instantMarkerFileName = String.format("%d%s%d%s%d", indexOfThisSubtask, DELIMITER, checkpointId, DELIMITER, recordCounter.get()); + Path path = new Path(new Path(HoodieTableMetaClient.AUXILIARYFOLDER_NAME, INSTANT_MARKER_FOLDER_NAME), instantMarkerFileName); + // mk generate file by each subtask Review comment: done ########## File path: hudi-flink/src/main/java/org/apache/hudi/operator/InstantGenerateOperator.java ########## @@ -222,4 +243,60 @@ public void close() throws Exception { fs.close(); } } + + private boolean checkReceivedData(long checkpointId) throws InterruptedException, IOException { + int numberOfParallelSubtasks = runtimeContext.getNumberOfParallelSubtasks(); + FileStatus[] fileStatuses; + Path instantMarkerPath = new Path(HoodieTableMetaClient.AUXILIARYFOLDER_NAME, INSTANT_MARKER_FOLDER_NAME); + int tryTimes = 1; + // waiting all subtask create marker file ready + while (true) { + Thread.sleep(500L); + fileStatuses = fs.listStatus(instantMarkerPath, new PathFilter() { + @Override + public boolean accept(Path pathname) { + return pathname.getName().contains(String.format("%s%d%s", DELIMITER, checkpointId, DELIMITER)); + } + }); + + // is ready + if (fileStatuses != null && fileStatuses.length == numberOfParallelSubtasks) { + break; + } + + if (tryTimes >= 5) { + LOG.warn("waiting generate file, checkpointId [{}]", checkpointId); Review comment: done ########## File path: hudi-flink/src/main/java/org/apache/hudi/operator/InstantGenerateOperator.java ########## @@ -102,65 +109,79 @@ public void open() throws Exception { // Hadoop FileSystem fs = FSUtils.getFs(cfg.targetBasePath, serializableHadoopConf.get()); - TaskContextSupplier taskContextSupplier = new FlinkTaskContextSupplier(null); + if (isMain) { + TaskContextSupplier taskContextSupplier = new FlinkTaskContextSupplier(runtimeContext); - // writeClient - writeClient = new HoodieFlinkWriteClient(new HoodieFlinkEngineContext(taskContextSupplier), StreamerUtil.getHoodieClientConfig(cfg), true); + // writeClient + writeClient = new HoodieFlinkWriteClient(new HoodieFlinkEngineContext(taskContextSupplier), StreamerUtil.getHoodieClientConfig(cfg), true); - // init table, create it if not exists. - initTable(); + // init table, create it if not exists. + initTable(); + + // create instant marker directory + createInstantMarkerDir(); + } } @Override public void prepareSnapshotPreBarrier(long checkpointId) throws Exception { super.prepareSnapshotPreBarrier(checkpointId); - // check whether the last instant is completed, if not, wait 10s and then throws an exception - if (!StringUtils.isNullOrEmpty(latestInstant)) { - doCheck(); - // last instant completed, set it empty - latestInstant = ""; - } + String instantMarkerFileName = String.format("%d%s%d%s%d", indexOfThisSubtask, DELIMITER, checkpointId, DELIMITER, recordCounter.get()); + Path path = new Path(new Path(HoodieTableMetaClient.AUXILIARYFOLDER_NAME, INSTANT_MARKER_FOLDER_NAME), instantMarkerFileName); + // mk generate file by each subtask + fs.create(path, true); + LOG.info("Subtask [{}] at checkpoint [{}] created generate file [{}]", indexOfThisSubtask, checkpointId, instantMarkerFileName); Review comment: done ########## File path: hudi-flink/src/main/java/org/apache/hudi/operator/InstantGenerateOperator.java ########## @@ -102,65 +109,79 @@ public void open() throws Exception { // Hadoop FileSystem fs = FSUtils.getFs(cfg.targetBasePath, serializableHadoopConf.get()); - TaskContextSupplier taskContextSupplier = new FlinkTaskContextSupplier(null); + if (isMain) { + TaskContextSupplier taskContextSupplier = new FlinkTaskContextSupplier(runtimeContext); - // writeClient - writeClient = new HoodieFlinkWriteClient(new HoodieFlinkEngineContext(taskContextSupplier), StreamerUtil.getHoodieClientConfig(cfg), true); + // writeClient + writeClient = new HoodieFlinkWriteClient(new HoodieFlinkEngineContext(taskContextSupplier), StreamerUtil.getHoodieClientConfig(cfg), true); - // init table, create it if not exists. - initTable(); + // init table, create it if not exists. + initTable(); + + // create instant marker directory + createInstantMarkerDir(); + } } @Override public void prepareSnapshotPreBarrier(long checkpointId) throws Exception { super.prepareSnapshotPreBarrier(checkpointId); - // check whether the last instant is completed, if not, wait 10s and then throws an exception - if (!StringUtils.isNullOrEmpty(latestInstant)) { - doCheck(); - // last instant completed, set it empty - latestInstant = ""; - } + String instantMarkerFileName = String.format("%d%s%d%s%d", indexOfThisSubtask, DELIMITER, checkpointId, DELIMITER, recordCounter.get()); + Path path = new Path(new Path(HoodieTableMetaClient.AUXILIARYFOLDER_NAME, INSTANT_MARKER_FOLDER_NAME), instantMarkerFileName); + // mk generate file by each subtask + fs.create(path, true); + LOG.info("Subtask [{}] at checkpoint [{}] created generate file [{}]", indexOfThisSubtask, checkpointId, instantMarkerFileName); + if (isMain) { + boolean receivedDataInCurrentCP = checkReceivedData(checkpointId); + // check whether the last instant is completed, if not, wait 10s and then throws an exception + if (!StringUtils.isNullOrEmpty(latestInstant)) { + doCheck(); + // last instant completed, set it empty + latestInstant = ""; + } - // no data no new instant - if (!bufferedRecords.isEmpty()) { - latestInstant = startNewInstant(checkpointId); + // no data no new instant Review comment: done ---------------------------------------------------------------- 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: us...@infra.apache.org