lordgamez commented on code in PR #2297:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2297#discussion_r4562448994


##########
libminifi/include/core/state/ComponentStateCache.h:
##########
@@ -0,0 +1,53 @@
+/**
+ * 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.
+ */
+#pragma once
+
+#include <shared_mutex>
+#include <string>
+#include <vector>
+
+#include "utils/Id.h"
+#include "core/state/UpdateController.h"
+
+namespace org::apache::nifi::minifi::core {
+class Processor;
+class ProcessGroup;
+}  // namespace org::apache::nifi::minifi::core
+
+namespace org::apache::nifi::minifi::state {
+
+// Identity of a root process group, copied out of it whenever the root 
changes, so that it can be read from another
+// thread (eg. a metrics thread) without touching the process group itself.
+struct RootIdentity {
+  std::string name;
+  utils::Identifier uuid;
+  std::string version{"0"};
+};
+
+// Thread-safe snapshot of a root process group's identity and processor list, 
guarded by a leaf mutex: it is never
+// held while any other minifi mutex is taken, so metrics threads can read it 
without inverting the lock order.
+struct ComponentStateCache {

Review Comment:
   nitpick: The instance of this struct `component_cache_` is only used through 
its getters and setter and that's correct, but the members should be private, 
maybe even make it a class instead of a struct.



##########
libminifi/src/core/state/nodes/ResponseNodeLoader.cpp:
##########


Review Comment:
   Claude code comment:
   Empty FlowInformation/QueueMetrics node can stay cached for a whole flow. 
Between clearConfigRoot() (sets root_ = nullptr) and setNewConfigRoot(), a 
describe request (C2MetricsPublisher::getMetricsNode("FlowInformation")) 
creates the node with no connections or processors and caches it in 
system_metrics_. setNewConfigRoot() never clears system_metrics_, so 
C2MetricsPublisher::loadMetricNodes() picks up the same empty node. The 
heartbeat's FlowInformation and QueueMetrics would then be empty until the next 
reload. The window existed before this commit. Even so, the new comment ("must 
be before … otherwise a reader could create and cache a system metrics node 
bound to the old root") and the comment in getSystemMetricsNode both claim this 
race is closed, and it isn't.
   
   Suggested fix:
   Drop cached system nodes when the new root is published:
   ```
   void setNewConfigRoot(core::ProcessGroup* root) {
       { 
           std::scoped_lock guard(system_metrics_mutex_, root_mutex_);
           system_metrics_.clear(); 
           root_ = root; 
       }
       initializeComponentMetrics(); 
   }
   ```
             
   Or skip caching root-dependent nodes while root_ == nullptr.



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

Reply via email to