szaszm commented on code in PR #1038: URL: https://github.com/apache/nifi-minifi-cpp/pull/1038#discussion_r920025164
########## extensions/rocksdb-repos/FlowFileLoader.cpp: ########## @@ -0,0 +1,112 @@ +/** + * 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 "FlowFileLoader.h" + +#include <span> +#include <memory> +#include <string> +#include <vector> +#include <utility> + +#include "logging/LoggerConfiguration.h" +#include "FlowFileRecord.h" + +namespace org::apache::nifi::minifi { + +FlowFileLoader::FlowFileLoader() + : logger_(core::logging::LoggerFactory<FlowFileLoader>::getLogger()) {} + +FlowFileLoader::~FlowFileLoader() { + stop(); +} + +void FlowFileLoader::initialize(gsl::not_null<minifi::internal::RocksDatabase *> db, std::shared_ptr<core::ContentRepository> content_repo) { + db_ = db; + content_repo_ = std::move(content_repo); +} + +std::future<FlowFileLoader::FlowFilePtrVec> FlowFileLoader::load(std::vector<SwappedFlowFile> flow_files) { + auto promise = std::make_shared<std::promise<FlowFilePtrVec>>(); + std::future<FlowFilePtrVec> future = promise->get_future(); + utils::Worker<utils::TaskRescheduleInfo> task{ + std::bind(&FlowFileLoader::loadImpl, this, std::move(flow_files), std::move(promise)), + "", // doesn't matter that tasks alias by name, as we never actually query their status or stop a single task + std::make_unique<utils::ComplexMonitor>()}; + std::future<utils::TaskRescheduleInfo> dummy_future; + thread_pool_.execute(std::move(task), dummy_future); + return future; Review Comment: Shouldn't this return a future that's resolved when the flow file is loaded? I find the current approach confusing. ########## libminifi/src/Connection.cpp: ########## @@ -169,8 +182,14 @@ void Connection::drain(bool delete_permanently) { std::lock_guard<std::mutex> lock(mutex_); while (!queue_.empty()) { - std::shared_ptr<core::FlowFile> item = queue_.pop(); - logger_->log_debug("Delete flow file UUID %s from connection %s, because it expired", item->getUUIDStr(), name_); + // TODO(adebreceni): we don't actually use the whole flow file + // there could be a more optimal solution without triggering a swap-in Review Comment: Ideally the swap-in would be done in the content repository, when the flow file is being read. It's enough if we start thinking about smarter solutions when it's apparent that that is too late / too slow. ########## extensions/rocksdb-repos/FlowFileLoader.cpp: ########## @@ -0,0 +1,112 @@ +/** + * 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 "FlowFileLoader.h" + +#include <span> +#include <memory> +#include <string> +#include <vector> +#include <utility> + +#include "logging/LoggerConfiguration.h" +#include "FlowFileRecord.h" + +namespace org::apache::nifi::minifi { + +FlowFileLoader::FlowFileLoader() + : logger_(core::logging::LoggerFactory<FlowFileLoader>::getLogger()) {} + +FlowFileLoader::~FlowFileLoader() { + stop(); +} + +void FlowFileLoader::initialize(gsl::not_null<minifi::internal::RocksDatabase *> db, std::shared_ptr<core::ContentRepository> content_repo) { + db_ = db; + content_repo_ = std::move(content_repo); +} + +std::future<FlowFileLoader::FlowFilePtrVec> FlowFileLoader::load(std::vector<SwappedFlowFile> flow_files) { + auto promise = std::make_shared<std::promise<FlowFilePtrVec>>(); + std::future<FlowFilePtrVec> future = promise->get_future(); + utils::Worker<utils::TaskRescheduleInfo> task{ + std::bind(&FlowFileLoader::loadImpl, this, std::move(flow_files), std::move(promise)), Review Comment: Prefer lambdas over `std::bind`. https://abseil.io/tips/108 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
