fgerlits commented on code in PR #1497:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1497#discussion_r1112809441
##########
libminifi/src/core/state/nodes/ResponseNodeLoader.cpp:
##########
@@ -25,89 +25,129 @@
#include "core/state/nodes/QueueMetrics.h"
#include "core/state/nodes/AgentInformation.h"
#include "core/state/nodes/ConfigurationChecksums.h"
-#include "c2/C2Agent.h"
#include "utils/gsl.h"
#include "utils/RegexUtils.h"
#include "utils/StringUtils.h"
+#include "c2/C2Utils.h"
namespace org::apache::nifi::minifi::state::response {
ResponseNodeLoader::ResponseNodeLoader(std::shared_ptr<Configure>
configuration, std::shared_ptr<core::Repository> provenance_repo,
- std::shared_ptr<core::Repository> flow_file_repo, core::FlowConfiguration*
flow_configuration)
+ std::shared_ptr<core::Repository> flow_file_repo,
std::shared_ptr<core::FlowConfiguration> flow_configuration)
: configuration_(std::move(configuration)),
provenance_repo_(std::move(provenance_repo)),
flow_file_repo_(std::move(flow_file_repo)),
- flow_configuration_(flow_configuration) {
+ flow_configuration_(std::move(flow_configuration)) {
}
-void ResponseNodeLoader::initializeComponentMetrics(core::ProcessGroup* root) {
+void ResponseNodeLoader::clearConfigRoot() {
+ {
+ std::lock_guard<std::mutex> guard(system_metrics_mutex_);
+ system_metrics_.clear();
+ }
+ {
+ std::lock_guard<std::mutex> guard(component_metrics_mutex_);
+ component_metrics_.clear();
+ }
+ {
+ std::lock_guard<std::mutex> guard(root_mutex_);
+ root_ = nullptr;
+ }
+}
+
+void ResponseNodeLoader::setNewConfigRoot(core::ProcessGroup* root) {
+ {
+ std::lock_guard<std::mutex> guard(root_mutex_);
+ root_ = root;
+ }
+ initializeComponentMetrics();
+}
+
+void ResponseNodeLoader::initializeComponentMetrics() {
{
std::lock_guard<std::mutex> guard(component_metrics_mutex_);
component_metrics_.clear();
}
- if (!root) {
+ std::lock_guard<std::mutex> guard(root_mutex_);
+ if (!root_) {
return;
}
std::vector<core::Processor*> processors;
- root->getAllProcessors(processors);
+ root_->getAllProcessors(processors);
Review Comment:
Yes, good point. Maybe we could collect the metrics into a local map under
the `root_mutex_` lock, and separately (after releasing the `root_mutex_` lock)
insert them into `component_metrics_` under the `component_metrics_mutex_`?
Locking a mutex while already holding another mutex can easily cause problems
later on.
--
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]