tiagodolphine commented on code in PR #1906:
URL: 
https://github.com/apache/incubator-kie-kogito-apps/pull/1906#discussion_r1395637144


##########
data-index/data-index-common/src/main/java/org/kie/kogito/index/service/IndexingService.java:
##########
@@ -69,6 +71,34 @@ public class IndexingService {
     Instance<UserTaskInstanceEventMerger> userTaskInstanceMergers;
 
     public void indexProcessInstanceEvent(ProcessInstanceDataEvent<?> event) {
+        //retry in case of rare but possible race condition during the insert 
for the first registry
+        ProcessInstance pi = executeWithRetry(event, 
this::handleProcessInstanceEvent, "indexing process instance");
+
+        ProcessDefinition definition = pi.getDefinition();
+
+        if (definition != null && 
!manager.getProcessDefinitionsCache().containsKey(definition.getKey())) {
+            //retry in case of rare but possible race condition during the 
insert for the first registry
+            executeWithRetry(definition, this::handleProcessDefinition, 
"indexing process definition");
+            LOGGER.debug("Stored Process Definition: {}", definition);
+        }
+    }
+
+    private ProcessDefinition handleProcessDefinition(ProcessDefinition 
definition) {
+        return manager.getProcessDefinitionsCache().put(definition.getKey(), 
definition);
+    }
+
+    private <R, T> R executeWithRetry(T input, Function<T, R> toExecute, 
String logMessage) {
+        R response;
+        try {
+            response = toExecute.apply(input);
+        } catch (ConcurrentModificationException e) {
+            LOGGER.warn("Retrying {} for {} {}", logMessage, input, 
e.getMessage());
+            response = toExecute.apply(input);

Review Comment:
   see that with the current impl it is very simple just retrying once and no 
delay, we can add that, but it would be better as I mentioned in the other 
comment to use `smallrye-fault-tolerance`.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to