Skip to content

Commit

Permalink
Prune operation result after each bucket
Browse files Browse the repository at this point in the history
This is to avoid uncontrollable growth of task operation result,
resulting in OOMs, extra large repo objects, and/or long task execution.

Should resolve MID-7830 (at least partially).
  • Loading branch information
mederly committed Apr 6, 2022
1 parent 569fec1 commit bbadfcf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ private void doRun(OperationResult result)
}

complete = processOrAnalyzeOrSkipSingleBucket(result);
pruneResult(result);

if (!complete) {
break;
}
Expand All @@ -263,6 +265,29 @@ private void doRun(OperationResult result)
}
}

/**
* Keeps the result of reasonable size:
*
* 1. removes successful minor subresults
* 2. summarizes operations (if there is a lot of buckets - see MID-7830)
*
* We catch all exceptions here, because we don't want the task to fail on these checks.
* We also want to execute the summarization even if the cleanup fails.
*/
private void pruneResult(OperationResult result) {
try {
result.cleanupResultDeeply();
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't clean up the operation result in {}", e, this);
}

try {
result.summarize();
} catch (Exception e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't summarize the operation result in {}", e, this);
}
}

private boolean shouldProcessBucket(OperationResult result) {
ExpressionType condition = getActivity().getControlFlowDefinition().getBucketProcessingCondition();
if (condition == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ private void updateTaskResult(TaskRunResult runResult) {
if (runResult.getMessage() != null) {
taskResult.setMessage(runResult.getMessage());
}
// TODO Clean up the result before updating (summarize, remove minor operations - maybe deeply?) - see e.g. MID-7830
task.setResult(taskResult); // This updates the result in the task prism object.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ private void updateTaskResult(Task task) {
}
}

// TODO Clean up the result before updating (summarize, remove minor operations - maybe deeply?) - see e.g. MID-7830
// Update result and result status in prism.
task.setResult(taskResult);
}

/** Executes close operation in the repository task object, i.e. with no regards of Quartz. */
private void closeInTask(TaskQuartzImpl task, OperationResult result)
throws ObjectNotFoundException, SchemaException {
LOGGER.trace("Closing task in repository: {}", task);
Expand Down

0 comments on commit bbadfcf

Please sign in to comment.