Skip to content

Commit

Permalink
fix reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Reza Zamani Zadeh Najari committed Feb 11, 2020
1 parent 9694b81 commit de0f8fb
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions helix-core/src/main/java/org/apache/helix/task/TaskUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1040,31 +1040,34 @@ public static void purgeExpiredJobs(String workflow, WorkflowConfig workflowConf
/**
* The function that loops through the all existing workflow contexts and removes IdealState and
* workflow context of the workflow whose workflow config does not exist.
* Try-catch has been used to avoid concurrent modification exception while doing deep copy. Since
* Map.keySet() can produce concurrent modification exception.
* @param dataProvider
* @param manager
*/
public static void workflowGarbageCollection(final WorkflowControllerDataProvider dataProvider,
final HelixManager manager) {
// Garbage collections for conditions where workflow context exists but config is missing.

// toBeDeletedWorkflows is a set that contains the name of the workflows that their contexts
// should be deleted.
Set<String> toBeDeletedWorkflows = new HashSet<>();
Set<String> existingWorkflowContexts;
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);
}
}
}
existingWorkflowContexts = new HashSet<>(dataProvider.getContexts().keySet());
} catch (Exception e) {
LOG.warn(
"Exception occurred while creating a list of all existing contexts with missing config!",
e);
return;
}

// toBeDeletedWorkflows is a set that contains the name of the workflows that their contexts
// should be deleted.
Set<String> toBeDeletedWorkflows = new HashSet<>();
for (String entry : existingWorkflowContexts) {
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);
}
}

HelixDataAccessor accessor = manager.getHelixDataAccessor();
Expand Down

0 comments on commit de0f8fb

Please sign in to comment.