szaszm commented on code in PR #1038: URL: https://github.com/apache/nifi-minifi-cpp/pull/1038#discussion_r925504241
########## 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: I feel like this is hacking around the added complexity of using ThreadPool. Why not use utils::FifoExecutor? I may be biased, since I wrote FifoExecutor, but it's meant to solve this exact problem: You give it a function of T, and it gives back a future of T. edit: I just realized that retries are needed. With FifoExecutor, you can't set a delay to retry flow file loading. The best you can do is add it to the back of the queue. -- 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]
