From 44755c839183de1c99062919307e0eca608b14b5 Mon Sep 17 00:00:00 2001 From: Remco Westerhoud Date: Mon, 8 May 2023 10:01:57 +0200 Subject: [PATCH] feat(engine): activate multi instance children in batches Instead of writing all the ACTIVATE commands for all children at once, we now use the ProcessInstanceBatch.ACTIVATE command instead. This command takes an index, which in this case is the amount of children that an ACTIVATE command will be written for. --- .../behavior/BpmnStateTransitionBehavior.java | 17 +++++++++++++++++ .../container/MultiInstanceBodyProcessor.java | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/engine/src/main/java/io/camunda/zeebe/engine/processing/bpmn/behavior/BpmnStateTransitionBehavior.java b/engine/src/main/java/io/camunda/zeebe/engine/processing/bpmn/behavior/BpmnStateTransitionBehavior.java index b7bddce12657..74ddc2dd3b3a 100644 --- a/engine/src/main/java/io/camunda/zeebe/engine/processing/bpmn/behavior/BpmnStateTransitionBehavior.java +++ b/engine/src/main/java/io/camunda/zeebe/engine/processing/bpmn/behavior/BpmnStateTransitionBehavior.java @@ -304,6 +304,23 @@ public long activateChildInstanceWithKey( return childInstanceKey; } + /** + * Activate a given amount of children of a multi-instance element. + * + * @param context the context of the multi-instance element + * @param amount the amount of children for which we will write an activate command + */ + public void activateChildInstancesInBatches(final BpmnElementContext context, final int amount) { + final var record = + new ProcessInstanceBatchRecord() + .setProcessInstanceKey(context.getProcessInstanceKey()) + .setBatchElementInstanceKey(context.getElementInstanceKey()) + .setIndex(amount); + + final var key = keyGenerator.nextKey(); + commandWriter.appendFollowUpCommand(key, ProcessInstanceBatchIntent.ACTIVATE, record); + } + public void activateElementInstanceInFlowScope( final BpmnElementContext context, final ExecutableFlowElement element) { diff --git a/engine/src/main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java b/engine/src/main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java index 789588cd2cb3..7be0e8f2c017 100644 --- a/engine/src/main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java +++ b/engine/src/main/java/io/camunda/zeebe/engine/processing/bpmn/container/MultiInstanceBodyProcessor.java @@ -274,7 +274,7 @@ private void activate( if (loopCharacteristics.isSequential()) { createInnerInstance(element, activated); } else { - inputCollection.forEach(item -> createInnerInstance(element, activated)); + stateTransitionBehavior.activateChildInstancesInBatches(context, inputCollection.size()); } }