imay commented on a change in pull request #671: Implement the routine load 
process of Kafka on Backend
URL: https://github.com/apache/incubator-doris/pull/671#discussion_r260684487
 
 

 ##########
 File path: be/src/runtime/routine_load/data_consumer.cpp
 ##########
 @@ -0,0 +1,195 @@
+// 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.
+
+#include "runtime/routine_load/data_consumer.h"
+
+#include <algorithm>
+#include <functional>
+#include <string>
+#include <vector>
+
+#include "common/status.h"
+#include "runtime/routine_load/kafka_consumer_pipe.h"
+#include "util/defer_op.h"
+#include "util/stopwatch.hpp"
+
+namespace doris {
+
+Status KafkaDataConsumer::init() {
+    std::unique_lock<std::mutex> l(_lock); 
+    if (_init) {
+        // this consumer has already been initialized.
+        return Status::OK;
+    }
+
+    RdKafka::Conf *conf = RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL);
+    
+    // conf has to be deleted finally
+    auto conf_deleter = [] (RdKafka::Conf *conf) { delete conf; };
+    DeferOp delete_conf(std::bind<void>(conf_deleter, conf));
+
+    std::string errstr;
+#define SET_KAFKA_CONF(conf_key, conf_val) \
+    if (conf->set(conf_key, conf_val, errstr) != RdKafka::Conf::CONF_OK) { \
+        std::stringstream ss; \
+        ss << "failed to set '" << conf_key << "'"; \
+        LOG(WARNING) << ss.str(); \
+        return Status(ss.str()); \
+    }
+
+    SET_KAFKA_CONF("metadata.broker.list", _ctx->kafka_info->brokers);
+    SET_KAFKA_CONF("group.id", _ctx->kafka_info->group_id);
+    SET_KAFKA_CONF("client.id", _ctx->kafka_info->client_id);
+    SET_KAFKA_CONF("enable.partition.eof", "false");
+    SET_KAFKA_CONF("enable.auto.offset.store", "false");
+    // TODO: set it larger than 0 after we set rd_kafka_conf_set_stats_cb()
+    SET_KAFKA_CONF("statistics.interval.ms", "0");
+
+    // create consumer
+    _k_consumer = RdKafka::KafkaConsumer::create(conf, errstr); 
+    if (!_k_consumer) {
+        LOG(WARNING) << "failed to create kafka consumer";
+        return Status("failed to create kafka consumer");
+    }
+
+    // create TopicPartitions
+    std::vector<RdKafka::TopicPartition*> topic_partitions;
+    for (auto& entry : _ctx->kafka_info->begin_offset) {
+        RdKafka::TopicPartition* tp1 = RdKafka::TopicPartition::create(
+                _ctx->kafka_info->topic, entry.first, entry.second);
+        topic_partitions.push_back(tp1);
+    }
+
+    // delete TopicPartition finally
+    auto tp_deleter = [] (const std::vector<RdKafka::TopicPartition*>& vec) {
+        std::for_each(vec.begin(), vec.end(),
+                [](RdKafka::TopicPartition* tp1) { delete tp1; });
+    };
+    DeferOp delete_tp(std::bind<void>(tp_deleter, topic_partitions));
 
 Review comment:
   no need to use `std::bind`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to