narendly commented on a change in pull request #741: Fix ConcurrentModification 
exception in Workflow Garbage Collection
URL: https://github.com/apache/helix/pull/741#discussion_r377434390
 
 

 ##########
 File path: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java
 ##########
 @@ -1043,23 +1043,33 @@ public static void purgeExpiredJobs(String workflow, 
WorkflowConfig workflowConf
    * @param dataProvider
    * @param manager
    */
-  public static void workflowGarbageCollection(WorkflowControllerDataProvider 
dataProvider,
+  public static void workflowGarbageCollection(final 
WorkflowControllerDataProvider dataProvider,
       final HelixManager manager) {
     // Garbage collections for conditions where workflow context exists but 
config is missing.
-    Map<String, ZNRecord> contexts = dataProvider.getContexts();
-    HelixDataAccessor accessor = manager.getHelixDataAccessor();
-    HelixPropertyStore<ZNRecord> propertyStore = 
manager.getHelixPropertyStore();
 
+    // toBeDeletedWorkflows is a set that contains the name of the workflows 
that their contexts
+    // should be deleted.
     Set<String> toBeDeletedWorkflows = new HashSet<>();
-    for (Map.Entry<String, ZNRecord> entry : contexts.entrySet()) {
-      if (entry.getValue() != null
-          && entry.getValue().getId().equals(TaskUtil.WORKFLOW_CONTEXT_KW)) {
-        if (dataProvider.getWorkflowConfig(entry.getKey()) == null) {
-          toBeDeletedWorkflows.add(entry.getKey());
+    try {
+      Set<String> existingWorkflowContexts = new 
HashSet<>(dataProvider.getContexts().keySet());
+      for (String entry : existingWorkflowContexts) {
+        if (entry != null) {
+          WorkflowConfig cfg = dataProvider.getWorkflowConfig(entry);
+          WorkflowContext ctx = dataProvider.getWorkflowContext(entry);
+          if (ctx != null && ctx.getId().equals(TaskUtil.WORKFLOW_CONTEXT_KW) 
&& cfg == null) {
+            toBeDeletedWorkflows.add(entry);
+          }
         }
       }
+    } catch (Exception e) {
+      LOG.warn(
+          "Exception occurred while creating a list of all existing contexts 
with missing config!",
+          e);
     }
 
 Review comment:
   If you make a deep copy of the set, you shouldn't need to wrap it with a 
try-catch since your async thread would be the only thread iterating over the 
data structure, correct? What I'm not understanding is why we need the 
try-catch.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org

Reply via email to