[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r655334095 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java ## @@ -506,6 +509,8 @@ public void refreshTimeline() throws IOException { return Pair.of(scheduledCompactionInstant, writeStatusRDD); } + + Review comment: removed -- 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
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r655498636 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -297,7 +295,37 @@ public String getTopicName() { return topicName; } - public HashMap getKafkaParams() { + public Map getKafkaParams() { +return kafkaParams; + } + + private static Map excludeHoodieConfigs(TypedProperties props) { +Map kafkaParams = new HashMap<>(); +props.keySet().stream().filter(prop -> { + // In order to prevent printing unnecessary warn logs, here filter out the hoodie + // configuration items before passing to kafkaParams + return !prop.toString().startsWith("hoodie."); +}).forEach(prop -> { + kafkaParams.put(prop.toString(), props.get(prop.toString())); +}); return kafkaParams; } + + /** + * Commit offsets to Kafka only after hoodie commit is successful. + * @param checkpointStr checkpoint string containing offsets. + * @param props properties for Kafka consumer. + */ + public static void commitOffsetToKafka(String checkpointStr, TypedProperties props) { +DataSourceUtils.checkRequiredProperties(props, Collections.singletonList(ConsumerConfig.GROUP_ID_CONFIG)); +Map offsetMap = KafkaOffsetGen.CheckpointUtils.strToOffsets(checkpointStr); +Map kafkaParams = KafkaOffsetGen.excludeHoodieConfigs(props); +Map offsetAndMetadataMap = new HashMap<>(offsetMap.size()); +try (KafkaConsumer consumer = new KafkaConsumer(kafkaParams)) { + offsetMap.forEach((topicPartition, offset) -> offsetAndMetadataMap.put(topicPartition, new OffsetAndMetadata(offset))); + consumer.commitSync(offsetAndMetadataMap); +} catch (CommitFailedException | TimeoutException e) { + LOG.warn("Committing offsets to Kafka failed, this does not impact processing of records", e); Review comment: committing offset to Kafka is optional for the user, failure of single commit should not fail the complete job, hence logged this exception. -- 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
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r655512304 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -297,7 +295,37 @@ public String getTopicName() { return topicName; } - public HashMap getKafkaParams() { + public Map getKafkaParams() { +return kafkaParams; + } + + private static Map excludeHoodieConfigs(TypedProperties props) { Review comment: Are you proposing to create `KafkaOffsetGen` object in `DeltaSync` as well to call `commitOffsetToKafka` method ? I wanted to avoid doing it as we are already doing so in respective Source classes. Also, I saw `excludeHoodieConfigs ` as helper method, hence created static -- 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
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r655525696 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java ## @@ -473,7 +474,9 @@ public void refreshTimeline() throws IOException { boolean success = writeClient.commit(instantTime, writeStatusRDD, Option.of(checkpointCommitMetadata)); if (success) { LOG.info("Commit " + instantTime + " successful!"); - +if (this.props.getBoolean(KafkaOffsetGen.Config.ENABLE_KAFKA_COMMIT_OFFSET,KafkaOffsetGen.Config.DEFAULT_ENABLE_KAFKA_COMMIT_OFFSET)) { 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
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r655526318 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -157,29 +161,23 @@ public static long totalNewMessages(OffsetRange[] ranges) { private static final String KAFKA_TOPIC_NAME = "hoodie.deltastreamer.source.kafka.topic"; private static final String MAX_EVENTS_FROM_KAFKA_SOURCE_PROP = "hoodie.deltastreamer.kafka.source.maxEvents"; +public static final String ENABLE_KAFKA_COMMIT_OFFSET = "hoodie.deltastreamer.source.enable.kafka.commit.offset"; Review comment: make sense, updated code, did not rename `hoodie.deltastreamer.kafka.source.maxEvents` in this PR, will discuss more on compatibility ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -157,29 +161,23 @@ public static long totalNewMessages(OffsetRange[] ranges) { private static final String KAFKA_TOPIC_NAME = "hoodie.deltastreamer.source.kafka.topic"; private static final String MAX_EVENTS_FROM_KAFKA_SOURCE_PROP = "hoodie.deltastreamer.kafka.source.maxEvents"; +public static final String ENABLE_KAFKA_COMMIT_OFFSET = "hoodie.deltastreamer.source.enable.kafka.commit.offset"; // "auto.offset.reset" is kafka native config param. Do not change the config param name. public static final String KAFKA_AUTO_OFFSET_RESET = "auto.offset.reset"; private static final KafkaResetOffsetStrategies DEFAULT_KAFKA_AUTO_OFFSET_RESET = KafkaResetOffsetStrategies.LATEST; public static final long DEFAULT_MAX_EVENTS_FROM_KAFKA_SOURCE = 500; public static long maxEventsFromKafkaSource = DEFAULT_MAX_EVENTS_FROM_KAFKA_SOURCE; +public static final Boolean DEFAULT_ENABLE_KAFKA_COMMIT_OFFSET = false; } - private final HashMap kafkaParams; + private final Map kafkaParams; private final TypedProperties props; protected final String topicName; private KafkaResetOffsetStrategies autoResetValue; public KafkaOffsetGen(TypedProperties props) { this.props = props; - -kafkaParams = new HashMap<>(); -props.keySet().stream().filter(prop -> { - // In order to prevent printing unnecessary warn logs, here filter out the hoodie - // configuration items before passing to kafkaParams - return !prop.toString().startsWith("hoodie."); -}).forEach(prop -> { - kafkaParams.put(prop.toString(), props.get(prop.toString())); -}); +kafkaParams = KafkaOffsetGen.excludeHoodieConfigs(props); 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
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r655526600 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java ## @@ -473,7 +474,9 @@ public void refreshTimeline() throws IOException { boolean success = writeClient.commit(instantTime, writeStatusRDD, Option.of(checkpointCommitMetadata)); if (success) { LOG.info("Commit " + instantTime + " successful!"); - +if (this.props.getBoolean(KafkaOffsetGen.Config.ENABLE_KAFKA_COMMIT_OFFSET,KafkaOffsetGen.Config.DEFAULT_ENABLE_KAFKA_COMMIT_OFFSET)) { + KafkaOffsetGen.commitOffsetToKafka(checkpointStr, this.props); 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
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r655334095 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java ## @@ -506,6 +509,8 @@ public void refreshTimeline() throws IOException { return Pair.of(scheduledCompactionInstant, writeStatusRDD); } + + Review comment: removed ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -297,7 +295,37 @@ public String getTopicName() { return topicName; } - public HashMap getKafkaParams() { + public Map getKafkaParams() { +return kafkaParams; + } + + private static Map excludeHoodieConfigs(TypedProperties props) { +Map kafkaParams = new HashMap<>(); +props.keySet().stream().filter(prop -> { + // In order to prevent printing unnecessary warn logs, here filter out the hoodie + // configuration items before passing to kafkaParams + return !prop.toString().startsWith("hoodie."); +}).forEach(prop -> { + kafkaParams.put(prop.toString(), props.get(prop.toString())); +}); return kafkaParams; } + + /** + * Commit offsets to Kafka only after hoodie commit is successful. + * @param checkpointStr checkpoint string containing offsets. + * @param props properties for Kafka consumer. + */ + public static void commitOffsetToKafka(String checkpointStr, TypedProperties props) { +DataSourceUtils.checkRequiredProperties(props, Collections.singletonList(ConsumerConfig.GROUP_ID_CONFIG)); +Map offsetMap = KafkaOffsetGen.CheckpointUtils.strToOffsets(checkpointStr); +Map kafkaParams = KafkaOffsetGen.excludeHoodieConfigs(props); +Map offsetAndMetadataMap = new HashMap<>(offsetMap.size()); +try (KafkaConsumer consumer = new KafkaConsumer(kafkaParams)) { + offsetMap.forEach((topicPartition, offset) -> offsetAndMetadataMap.put(topicPartition, new OffsetAndMetadata(offset))); + consumer.commitSync(offsetAndMetadataMap); +} catch (CommitFailedException | TimeoutException e) { + LOG.warn("Committing offsets to Kafka failed, this does not impact processing of records", e); Review comment: committing offset to Kafka is optional for the user, failure of single commit should not fail the complete job, hence logged this exception. ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -297,7 +295,37 @@ public String getTopicName() { return topicName; } - public HashMap getKafkaParams() { + public Map getKafkaParams() { +return kafkaParams; + } + + private static Map excludeHoodieConfigs(TypedProperties props) { Review comment: Are you proposing to create `KafkaOffsetGen` object in `DeltaSync` as well to call `commitOffsetToKafka` method ? I wanted to avoid doing it as we are already doing so in respective Source classes. Also, I saw `excludeHoodieConfigs ` as helper method, hence created static ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java ## @@ -473,7 +474,9 @@ public void refreshTimeline() throws IOException { boolean success = writeClient.commit(instantTime, writeStatusRDD, Option.of(checkpointCommitMetadata)); if (success) { LOG.info("Commit " + instantTime + " successful!"); - +if (this.props.getBoolean(KafkaOffsetGen.Config.ENABLE_KAFKA_COMMIT_OFFSET,KafkaOffsetGen.Config.DEFAULT_ENABLE_KAFKA_COMMIT_OFFSET)) { Review comment: done ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -157,29 +161,23 @@ public static long totalNewMessages(OffsetRange[] ranges) { private static final String KAFKA_TOPIC_NAME = "hoodie.deltastreamer.source.kafka.topic"; private static final String MAX_EVENTS_FROM_KAFKA_SOURCE_PROP = "hoodie.deltastreamer.kafka.source.maxEvents"; +public static final String ENABLE_KAFKA_COMMIT_OFFSET = "hoodie.deltastreamer.source.enable.kafka.commit.offset"; Review comment: make sense, updated code, did not rename `hoodie.deltastreamer.kafka.source.maxEvents` in this PR, will discuss more on compatibility ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -157,29 +161,23 @@ public static long totalNewMessages(OffsetRange[] ranges) { private static final String KAFKA_TOPIC_NAME = "hoodie.deltastreamer.source.kafka.topic"; private static final String MAX_EVENTS_FROM_KAFKA_SOURCE_PROP = "hoodie.deltastreamer.kafka.source.maxEvents"; +public static final String ENABLE_KAFKA_COMMIT_OFFSET = "hoodie.deltastreamer.source.enable.kafka.commit.offset"; // "auto.offset.reset" is kafka native config param. Do not change the conf
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r656757106 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -157,29 +161,23 @@ public static long totalNewMessages(OffsetRange[] ranges) { private static final String KAFKA_TOPIC_NAME = "hoodie.deltastreamer.source.kafka.topic"; private static final String MAX_EVENTS_FROM_KAFKA_SOURCE_PROP = "hoodie.deltastreamer.kafka.source.maxEvents"; +public static final String ENABLE_KAFKA_COMMIT_OFFSET = "hoodie.deltastreamer.source.kafka.enable.commit.offset"; Review comment: that is `auto.commit.offset` config of Kafka, this will be a custom optional config -- 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
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r656759751 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java ## @@ -473,7 +476,9 @@ public void refreshTimeline() throws IOException { boolean success = writeClient.commit(instantTime, writeStatusRDD, Option.of(checkpointCommitMetadata)); if (success) { LOG.info("Commit " + instantTime + " successful!"); - +if (this.props.getBoolean(ENABLE_KAFKA_COMMIT_OFFSET, DEFAULT_ENABLE_KAFKA_COMMIT_OFFSET)) { Review comment: Agree, @n3nash and me discussed on various approaches here https://issues.apache.org/jira/browse/HUDI-1910 and picked this one , hence did not add the config to DeltaSync. Should we implement callback approach instead ? -- 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
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r658703745 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -297,7 +295,37 @@ public String getTopicName() { return topicName; } - public HashMap getKafkaParams() { + public Map getKafkaParams() { +return kafkaParams; + } + + private static Map excludeHoodieConfigs(TypedProperties props) { Review comment: @leesf 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
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r658715036 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java ## @@ -473,7 +476,9 @@ public void refreshTimeline() throws IOException { boolean success = writeClient.commit(instantTime, writeStatusRDD, Option.of(checkpointCommitMetadata)); if (success) { LOG.info("Commit " + instantTime + " successful!"); - +if (this.props.getBoolean(ENABLE_KAFKA_COMMIT_OFFSET, DEFAULT_ENABLE_KAFKA_COMMIT_OFFSET)) { Review comment: @n3nash @vinothchandar added `onCommit` method to Source, let me know if this approach works -- 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
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r659271355 ## File path: hudi-examples/src/main/java/org/apache/hudi/examples/common/RandomJsonSource.java ## @@ -45,4 +45,8 @@ public RandomJsonSource(TypedProperties props, JavaSparkContext sparkContext, Sp return new InputBatch<>(Option.of(sparkContext.parallelize(inserts, 1)), commitTime); } + + @Override + public void onCommit(String lastCkptStr) { Review comment: Yes, I thought about it first but Source being an abstract class dropped that idea, should we add a new interface like `SourceCallback` which will contain this default method ? -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r659271949 ## File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/sources/helpers/KafkaOffsetGen.java ## @@ -297,7 +295,37 @@ public String getTopicName() { return topicName; } - public HashMap getKafkaParams() { + public Map getKafkaParams() { +return kafkaParams; + } + + private static Map excludeHoodieConfigs(TypedProperties props) { +Map kafkaParams = new HashMap<>(); +props.keySet().stream().filter(prop -> { + // In order to prevent printing unnecessary warn logs, here filter out the hoodie + // configuration items before passing to kafkaParams + return !prop.toString().startsWith("hoodie."); +}).forEach(prop -> { + kafkaParams.put(prop.toString(), props.get(prop.toString())); +}); return kafkaParams; } + + /** + * Commit offsets to Kafka only after hoodie commit is successful. + * @param checkpointStr checkpoint string containing offsets. + * @param props properties for Kafka consumer. + */ + public static void commitOffsetToKafka(String checkpointStr, TypedProperties props) { +DataSourceUtils.checkRequiredProperties(props, Collections.singletonList(ConsumerConfig.GROUP_ID_CONFIG)); +Map offsetMap = KafkaOffsetGen.CheckpointUtils.strToOffsets(checkpointStr); +Map kafkaParams = KafkaOffsetGen.excludeHoodieConfigs(props); +Map offsetAndMetadataMap = new HashMap<>(offsetMap.size()); +try (KafkaConsumer consumer = new KafkaConsumer(kafkaParams)) { + offsetMap.forEach((topicPartition, offset) -> offsetAndMetadataMap.put(topicPartition, new OffsetAndMetadata(offset))); + consumer.commitSync(offsetAndMetadataMap); +} catch (CommitFailedException | TimeoutException e) { + LOG.warn("Committing offsets to Kafka failed, this does not impact processing of records", e); Review comment: This change will not have any effect on job restarts. Hudi will not rely on the offsets committed to Kafka after restarts. This is similar to how Flink behaves which only commits offsets to Kafka (configurable) but relies on it's own checkpointing if the job restarts. -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [hudi] veenaypatil commented on a change in pull request #3092: [HUDI-1910] Commit Offset to Kafka after successful Hudi commit
veenaypatil commented on a change in pull request #3092: URL: https://github.com/apache/hudi/pull/3092#discussion_r659277370 ## File path: hudi-examples/src/main/java/org/apache/hudi/examples/common/RandomJsonSource.java ## @@ -45,4 +45,8 @@ public RandomJsonSource(TypedProperties props, JavaSparkContext sparkContext, Sp return new InputBatch<>(Option.of(sparkContext.parallelize(inserts, 1)), commitTime); } + + @Override + public void onCommit(String lastCkptStr) { Review comment: done, as discussed added `SourceCommitCallback` interface with default method. -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org