You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/09/02 12:25:10 UTC

[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #621: MINIFICPP-959: Review librdkafka thread safety

arpadboda commented on a change in pull request #621: MINIFICPP-959: Review librdkafka thread safety
URL: https://github.com/apache/nifi-minifi-cpp/pull/621#discussion_r319932086
 
 

 ##########
 File path: extensions/librdkafka/KafkaConnection.cpp
 ##########
 @@ -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.
+ */
+
+#include "KafkaConnection.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace processors {
+
+KafkaConnection::KafkaConnection(const KafkaConnectionKey &key)
+    : logger_(logging::LoggerFactory<KafkaConnection>::getLogger()),
+      conf_(nullptr),
+      kafka_connection_(nullptr) {
+  lease_ = false;
+  initialized_ = false;
+  key_ = key;
+}
+
+void KafkaConnection::remove() {
+  topics_.clear();
+  removeConnection();
+}
+
+void KafkaConnection::removeConnection() {
+  if (kafka_connection_) {
+    rd_kafka_flush(kafka_connection_, 10 * 1000); /* wait for max 10 seconds */
+    rd_kafka_destroy(kafka_connection_);
+    modifyLoggers([&](std::unordered_map<const rd_kafka_t*, std::weak_ptr<logging::Logger>>& loggers) {
+      loggers.erase(kafka_connection_);
+    });
+    kafka_connection_ = nullptr;
+  }
+  if (conf_) {
+    rd_kafka_conf_destroy(conf_);
+    conf_ = nullptr;
+  }
+  initialized_ = false;
+}
+
+bool KafkaConnection::initialized() const {
+  return initialized_;
+}
+
+void KafkaConnection::setConnection(rd_kafka_t *producer, rd_kafka_conf_t *conf) {
+  std::lock_guard<std::mutex> lock(mutex_);
 
 Review comment:
   I think this is needless here.
   The mutex is only responsible in this class for protecting lease_.
   
   To make this a bit more clear, please either rename the mutex or add some comment at the declaration of the mutex to indicate the fact that this mutex is *not* responsible to make the usage of the class thread-fase. 

----------------------------------------------------------------
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


With regards,
Apache Git Services