This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new a7d1b09326e NIFI-16545 Add rebase handler for connection backpressure, 
FlowFile expiration and prioritizer changes (#11888)
a7d1b09326e is described below

commit a7d1b09326ed4e544f1111c397e6ff67b44940de
Author: Pierre Villard <[email protected]>
AuthorDate: Tue Nov 10 16:09:05 2026 +0100

    NIFI-16545 Add rebase handler for connection backpressure, FlowFile 
expiration and prioritizer changes (#11888)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../ConnectionSettingsChangedRebaseHandler.java    |  95 +++++++++++++
 .../registry/flow/diff/RebaseConflictCode.java     |   5 +
 .../registry/flow/diff/StandardRebaseEngine.java   |   4 +
 ...ConnectionSettingsChangedRebaseHandlerTest.java | 148 +++++++++++++++++++++
 .../nifi/registry/flow/diff/RebaseEngineTest.java  |  29 ++++
 5 files changed, 281 insertions(+)

diff --git 
a/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/ConnectionSettingsChangedRebaseHandler.java
 
b/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/ConnectionSettingsChangedRebaseHandler.java
new file mode 100644
index 00000000000..4a8ab2ce583
--- /dev/null
+++ 
b/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/ConnectionSettingsChangedRebaseHandler.java
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+package org.apache.nifi.registry.flow.diff;
+
+import org.apache.nifi.flow.VersionedComponent;
+import org.apache.nifi.flow.VersionedConnection;
+import org.apache.nifi.flow.VersionedProcessGroup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Handles back pressure threshold, FlowFile expiration and prioritizer 
changes on connections. An upstream change to the
+ * same setting of the same connection conflicts with the local change unless 
it results in the same value.
+ */
+public class ConnectionSettingsChangedRebaseHandler implements RebaseHandler {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(ConnectionSettingsChangedRebaseHandler.class);
+
+    private static final Set<DifferenceType> SUPPORTED_TYPES = Set.of(
+            DifferenceType.BACKPRESSURE_OBJECT_THRESHOLD_CHANGED,
+            DifferenceType.BACKPRESSURE_DATA_SIZE_THRESHOLD_CHANGED,
+            DifferenceType.FLOWFILE_EXPIRATION_CHANGED,
+            DifferenceType.PRIORITIZERS_CHANGED);
+
+    private final DifferenceType supportedType;
+
+    public ConnectionSettingsChangedRebaseHandler(final DifferenceType 
supportedType) {
+        if (!SUPPORTED_TYPES.contains(supportedType)) {
+            throw new IllegalArgumentException("Unsupported difference type " 
+ supportedType);
+        }
+        this.supportedType = supportedType;
+    }
+
+    @Override
+    public DifferenceType getSupportedType() {
+        return supportedType;
+    }
+
+    @Override
+    public RebaseAnalysis.ClassifiedDifference classify(final FlowDifference 
localDifference, final Set<FlowDifference> upstreamDifferences,
+                                                        final 
VersionedProcessGroup targetSnapshot) {
+        final VersionedComponent localComponent = 
localDifference.getComponentB();
+        final String componentIdentifier = localComponent.getIdentifier();
+        if (!(localComponent instanceof VersionedConnection)) {
+            return 
RebaseAnalysis.ClassifiedDifference.unsupported(localDifference, 
RebaseConflictCode.UNSUPPORTED_COMPONENT_TYPE,
+                    "Connection setting change is not supported for component 
%s of type %s".formatted(componentIdentifier, 
localComponent.getComponentType()));
+        }
+        if 
(RebaseHandlerUtils.findConflictingUpstreamDifference(localDifference, 
upstreamDifferences).isPresent()) {
+            return 
RebaseAnalysis.ClassifiedDifference.conflicting(localDifference, 
RebaseConflictCode.SAME_CONNECTION_SETTING,
+                    "Both local and upstream flows modified the same setting 
of connection " + componentIdentifier);
+        }
+        return RebaseAnalysis.ClassifiedDifference.compatible(localDifference);
+    }
+
+    @Override
+    public void apply(final FlowDifference localDifference, final 
VersionedProcessGroup mergedFlow) {
+        final String componentIdentifier = 
localDifference.getComponentB().getIdentifier();
+        final VersionedConnection connection = 
RebaseHandlerUtils.findConnectionById(mergedFlow, componentIdentifier);
+        if (connection == null) {
+            logger.warn("Unable to apply connection setting change: connection 
[{}] not found in merged flow", componentIdentifier);
+            return;
+        }
+
+        final VersionedConnection localConnection = (VersionedConnection) 
localDifference.getComponentB();
+        switch (supportedType) {
+            case BACKPRESSURE_OBJECT_THRESHOLD_CHANGED -> 
connection.setBackPressureObjectThreshold(localConnection.getBackPressureObjectThreshold());
+            case BACKPRESSURE_DATA_SIZE_THRESHOLD_CHANGED -> 
connection.setBackPressureDataSizeThreshold(localConnection.getBackPressureDataSizeThreshold());
+            case FLOWFILE_EXPIRATION_CHANGED -> 
connection.setFlowFileExpiration(localConnection.getFlowFileExpiration());
+            case PRIORITIZERS_CHANGED -> {
+                final List<String> prioritizers = 
localConnection.getPrioritizers();
+                connection.setPrioritizers(prioritizers == null ? null : new 
ArrayList<>(prioritizers));
+            }
+            default -> throw new IllegalStateException("Unsupported difference 
type " + supportedType);
+        }
+    }
+}
diff --git 
a/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/RebaseConflictCode.java
 
b/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/RebaseConflictCode.java
index 60b165c433c..af7ffa4e46f 100644
--- 
a/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/RebaseConflictCode.java
+++ 
b/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/RebaseConflictCode.java
@@ -67,6 +67,11 @@ public enum RebaseConflictCode {
      */
     SAME_SCHEDULING,
 
+    /**
+     * Both the local and upstream flows modified the same setting of the same 
connection to different values.
+     */
+    SAME_CONNECTION_SETTING,
+
     /**
      * The component targeted by the local change does not exist in the target 
version.
      */
diff --git 
a/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/StandardRebaseEngine.java
 
b/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/StandardRebaseEngine.java
index 9ebbcb6ecb6..c1b8e9dc67c 100644
--- 
a/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/StandardRebaseEngine.java
+++ 
b/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/main/java/org/apache/nifi/registry/flow/diff/StandardRebaseEngine.java
@@ -55,6 +55,10 @@ public class StandardRebaseEngine implements RebaseEngine {
         registerHandler(new ScheduledStateChangedRebaseHandler());
         registerHandler(new 
SchedulingChangedRebaseHandler(DifferenceType.SCHEDULING_STRATEGY_CHANGED));
         registerHandler(new 
SchedulingChangedRebaseHandler(DifferenceType.RUN_SCHEDULE_CHANGED));
+        registerHandler(new 
ConnectionSettingsChangedRebaseHandler(DifferenceType.BACKPRESSURE_OBJECT_THRESHOLD_CHANGED));
+        registerHandler(new 
ConnectionSettingsChangedRebaseHandler(DifferenceType.BACKPRESSURE_DATA_SIZE_THRESHOLD_CHANGED));
+        registerHandler(new 
ConnectionSettingsChangedRebaseHandler(DifferenceType.FLOWFILE_EXPIRATION_CHANGED));
+        registerHandler(new 
ConnectionSettingsChangedRebaseHandler(DifferenceType.PRIORITIZERS_CHANGED));
     }
 
     public StandardRebaseEngine(final Map<DifferenceType, RebaseHandler> 
handlerRegistry) {
diff --git 
a/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/test/java/org/apache/nifi/registry/flow/diff/ConnectionSettingsChangedRebaseHandlerTest.java
 
b/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/test/java/org/apache/nifi/registry/flow/diff/ConnectionSettingsChangedRebaseHandlerTest.java
new file mode 100644
index 00000000000..0670ffbf564
--- /dev/null
+++ 
b/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/test/java/org/apache/nifi/registry/flow/diff/ConnectionSettingsChangedRebaseHandlerTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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.
+ */
+
+package org.apache.nifi.registry.flow.diff;
+
+import org.apache.nifi.flow.VersionedConnection;
+import org.apache.nifi.flow.VersionedProcessGroup;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class ConnectionSettingsChangedRebaseHandlerTest {
+
+    private static final String ROOT = "root";
+    private static final String CHILD_GROUP = "child-group";
+    private static final String CONN_A = "conn-a";
+    private static final String CONN_B = "conn-b";
+    private static final String FIFO_PRIORITIZER = 
"org.apache.nifi.prioritizer.FirstInFirstOutPrioritizer";
+    private static final String NEWEST_PRIORITIZER = 
"org.apache.nifi.prioritizer.NewestFlowFileFirstPrioritizer";
+
+    private static final Map<DifferenceType, Setting> SETTINGS = Map.of(
+            DifferenceType.BACKPRESSURE_OBJECT_THRESHOLD_CHANGED, new 
Setting(10000L, 500L, 2000L,
+                    VersionedConnection::getBackPressureObjectThreshold, 
(connection, value) -> connection.setBackPressureObjectThreshold((Long) value)),
+            DifferenceType.BACKPRESSURE_DATA_SIZE_THRESHOLD_CHANGED, new 
Setting("1 GB", "500 MB", "2 GB",
+                    VersionedConnection::getBackPressureDataSizeThreshold, 
(connection, value) -> connection.setBackPressureDataSizeThreshold((String) 
value)),
+            DifferenceType.FLOWFILE_EXPIRATION_CHANGED, new Setting("0 sec", 
"5 min", "10 min",
+                    VersionedConnection::getFlowFileExpiration, (connection, 
value) -> connection.setFlowFileExpiration((String) value)),
+            DifferenceType.PRIORITIZERS_CHANGED, new Setting(List.of(), 
List.of(FIFO_PRIORITIZER), List.of(NEWEST_PRIORITIZER),
+                    VersionedConnection::getPrioritizers, (connection, value) 
-> connection.setPrioritizers(toStringList(value))));
+
+    @ParameterizedTest
+    @EnumSource(value = DifferenceType.class, names = 
{"BACKPRESSURE_OBJECT_THRESHOLD_CHANGED", 
"BACKPRESSURE_DATA_SIZE_THRESHOLD_CHANGED",
+            "FLOWFILE_EXPIRATION_CHANGED", "PRIORITIZERS_CHANGED"})
+    void testNoUpstreamChange(final DifferenceType type) {
+        final Setting setting = SETTINGS.get(type);
+        final ConnectionSettingsChangedRebaseHandler handler = new 
ConnectionSettingsChangedRebaseHandler(type);
+        final FlowDifference localDifference = createDifference(type, CONN_A, 
setting.local());
+        final FlowDifference upstreamOtherConnection = createDifference(type, 
CONN_B, setting.upstream());
+
+        final RebaseAnalysis.ClassifiedDifference result = 
handler.classify(localDifference, Set.of(upstreamOtherConnection), 
createGroup(ROOT));
+
+        assertEquals(RebaseClassification.COMPATIBLE, 
result.getClassification());
+    }
+
+    @ParameterizedTest
+    @EnumSource(value = DifferenceType.class, names = 
{"BACKPRESSURE_OBJECT_THRESHOLD_CHANGED", 
"BACKPRESSURE_DATA_SIZE_THRESHOLD_CHANGED",
+            "FLOWFILE_EXPIRATION_CHANGED", "PRIORITIZERS_CHANGED"})
+    void testUpstreamChangedToSameValue(final DifferenceType type) {
+        final Setting setting = SETTINGS.get(type);
+        final ConnectionSettingsChangedRebaseHandler handler = new 
ConnectionSettingsChangedRebaseHandler(type);
+        final FlowDifference localDifference = createDifference(type, CONN_A, 
setting.local());
+        final FlowDifference upstreamDifference = createDifference(type, 
CONN_A, setting.local());
+
+        final RebaseAnalysis.ClassifiedDifference result = 
handler.classify(localDifference, Set.of(upstreamDifference), 
createGroup(ROOT));
+
+        assertEquals(RebaseClassification.COMPATIBLE, 
result.getClassification());
+    }
+
+    @ParameterizedTest
+    @EnumSource(value = DifferenceType.class, names = 
{"BACKPRESSURE_OBJECT_THRESHOLD_CHANGED", 
"BACKPRESSURE_DATA_SIZE_THRESHOLD_CHANGED",
+            "FLOWFILE_EXPIRATION_CHANGED", "PRIORITIZERS_CHANGED"})
+    void testUpstreamChangedToDifferentValue(final DifferenceType type) {
+        final Setting setting = SETTINGS.get(type);
+        final ConnectionSettingsChangedRebaseHandler handler = new 
ConnectionSettingsChangedRebaseHandler(type);
+        final FlowDifference localDifference = createDifference(type, CONN_A, 
setting.local());
+        final FlowDifference upstreamDifference = createDifference(type, 
CONN_A, setting.upstream());
+
+        final RebaseAnalysis.ClassifiedDifference result = 
handler.classify(localDifference, Set.of(upstreamDifference), 
createGroup(ROOT));
+
+        assertEquals(RebaseClassification.CONFLICTING, 
result.getClassification());
+        assertEquals(RebaseConflictCode.SAME_CONNECTION_SETTING, 
result.getConflictCode());
+    }
+
+    @ParameterizedTest
+    @EnumSource(value = DifferenceType.class, names = 
{"BACKPRESSURE_OBJECT_THRESHOLD_CHANGED", 
"BACKPRESSURE_DATA_SIZE_THRESHOLD_CHANGED",
+            "FLOWFILE_EXPIRATION_CHANGED", "PRIORITIZERS_CHANGED"})
+    void testApplyConnectionInChildGroup(final DifferenceType type) {
+        final Setting setting = SETTINGS.get(type);
+        final ConnectionSettingsChangedRebaseHandler handler = new 
ConnectionSettingsChangedRebaseHandler(type);
+        final VersionedProcessGroup mergedFlow = createGroup(ROOT);
+        final VersionedProcessGroup childGroup = createGroup(CHILD_GROUP);
+        mergedFlow.getProcessGroups().add(childGroup);
+        final VersionedConnection connection = createConnection(CONN_A, 
setting, setting.original());
+        childGroup.getConnections().add(connection);
+
+        final FlowDifference localDifference = createDifference(type, CONN_A, 
setting.local());
+        assertEquals(RebaseClassification.COMPATIBLE, 
handler.classify(localDifference, Collections.emptySet(), 
mergedFlow).getClassification());
+        handler.apply(localDifference, mergedFlow);
+
+        assertEquals(setting.local(), setting.getter().apply(connection));
+    }
+
+    @Test
+    void testUnsupportedDifferenceTypeRejected() {
+        assertThrows(IllegalArgumentException.class, () -> new 
ConnectionSettingsChangedRebaseHandler(DifferenceType.LOAD_BALANCE_STRATEGY_CHANGED));
+    }
+
+    private FlowDifference createDifference(final DifferenceType type, final 
String identifier, final Object localValue) {
+        final Setting setting = SETTINGS.get(type);
+        return new StandardFlowDifference(type, createConnection(identifier, 
setting, setting.original()), createConnection(identifier, setting, localValue),
+                setting.original(), localValue, "Connection setting changed");
+    }
+
+    private VersionedConnection createConnection(final String identifier, 
final Setting setting, final Object value) {
+        final VersionedConnection connection = new VersionedConnection();
+        connection.setIdentifier(identifier);
+        setting.setter().accept(connection, value);
+        return connection;
+    }
+
+    private VersionedProcessGroup createGroup(final String identifier) {
+        final VersionedProcessGroup group = new VersionedProcessGroup();
+        group.setIdentifier(identifier);
+        return group;
+    }
+
+    private static List<String> toStringList(final Object value) {
+        return ((List<?>) value).stream().map(String.class::cast).toList();
+    }
+
+    private record Setting(Object original, Object local, Object upstream, 
Function<VersionedConnection, Object> getter,
+                           BiConsumer<VersionedConnection, Object> setter) {
+    }
+}
diff --git 
a/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/test/java/org/apache/nifi/registry/flow/diff/RebaseEngineTest.java
 
b/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/test/java/org/apache/nifi/registry/flow/diff/RebaseEngineTest.java
index 5bdd3e93a37..c14f0dc9ef7 100644
--- 
a/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/test/java/org/apache/nifi/registry/flow/diff/RebaseEngineTest.java
+++ 
b/nifi-registry/nifi-registry-core/nifi-registry-flow-diff/src/test/java/org/apache/nifi/registry/flow/diff/RebaseEngineTest.java
@@ -695,6 +695,35 @@ class RebaseEngineTest {
         assertEquals(2, mergedConn.getBends().size());
     }
 
+    @Test
+    void testBackPressureObjectThresholdChangeCompatibility() {
+        final VersionedConnection originalConn = createConnection("conn-a");
+        originalConn.setBackPressureObjectThreshold(10000L);
+
+        final VersionedConnection localConn = createConnection("conn-a");
+        localConn.setBackPressureObjectThreshold(500L);
+
+        final Set<FlowDifference> localDifferences = new HashSet<>();
+        localDifferences.add(new 
StandardFlowDifference(DifferenceType.BACKPRESSURE_OBJECT_THRESHOLD_CHANGED, 
originalConn, localConn,
+                10000L, 500L, "Back pressure object threshold changed"));
+
+        final VersionedConnection targetConn = createConnection("conn-a");
+        targetConn.setBackPressureObjectThreshold(10000L);
+
+        final VersionedProcessGroup targetSnapshot = new 
VersionedProcessGroup();
+        targetSnapshot.setIdentifier("root");
+        targetSnapshot.getConnections().add(targetConn);
+
+        final RebaseAnalysis analysis = engine.analyze(localDifferences, 
Collections.emptySet(), targetSnapshot);
+
+        assertTrue(analysis.isRebaseAllowed());
+        assertEquals(RebaseClassification.COMPATIBLE, 
analysis.getClassifiedLocalChanges().get(0).getClassification());
+        assertNotNull(analysis.getMergedSnapshot());
+
+        final VersionedConnection mergedConn = 
analysis.getMergedSnapshot().getConnections().iterator().next();
+        assertEquals(500L, mergedConn.getBackPressureObjectThreshold());
+    }
+
     @Test
     void testCommentsChangeCompatibility() {
         final VersionedProcessor processor = createProcessor("proc-a", 
"ProcessorA");

Reply via email to