lordgamez commented on code in PR #1888:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1888#discussion_r1843436107
##########
libminifi/src/core/flow/StructuredConfiguration.cpp:
##########
@@ -145,6 +145,41 @@ std::unique_ptr<core::ProcessGroup>
StructuredConfiguration::getRootFrom(const N
}
}
+namespace {
+bool hasInheritanceCycle(const ParameterContext& parameter_context,
std::unordered_set<std::string>& visited_parameter_contexts,
std::unordered_set<std::string>& current_stack) {
+ if (current_stack.contains(parameter_context.getName())) {
+ return true;
+ }
+
+ if (visited_parameter_contexts.contains(parameter_context.getName())) {
+ return false;
+ }
+
+ current_stack.insert(parameter_context.getName());
+ visited_parameter_contexts.insert(parameter_context.getName());
+
+ for (const auto& inherited_parameter_context :
parameter_context.getInheritedParameterContexts()) {
+ if (hasInheritanceCycle(*inherited_parameter_context,
visited_parameter_contexts, current_stack)) {
+ return true;
+ }
+ }
+
+ current_stack.erase(parameter_context.getName());
+
+ return false;
+}
+} // namespace
+
+void StructuredConfiguration::verifyNoInheritanceCycles() const {
+ std::unordered_set<std::string> visited_parameter_contexts;
+ std::unordered_set<std::string> current_stack;
+ for (const auto& [parameter_context_name, parameter_context] :
parameter_contexts_) {
+ if (hasInheritanceCycle(*parameter_context, visited_parameter_contexts,
current_stack)) {
+ throw std::invalid_argument("Circular references in Parameter Context
inheritance are not allowed. Inheritance cycle was detected in parameter
context '" + parameter_context->getName() + "'");
+ }
+ }
+}
+
Review Comment:
I'm not sure this requires a timeout or any restriction. The cycle detection
run a depth-first search algorithm which has linear complexity based on the
number of parameter contexts, so it should not be running that long even for
large number of parameter contexts. But I suppose even in flows where parameter
contexts could be generated, like using a parameter provider that would
generate parameters based on file hierarchies the number of contexts should
only be in the 1000s at most which would still not cause a problem with
algorithm.
--
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]