This is an automated email from the ASF dual-hosted git repository.
pvillard31 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 158b8bb25f9 NIFI-16598: Return retried FlowFiles to the active queue
when swapping (#11934)
158b8bb25f9 is described below
commit 158b8bb25f98fd2b703a74505c766db8f0cbe809
Author: Wojciech <[email protected]>
AuthorDate: Wed Nov 18 12:41:30 2026 +0100
NIFI-16598: Return retried FlowFiles to the active queue when swapping
(#11934)
* NIFI-16598: Return retried FlowFiles to the active queue when swapping.
Relationship retry used putAll, which parks the FlowFile on the swap queue
behind later active FlowFiles. Session rollback already uses putToActive
(NIFI-16468); retries need the same path so YIELD_PROCESSOR keeps FIFO
order.
---
.../nifi/controller/queue/FlowFileQueue.java | 4 +--
.../repository/StandardProcessSession.java | 19 +++++++++++--
.../repository/StandardProcessSessionIT.java | 33 ++++++++++++++++++++++
3 files changed, 52 insertions(+), 4 deletions(-)
diff --git
a/nifi-framework-api/src/main/java/org/apache/nifi/controller/queue/FlowFileQueue.java
b/nifi-framework-api/src/main/java/org/apache/nifi/controller/queue/FlowFileQueue.java
index 10f7290f813..fcbb285558f 100644
---
a/nifi-framework-api/src/main/java/org/apache/nifi/controller/queue/FlowFileQueue.java
+++
b/nifi-framework-api/src/main/java/org/apache/nifi/controller/queue/FlowFileQueue.java
@@ -164,8 +164,8 @@ public interface FlowFileQueue {
/**
* Places the given FlowFile onto the active portion of the queue, never
onto the swap queue, even if the queue is
* currently swapping FlowFiles out. This is intended for FlowFiles that
were previously polled from this queue and are
- * being returned to it, such as on session rollback. Because such a
FlowFile was polled from the active queue, it was
- * ahead of any FlowFiles that are swapped out, and placing it back onto
the active queue preserves that ordering.
+ * being returned to it, such as on session rollback or a relationship
retry. Because such a FlowFile was polled from the
+ * active queue, it was ahead of any FlowFiles that are swapped out, and
placing it back onto the active queue preserves that ordering.
*
* @param file the FlowFile to place onto the active queue
*/
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java
index 561c25d79b5..e78f5d46e0e 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java
@@ -654,10 +654,25 @@ public class StandardProcessSession implements
ProcessSession, ProvenanceEventEn
// record.getCurrent() will return null if this record was
created in this session --
// in this case, we just ignore it, and it will be cleaned up
by clearing the records map.
if (record.getCurrent() != null) {
- Collection<FlowFileRecord> collection =
recordMap.get(record.getDestination());
+ final FlowFileQueue destination = record.getDestination();
+ // A retry rebuilds the FlowFile from the original, so it
keeps the original queue time and queue index.
+ // Transfer onto the same queue (a self-loop or transfer
without a relationship) assigns a new queue time
+ // and must go through putAll so the FlowFile is not
placed ahead of swapped FlowFiles.
+ if (destination != null &&
destination.equals(record.getOriginalQueue())) {
+ final FlowFileRecord original = record.getOriginal();
+ final FlowFileRecord current = record.getCurrent();
+ if (original != null
+ && Objects.equals(original.getLastQueueDate(),
current.getLastQueueDate())
+ && original.getQueueDateIndex() ==
current.getQueueDateIndex()) {
+ destination.putToActive(current);
+ continue;
+ }
+ }
+
+ Collection<FlowFileRecord> collection =
recordMap.get(destination);
if (collection == null) {
collection = new ArrayList<>();
- recordMap.put(record.getDestination(), collection);
+ recordMap.put(destination, collection);
}
collection.add(record.getCurrent());
}
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/StandardProcessSessionIT.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/StandardProcessSessionIT.java
index 25261c982a0..306dbd849a6 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/StandardProcessSessionIT.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/StandardProcessSessionIT.java
@@ -1944,6 +1944,39 @@ public class StandardProcessSessionIT {
assertEquals(flowFileCount, flowFileQueue.size().getObjectCount());
}
+ @Test
+ public void testRetryReturnsFlowFileToFrontOfSwappingQueue() {
+ final Connectable processor = createProcessorConnectable();
+ configureRetry(processor, 1, BackoffMechanism.YIELD_PROCESSOR, "1 ms",
1L);
+ final StandardProcessSession retrySession =
createSessionForRetry(processor);
+
+ final int flowFileCount = 10_001;
+ for (int i = 0; i < flowFileCount; i++) {
+ final FlowFileRecord flowFileRecord = new
StandardFlowFileRecord.Builder()
+ .id(i)
+ .addAttribute("uuid",
String.format("00000000-0000-0000-0000-%012d", i))
+ .entryDate(System.currentTimeMillis())
+ .size(0L)
+ .build();
+ flowFileQueue.put(flowFileRecord);
+ }
+
+ final FlowFile firstFlowFile = retrySession.get();
+ assertEquals(0, firstFlowFile.getId());
+ retrySession.transfer(firstFlowFile, new
Relationship.Builder().name("failure").build());
+ retrySession.commit();
+
+ final FlowFile flowFileAfterRetry = retrySession.get();
+ assertEquals(0, flowFileAfterRetry.getId());
+ assertEquals(flowFileCount, flowFileQueue.size().getObjectCount());
+
+ retrySession.transfer(flowFileAfterRetry);
+ retrySession.commit();
+
+ final FlowFile flowFileAfterSelfTransfer = retrySession.get();
+ assertEquals(1, flowFileAfterSelfTransfer.getId());
+ }
+
@Test
public void testCreateEmitted() throws IOException {
final FlowFile newFlowFile = session.create();