You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2020/07/29 17:37:12 UTC

[GitHub] [hudi] Mathieu1124 opened a new pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Mathieu1124 opened a new pull request #1886:
URL: https://github.com/apache/hudi/pull/1886


   …llback
   
   ## *Tips*
   - *Thank you very much for contributing to Apache Hudi.*
   - *Please review https://hudi.apache.org/contributing.html before opening a pull request.*
   
   ## What is the purpose of the pull request
   
   *Introduce a kafka implementation of hoodie write commit callback*
   
   ## Brief change log
   
   *(for example:)*
     - *Modify AnnotationLocation checkstyle rule in checkstyle.xml*
   
   ## Verify this pull request
   
   *(Please pick either of the following options)*
   
   This pull request is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This pull request is already covered by existing tests, such as *(please describe tests)*.
   
   (or)
   
   This change added tests and can be verified as follows:
   
   *(example:)*
   
     - *Added integration tests for end-to-end.*
     - *Added HoodieClientWriteTest to verify the change.*
     - *Manually verified the change by running a job locally.*
   
   ## Committer checklist
   
    - [ ] Has a corresponding JIRA in PR title & commit
    
    - [ ] Commit message is descriptive of the change
    
    - [ ] CI is green
   
    - [ ] Necessary doc changes done or have another open PR
          
    - [ ] For large changes, please consider breaking it into sub-tasks under an umbrella JIRA.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 edited a comment on pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 edited a comment on pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#issuecomment-670294044


   @yanghua VC seems busy, do you have any other concern about this pr ?
   if it is ok,  can we merge this first, and file a new pr if VC  agree to move this to hudi-client in the future :)


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 commented on pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 commented on pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#issuecomment-670453889


   > 
   > 
   > > I was wondering can we move this implement to hudi-client module just like the way all the implementations of metrics does.
   > 
   > I think we can move this down the line. `hudi-client` or `hudi-spark` talking a direct dependency on kafka does not feel that clean to me. May be file a follow up JIRA?
   
   ok 


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] yanghua commented on a change in pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#discussion_r464145643



##########
File path: hudi-client/src/main/java/org/apache/hudi/callback/util/HoodieWriteCommitCallbackUtil.java
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.hudi.callback.util;
+
+import org.apache.hudi.exception.HoodieCommitCallbackException;
+
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.io.IOException;
+
+/**
+ * Util helps to prepare callback message.
+ */
+public class HoodieWriteCommitCallbackUtil {
+
+  /**
+   * Convert data to json string format.
+   *
+   * @param obj

Review comment:
       If you do not want to add the comments for `@param` and `@return`. Just remove them.

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/callback/kafka/HoodieWriteCommitKafkaCallback.java
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.hudi.utilities.callback.kafka;
+
+import org.apache.hudi.callback.HoodieWriteCommitCallback;
+import org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage;
+import org.apache.hudi.callback.util.HoodieWriteCommitCallbackUtil;
+import org.apache.hudi.config.HoodieWriteConfig;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+
+/**
+ * Kafka implementation of {@link HoodieWriteCommitCallback}.
+ */
+public class HoodieWriteCommitKafkaCallback implements HoodieWriteCommitCallback {
+
+  private static final Logger LOG = LogManager.getLogger(HoodieWriteCommitKafkaCallback.class);
+
+  private KafkaProducer<String, String> producer;
+  private Properties props;
+
+  public HoodieWriteCommitKafkaCallback(HoodieWriteConfig config) {
+    this.props = config.getProps();
+    this.producer = HoodieWriteCommitKafkaCallbackUtil.createProducer(props);
+  }
+
+  @Override
+  public void call(HoodieWriteCommitCallbackMessage callbackMessage) {
+    String callbackMsg = HoodieWriteCommitCallbackUtil.convertToJsonString(callbackMessage);
+    ProducerRecord<String, String> record = HoodieWriteCommitKafkaCallbackUtil.buildProducerRecord(props, callbackMsg);
+    producer.send(record, new ProducerSendCallback());
+    producer.close();

Review comment:
       Shall we use `try-with-resource` or `try-catch` block to prevent leaking resources?

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/callback/kafka/HoodieWriteCommitKafkaCallbackUtil.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.hudi.utilities.callback.kafka;
+
+import org.apache.hudi.callback.util.HoodieWriteCommitCallbackUtil;
+import org.apache.hudi.common.util.StringUtils;
+import org.apache.hudi.common.util.ValidationUtils;
+
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+
+import static org.apache.hudi.config.HoodieWriteCommitCallbackConfig.CALLBACK_KAFKA_ACKS;
+import static org.apache.hudi.config.HoodieWriteCommitCallbackConfig.CALLBACK_KAFKA_BOOTSTRAP_SERVERS;
+import static org.apache.hudi.config.HoodieWriteCommitCallbackConfig.CALLBACK_KAFKA_PARTITION;
+import static org.apache.hudi.config.HoodieWriteCommitCallbackConfig.CALLBACK_KAFKA_RETRIES;
+import static org.apache.hudi.config.HoodieWriteCommitCallbackConfig.CALLBACK_KAFKA_TOPIC;
+import static org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME;
+
+/**
+ * Util helps to build kafka callback.
+ */
+public class HoodieWriteCommitKafkaCallbackUtil {

Review comment:
       IMO, moving the content of this class into `HoodieWriteCommitKafkaCallback ` is reasonable. WDYT?

##########
File path: hudi-client/src/main/java/org/apache/hudi/config/HoodieWriteCommitCallbackConfig.java
##########
@@ -91,13 +103,44 @@ public Builder withCallbackHttpApiKey(String apiKey) {
       return this;
     }
 
+    public Builder withCallbackKafkaBootstrapServers(String kafkaBootstrapServers) {

Review comment:
       I am thinking one thing: the config options of the callback feature for Kafka are left in `hudi-client`, while the implementation hosts in `hudi-utilities`, if it's suitable.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] yanghua commented on pull request #1886: [HUDI-1122] Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
yanghua commented on pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#issuecomment-677718994


   > > I was wondering can we move this implement to hudi-client module just like the way all the implementations of metrics does.
   > 
   > I think we can move this down the line. `hudi-client` or `hudi-spark` talking a direct dependency on kafka does not feel that clean to me. May be file a follow up JIRA?
   
   @wangxianghu Please follow vc's suggestion, file a Jira issue to track the future work.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 commented on a change in pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 commented on a change in pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#discussion_r464166107



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/callback/kafka/HoodieWriteCommitKafkaCallbackUtil.java
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.hudi.utilities.callback.kafka;
+
+import org.apache.hudi.callback.util.HoodieWriteCommitCallbackUtil;
+import org.apache.hudi.common.util.StringUtils;
+import org.apache.hudi.common.util.ValidationUtils;
+
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+
+import static org.apache.hudi.config.HoodieWriteCommitCallbackConfig.CALLBACK_KAFKA_ACKS;
+import static org.apache.hudi.config.HoodieWriteCommitCallbackConfig.CALLBACK_KAFKA_BOOTSTRAP_SERVERS;
+import static org.apache.hudi.config.HoodieWriteCommitCallbackConfig.CALLBACK_KAFKA_PARTITION;
+import static org.apache.hudi.config.HoodieWriteCommitCallbackConfig.CALLBACK_KAFKA_RETRIES;
+import static org.apache.hudi.config.HoodieWriteCommitCallbackConfig.CALLBACK_KAFKA_TOPIC;
+import static org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME;
+
+/**
+ * Util helps to build kafka callback.
+ */
+public class HoodieWriteCommitKafkaCallbackUtil {

Review comment:
       > 
   > 
   > IMO, moving the content of this class into `HoodieWriteCommitKafkaCallback ` is reasonable. WDYT?
   
   I once hesitated here, kind of messy to host in one class. But it is reasonable, will move




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] wangxianghu commented on a change in pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#discussion_r471314453



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/callback/kafka/HoodieWriteCommitKafkaCallback.java
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.hudi.utilities.callback.kafka;
+
+import org.apache.hudi.callback.HoodieWriteCommitCallback;
+import org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage;
+import org.apache.hudi.callback.util.HoodieWriteCommitCallbackUtil;
+import org.apache.hudi.common.util.StringUtils;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.config.HoodieWriteConfig;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+
+import static org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_ACKS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_BOOTSTRAP_SERVERS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_PARTITION;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_RETRIES;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_TOPIC;
+
+/**
+ * Kafka implementation of {@link HoodieWriteCommitCallback}.
+ */
+public class HoodieWriteCommitKafkaCallback implements HoodieWriteCommitCallback {
+
+  private static final Logger LOG = LogManager.getLogger(HoodieWriteCommitKafkaCallback.class);
+
+  private Properties props;
+  private String bootstrapServers;
+  private String topic;
+
+  public HoodieWriteCommitKafkaCallback(HoodieWriteConfig config) {
+    this.props = config.getProps();
+    this.bootstrapServers = props.getProperty(CALLBACK_KAFKA_BOOTSTRAP_SERVERS);
+    this.topic = props.getProperty(CALLBACK_KAFKA_TOPIC);
+    validateKafkaConfig();
+  }
+
+  @Override
+  public void call(HoodieWriteCommitCallbackMessage callbackMessage) {
+    String callbackMsg = HoodieWriteCommitCallbackUtil.convertToJsonString(callbackMessage);
+    try (KafkaProducer<String, String> producer = createProducer(props)) {
+      ProducerRecord<String, String> record = buildProducerRecord(props, callbackMsg);
+      producer.send(record);
+      LOG.info(String.format("Send callback message %s succeed", callbackMsg));
+    } catch (Exception e) {
+      LOG.error("Send kafka callback msg failed : " + e);
+    }
+  }
+
+  /**
+   * Method helps to create {@link KafkaProducer}. Here we set acks = all and retries = 3 by default to ensure no data
+   * loss.
+   *
+   * @param props Kafka configs
+   * @return A {@link KafkaProducer}
+   */
+  public KafkaProducer<String, String> createProducer(Properties props) {
+    Properties kafkaProducerProps = new Properties();
+    // bootstrap.servers
+    kafkaProducerProps.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+    // default "all" to ensure no message loss
+    kafkaProducerProps.setProperty(ProducerConfig.ACKS_CONFIG, props.getProperty(CALLBACK_KAFKA_ACKS));
+    // retries 3 times by default
+    kafkaProducerProps.setProperty(ProducerConfig.RETRIES_CONFIG, props.getProperty(CALLBACK_KAFKA_RETRIES));
+    kafkaProducerProps.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
+        "org.apache.kafka.common.serialization.StringSerializer");
+    kafkaProducerProps.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
+        "org.apache.kafka.common.serialization.StringSerializer");
+
+    LOG.info("Callback kafka producer init with configs: "

Review comment:
       done

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/callback/kafka/HoodieWriteCommitKafkaCallback.java
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.hudi.utilities.callback.kafka;
+
+import org.apache.hudi.callback.HoodieWriteCommitCallback;
+import org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage;
+import org.apache.hudi.callback.util.HoodieWriteCommitCallbackUtil;
+import org.apache.hudi.common.util.StringUtils;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.config.HoodieWriteConfig;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+
+import static org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_ACKS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_BOOTSTRAP_SERVERS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_PARTITION;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_RETRIES;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_TOPIC;
+
+/**
+ * Kafka implementation of {@link HoodieWriteCommitCallback}.
+ */
+public class HoodieWriteCommitKafkaCallback implements HoodieWriteCommitCallback {
+
+  private static final Logger LOG = LogManager.getLogger(HoodieWriteCommitKafkaCallback.class);
+
+  private Properties props;
+  private String bootstrapServers;
+  private String topic;
+
+  public HoodieWriteCommitKafkaCallback(HoodieWriteConfig config) {
+    this.props = config.getProps();
+    this.bootstrapServers = props.getProperty(CALLBACK_KAFKA_BOOTSTRAP_SERVERS);
+    this.topic = props.getProperty(CALLBACK_KAFKA_TOPIC);
+    validateKafkaConfig();
+  }
+
+  @Override
+  public void call(HoodieWriteCommitCallbackMessage callbackMessage) {
+    String callbackMsg = HoodieWriteCommitCallbackUtil.convertToJsonString(callbackMessage);
+    try (KafkaProducer<String, String> producer = createProducer(props)) {
+      ProducerRecord<String, String> record = buildProducerRecord(props, callbackMsg);
+      producer.send(record);
+      LOG.info(String.format("Send callback message %s succeed", callbackMsg));
+    } catch (Exception e) {
+      LOG.error("Send kafka callback msg failed : " + e);
+    }
+  }
+
+  /**
+   * Method helps to create {@link KafkaProducer}. Here we set acks = all and retries = 3 by default to ensure no data
+   * loss.
+   *
+   * @param props Kafka configs
+   * @return A {@link KafkaProducer}
+   */
+  public KafkaProducer<String, String> createProducer(Properties props) {
+    Properties kafkaProducerProps = new Properties();
+    // bootstrap.servers
+    kafkaProducerProps.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+    // default "all" to ensure no message loss
+    kafkaProducerProps.setProperty(ProducerConfig.ACKS_CONFIG, props.getProperty(CALLBACK_KAFKA_ACKS));
+    // retries 3 times by default
+    kafkaProducerProps.setProperty(ProducerConfig.RETRIES_CONFIG, props.getProperty(CALLBACK_KAFKA_RETRIES));
+    kafkaProducerProps.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
+        "org.apache.kafka.common.serialization.StringSerializer");
+    kafkaProducerProps.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
+        "org.apache.kafka.common.serialization.StringSerializer");
+
+    LOG.info("Callback kafka producer init with configs: "
+        + HoodieWriteCommitCallbackUtil.convertToJsonString(kafkaProducerProps));
+    return new KafkaProducer<String, String>(kafkaProducerProps);
+  }
+
+  /**
+   * Method helps to create a {@link ProducerRecord}. To ensure the order of the callback messages, we should guarantee
+   * that the callback message of the same table will goes to the same partition. Therefore, if user does not specify
+   * the partition, we can use the table name as {@link ProducerRecord} key.
+   *
+   * @param props       Kafka configs
+   * @param callbackMsg Callback message
+   * @return Callback {@link ProducerRecord}
+   */
+  private ProducerRecord<String, String> buildProducerRecord(Properties props, String callbackMsg) {
+    String partition = props.getProperty(CALLBACK_KAFKA_PARTITION);
+    if (null != partition) {
+      return new ProducerRecord<String, String>(topic,
+          Integer.valueOf(partition),
+          props.getProperty(TABLE_NAME),
+          callbackMsg);
+    } else {
+      return new ProducerRecord<String, String>(topic,

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:
users@infra.apache.org



[GitHub] [hudi] vinothchandar commented on pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
vinothchandar commented on pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#issuecomment-670357054


   As the RM sent out the note, we are only landing small PRs and release blockers, so we can keep master stable for cutting the 0.6.0 RC. Apologize for the inconvenience. 
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 commented on a change in pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 commented on a change in pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#discussion_r464165358



##########
File path: hudi-client/src/main/java/org/apache/hudi/config/HoodieWriteCommitCallbackConfig.java
##########
@@ -91,13 +103,44 @@ public Builder withCallbackHttpApiKey(String apiKey) {
       return this;
     }
 
+    public Builder withCallbackKafkaBootstrapServers(String kafkaBootstrapServers) {

Review comment:
       > 
   > 
   > I am thinking one thing: the config options of the callback feature for Kafka are left in `hudi-client`, while the implementation hosts in `hudi-utilities`, if it's suitable.
   
   It is truly a problem. since kafka callback implementation is placed in hudi-utilities, the config should be there too. will move it 




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] yanghua commented on a change in pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#discussion_r465708684



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java
##########
@@ -535,6 +537,11 @@ private HoodieWriteConfig getHoodieClientConfig(SchemaProvider schemaProvider) {
     }
     HoodieWriteConfig config = builder.build();
 
+    // set default value for {@link HoodieWriteCommitKafkaCallbackConfig} if needed.
+    if (config.writeCommitCallbackOn() && HoodieWriteCommitKafkaCallback.class.getName().equals(config.getCallbackClass())) {

Review comment:
       If users configure http callback? Why we only consider Kafka callback here?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] yanghua merged pull request #1886: [HUDI-1122] Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
yanghua merged pull request #1886:
URL: https://github.com/apache/hudi/pull/1886


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 commented on a change in pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 commented on a change in pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#discussion_r465761151



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java
##########
@@ -535,6 +537,11 @@ private HoodieWriteConfig getHoodieClientConfig(SchemaProvider schemaProvider) {
     }
     HoodieWriteConfig config = builder.build();
 
+    // set default value for {@link HoodieWriteCommitKafkaCallbackConfig} if needed.
+    if (config.writeCommitCallbackOn() && HoodieWriteCommitKafkaCallback.class.getName().equals(config.getCallbackClass())) {

Review comment:
       > 
   > 
   > If users configure http callback? Why we only consider Kafka callback here?
   
   the config of http callback will be Initialized when HoodieWriteClient set up, while kafka's can't. the kafka's config can only be set up in hudi-utilities module, so the logic above come up.  




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] wangxianghu commented on pull request #1886: [HUDI-1122] Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#issuecomment-677990052


   > `hudi-client` or `hudi-spark` talking a direct dependency on kafka
   
   @yanghua thanks for your time. The ticket filed here: https://issues.apache.org/jira/browse/HUDI-1207


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] yanghua commented on a change in pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
yanghua commented on a change in pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#discussion_r471306202



##########
File path: hudi-client/src/main/java/org/apache/hudi/callback/util/HoodieWriteCommitCallbackUtil.java
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.hudi.callback.util;
+
+import org.apache.hudi.exception.HoodieCommitCallbackException;
+
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.io.IOException;
+
+/**
+ * Util helps to prepare callback message.
+ */
+public class HoodieWriteCommitCallbackUtil {
+
+  /**
+   * Convert data to json string format.
+   */
+  public static String convertToJsonString(Object obj) {
+    // convert to json
+    ObjectMapper mapper = new ObjectMapper();

Review comment:
       Can we make this variable static to be shared in the whole class?

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/callback/kafka/HoodieWriteCommitKafkaCallback.java
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.hudi.utilities.callback.kafka;
+
+import org.apache.hudi.callback.HoodieWriteCommitCallback;
+import org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage;
+import org.apache.hudi.callback.util.HoodieWriteCommitCallbackUtil;
+import org.apache.hudi.common.util.StringUtils;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.config.HoodieWriteConfig;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+
+import static org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_ACKS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_BOOTSTRAP_SERVERS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_PARTITION;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_RETRIES;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_TOPIC;
+
+/**
+ * Kafka implementation of {@link HoodieWriteCommitCallback}.
+ */
+public class HoodieWriteCommitKafkaCallback implements HoodieWriteCommitCallback {
+
+  private static final Logger LOG = LogManager.getLogger(HoodieWriteCommitKafkaCallback.class);
+
+  private Properties props;
+  private String bootstrapServers;
+  private String topic;
+
+  public HoodieWriteCommitKafkaCallback(HoodieWriteConfig config) {
+    this.props = config.getProps();
+    this.bootstrapServers = props.getProperty(CALLBACK_KAFKA_BOOTSTRAP_SERVERS);
+    this.topic = props.getProperty(CALLBACK_KAFKA_TOPIC);
+    validateKafkaConfig();
+  }
+
+  @Override
+  public void call(HoodieWriteCommitCallbackMessage callbackMessage) {
+    String callbackMsg = HoodieWriteCommitCallbackUtil.convertToJsonString(callbackMessage);
+    try (KafkaProducer<String, String> producer = createProducer(props)) {
+      ProducerRecord<String, String> record = buildProducerRecord(props, callbackMsg);
+      producer.send(record);
+      LOG.info(String.format("Send callback message %s succeed", callbackMsg));
+    } catch (Exception e) {
+      LOG.error("Send kafka callback msg failed : " + e);

Review comment:
       `LOG.error("Send kafka callback msg failed : ",e);`

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/callback/kafka/HoodieWriteCommitKafkaCallback.java
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.hudi.utilities.callback.kafka;
+
+import org.apache.hudi.callback.HoodieWriteCommitCallback;
+import org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage;
+import org.apache.hudi.callback.util.HoodieWriteCommitCallbackUtil;
+import org.apache.hudi.common.util.StringUtils;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.config.HoodieWriteConfig;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+
+import static org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_ACKS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_BOOTSTRAP_SERVERS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_PARTITION;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_RETRIES;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_TOPIC;
+
+/**
+ * Kafka implementation of {@link HoodieWriteCommitCallback}.
+ */
+public class HoodieWriteCommitKafkaCallback implements HoodieWriteCommitCallback {
+
+  private static final Logger LOG = LogManager.getLogger(HoodieWriteCommitKafkaCallback.class);
+
+  private Properties props;
+  private String bootstrapServers;
+  private String topic;
+
+  public HoodieWriteCommitKafkaCallback(HoodieWriteConfig config) {
+    this.props = config.getProps();
+    this.bootstrapServers = props.getProperty(CALLBACK_KAFKA_BOOTSTRAP_SERVERS);
+    this.topic = props.getProperty(CALLBACK_KAFKA_TOPIC);
+    validateKafkaConfig();
+  }
+
+  @Override
+  public void call(HoodieWriteCommitCallbackMessage callbackMessage) {
+    String callbackMsg = HoodieWriteCommitCallbackUtil.convertToJsonString(callbackMessage);
+    try (KafkaProducer<String, String> producer = createProducer(props)) {
+      ProducerRecord<String, String> record = buildProducerRecord(props, callbackMsg);
+      producer.send(record);
+      LOG.info(String.format("Send callback message %s succeed", callbackMsg));
+    } catch (Exception e) {
+      LOG.error("Send kafka callback msg failed : " + e);
+    }
+  }
+
+  /**
+   * Method helps to create {@link KafkaProducer}. Here we set acks = all and retries = 3 by default to ensure no data
+   * loss.
+   *
+   * @param props Kafka configs
+   * @return A {@link KafkaProducer}
+   */
+  public KafkaProducer<String, String> createProducer(Properties props) {
+    Properties kafkaProducerProps = new Properties();
+    // bootstrap.servers
+    kafkaProducerProps.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+    // default "all" to ensure no message loss
+    kafkaProducerProps.setProperty(ProducerConfig.ACKS_CONFIG, props.getProperty(CALLBACK_KAFKA_ACKS));
+    // retries 3 times by default
+    kafkaProducerProps.setProperty(ProducerConfig.RETRIES_CONFIG, props.getProperty(CALLBACK_KAFKA_RETRIES));
+    kafkaProducerProps.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
+        "org.apache.kafka.common.serialization.StringSerializer");
+    kafkaProducerProps.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
+        "org.apache.kafka.common.serialization.StringSerializer");
+
+    LOG.info("Callback kafka producer init with configs: "

Review comment:
       Using `LOG.debug`?

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/callback/kafka/HoodieWriteCommitKafkaCallback.java
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.hudi.utilities.callback.kafka;
+
+import org.apache.hudi.callback.HoodieWriteCommitCallback;
+import org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage;
+import org.apache.hudi.callback.util.HoodieWriteCommitCallbackUtil;
+import org.apache.hudi.common.util.StringUtils;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.config.HoodieWriteConfig;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+
+import static org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_ACKS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_BOOTSTRAP_SERVERS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_PARTITION;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_RETRIES;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_TOPIC;
+
+/**
+ * Kafka implementation of {@link HoodieWriteCommitCallback}.
+ */
+public class HoodieWriteCommitKafkaCallback implements HoodieWriteCommitCallback {
+
+  private static final Logger LOG = LogManager.getLogger(HoodieWriteCommitKafkaCallback.class);
+
+  private Properties props;
+  private String bootstrapServers;
+  private String topic;
+
+  public HoodieWriteCommitKafkaCallback(HoodieWriteConfig config) {
+    this.props = config.getProps();
+    this.bootstrapServers = props.getProperty(CALLBACK_KAFKA_BOOTSTRAP_SERVERS);
+    this.topic = props.getProperty(CALLBACK_KAFKA_TOPIC);
+    validateKafkaConfig();
+  }
+
+  @Override
+  public void call(HoodieWriteCommitCallbackMessage callbackMessage) {
+    String callbackMsg = HoodieWriteCommitCallbackUtil.convertToJsonString(callbackMessage);
+    try (KafkaProducer<String, String> producer = createProducer(props)) {
+      ProducerRecord<String, String> record = buildProducerRecord(props, callbackMsg);
+      producer.send(record);
+      LOG.info(String.format("Send callback message %s succeed", callbackMsg));
+    } catch (Exception e) {
+      LOG.error("Send kafka callback msg failed : " + e);
+    }
+  }
+
+  /**
+   * Method helps to create {@link KafkaProducer}. Here we set acks = all and retries = 3 by default to ensure no data
+   * loss.
+   *
+   * @param props Kafka configs
+   * @return A {@link KafkaProducer}
+   */
+  public KafkaProducer<String, String> createProducer(Properties props) {
+    Properties kafkaProducerProps = new Properties();
+    // bootstrap.servers
+    kafkaProducerProps.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+    // default "all" to ensure no message loss
+    kafkaProducerProps.setProperty(ProducerConfig.ACKS_CONFIG, props.getProperty(CALLBACK_KAFKA_ACKS));
+    // retries 3 times by default
+    kafkaProducerProps.setProperty(ProducerConfig.RETRIES_CONFIG, props.getProperty(CALLBACK_KAFKA_RETRIES));
+    kafkaProducerProps.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
+        "org.apache.kafka.common.serialization.StringSerializer");
+    kafkaProducerProps.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
+        "org.apache.kafka.common.serialization.StringSerializer");
+
+    LOG.info("Callback kafka producer init with configs: "
+        + HoodieWriteCommitCallbackUtil.convertToJsonString(kafkaProducerProps));
+    return new KafkaProducer<String, String>(kafkaProducerProps);
+  }
+
+  /**
+   * Method helps to create a {@link ProducerRecord}. To ensure the order of the callback messages, we should guarantee
+   * that the callback message of the same table will goes to the same partition. Therefore, if user does not specify
+   * the partition, we can use the table name as {@link ProducerRecord} key.
+   *
+   * @param props       Kafka configs
+   * @param callbackMsg Callback message
+   * @return Callback {@link ProducerRecord}
+   */
+  private ProducerRecord<String, String> buildProducerRecord(Properties props, String callbackMsg) {
+    String partition = props.getProperty(CALLBACK_KAFKA_PARTITION);
+    if (null != partition) {
+      return new ProducerRecord<String, String>(topic,
+          Integer.valueOf(partition),
+          props.getProperty(TABLE_NAME),
+          callbackMsg);
+    } else {
+      return new ProducerRecord<String, String>(topic,

Review comment:
       Maybe we do not need to break the lines here?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 commented on pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 commented on pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#issuecomment-665661859


   @yanghua please take a look when free


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 commented on pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 commented on pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#issuecomment-667773074


   > 
   > 
   > @Mathieu1124 Thanks for your contribution. Left some comments you can consider. Did you test this feature in your local?
   
   Yes, I tested  it in my local, it works good.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] wangxianghu commented on a change in pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
wangxianghu commented on a change in pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#discussion_r471314347



##########
File path: hudi-client/src/main/java/org/apache/hudi/callback/util/HoodieWriteCommitCallbackUtil.java
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.hudi.callback.util;
+
+import org.apache.hudi.exception.HoodieCommitCallbackException;
+
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.io.IOException;
+
+/**
+ * Util helps to prepare callback message.
+ */
+public class HoodieWriteCommitCallbackUtil {
+
+  /**
+   * Convert data to json string format.
+   */
+  public static String convertToJsonString(Object obj) {
+    // convert to json
+    ObjectMapper mapper = new ObjectMapper();

Review comment:
       done

##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/callback/kafka/HoodieWriteCommitKafkaCallback.java
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.hudi.utilities.callback.kafka;
+
+import org.apache.hudi.callback.HoodieWriteCommitCallback;
+import org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage;
+import org.apache.hudi.callback.util.HoodieWriteCommitCallbackUtil;
+import org.apache.hudi.common.util.StringUtils;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.config.HoodieWriteConfig;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+
+import static org.apache.hudi.config.HoodieWriteConfig.TABLE_NAME;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_ACKS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_BOOTSTRAP_SERVERS;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_PARTITION;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_RETRIES;
+import static org.apache.hudi.utilities.callback.kafka.HoodieWriteCommitKafkaCallbackConfig.CALLBACK_KAFKA_TOPIC;
+
+/**
+ * Kafka implementation of {@link HoodieWriteCommitCallback}.
+ */
+public class HoodieWriteCommitKafkaCallback implements HoodieWriteCommitCallback {
+
+  private static final Logger LOG = LogManager.getLogger(HoodieWriteCommitKafkaCallback.class);
+
+  private Properties props;
+  private String bootstrapServers;
+  private String topic;
+
+  public HoodieWriteCommitKafkaCallback(HoodieWriteConfig config) {
+    this.props = config.getProps();
+    this.bootstrapServers = props.getProperty(CALLBACK_KAFKA_BOOTSTRAP_SERVERS);
+    this.topic = props.getProperty(CALLBACK_KAFKA_TOPIC);
+    validateKafkaConfig();
+  }
+
+  @Override
+  public void call(HoodieWriteCommitCallbackMessage callbackMessage) {
+    String callbackMsg = HoodieWriteCommitCallbackUtil.convertToJsonString(callbackMessage);
+    try (KafkaProducer<String, String> producer = createProducer(props)) {
+      ProducerRecord<String, String> record = buildProducerRecord(props, callbackMsg);
+      producer.send(record);
+      LOG.info(String.format("Send callback message %s succeed", callbackMsg));
+    } catch (Exception e) {
+      LOG.error("Send kafka callback msg failed : " + e);

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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 commented on pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 commented on pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#issuecomment-670294044


   @yanghua VC seems busy, do you have any other concern about this pr ?
   if it is ok,  can we merge this first, and file a new pr if VC  agree to move this to hudi-client :)


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] vinothchandar commented on pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
vinothchandar commented on pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#issuecomment-670358009


   > I was wondering can we move this implement to hudi-client module just like the way all the implementations of metrics does.
   
   I think we can move this down the line. `hudi-client` or `hudi-spark` talking a direct dependency on kafka does not feel that clean to me. May be file a follow up JIRA? 
   
   
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 commented on a change in pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 commented on a change in pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#discussion_r464165507



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/callback/kafka/HoodieWriteCommitKafkaCallback.java
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.hudi.utilities.callback.kafka;
+
+import org.apache.hudi.callback.HoodieWriteCommitCallback;
+import org.apache.hudi.callback.common.HoodieWriteCommitCallbackMessage;
+import org.apache.hudi.callback.util.HoodieWriteCommitCallbackUtil;
+import org.apache.hudi.config.HoodieWriteConfig;
+
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+
+import java.util.Properties;
+
+/**
+ * Kafka implementation of {@link HoodieWriteCommitCallback}.
+ */
+public class HoodieWriteCommitKafkaCallback implements HoodieWriteCommitCallback {
+
+  private static final Logger LOG = LogManager.getLogger(HoodieWriteCommitKafkaCallback.class);
+
+  private KafkaProducer<String, String> producer;
+  private Properties props;
+
+  public HoodieWriteCommitKafkaCallback(HoodieWriteConfig config) {
+    this.props = config.getProps();
+    this.producer = HoodieWriteCommitKafkaCallbackUtil.createProducer(props);
+  }
+
+  @Override
+  public void call(HoodieWriteCommitCallbackMessage callbackMessage) {
+    String callbackMsg = HoodieWriteCommitCallbackUtil.convertToJsonString(callbackMessage);
+    ProducerRecord<String, String> record = HoodieWriteCommitKafkaCallbackUtil.buildProducerRecord(props, callbackMsg);
+    producer.send(record, new ProducerSendCallback());
+    producer.close();

Review comment:
       > 
   > 
   > Shall we use `try-with-resource` or `try-catch` block to prevent leaking resources?
   
   yes, will do




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 commented on a change in pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 commented on a change in pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#discussion_r464164867



##########
File path: hudi-client/src/main/java/org/apache/hudi/callback/util/HoodieWriteCommitCallbackUtil.java
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.hudi.callback.util;
+
+import org.apache.hudi.exception.HoodieCommitCallbackException;
+
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.io.IOException;
+
+/**
+ * Util helps to prepare callback message.
+ */
+public class HoodieWriteCommitCallbackUtil {
+
+  /**
+   * Convert data to json string format.
+   *
+   * @param obj

Review comment:
       > 
   > 
   > If you do not want to add the comments for `@param` and `@return`. Just remove them.
   
   yes, will remove it




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [hudi] Mathieu1124 commented on pull request #1886: [HUDI-1122]Introduce a kafka implementation of hoodie write commit ca…

Posted by GitBox <gi...@apache.org>.
Mathieu1124 commented on pull request #1886:
URL: https://github.com/apache/hudi/pull/1886#issuecomment-669261486


   Hi @vinothchandar, I was wondering can we move this implement to hudi-client module just like the way all the implementations of metrics does.
   
   put this implementation in hudi-utilities, the Spark API(hudi-spark moudle) can not benefit from it. besides, in the future, when the flink engine merged in , it can not use it either.
   WDYT?
   


----------------------------------------------------------------
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:
users@infra.apache.org