Skip to content

Commit

Permalink
Add regular updating of activity statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jul 7, 2021
1 parent 6009f48 commit d6c7147
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.repo.cache.RepositoryCache;
import com.evolveum.midpoint.repo.common.activity.ActivityExecutionException;
import com.evolveum.midpoint.repo.common.activity.state.ActivityItemProcessingStatistics.Operation;
import com.evolveum.midpoint.repo.common.activity.state.ActivityStatistics;
import com.evolveum.midpoint.repo.common.util.OperationExecutionRecorderForTasks;
Expand Down Expand Up @@ -498,7 +499,19 @@ private void updateStatisticsInTasks(OperationResult result) {

// If needed, let us write current statistics into the repository.
// There is no need to do this for worker task, because it is either the same as the coordinator, or it's a LAT.
coordinatorTask.storeStatisticsIntoRepositoryIfTimePassed(result);
coordinatorTask.storeStatisticsIntoRepositoryIfTimePassed(getActivityStatUpdater(), result);
}

private Runnable getActivityStatUpdater() {
return () -> {
try {
activityExecution.getActivityState().updateProgressAndStatisticsNoCommit();
} catch (ActivityExecutionException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't update activity statistics in the task {}", e,
coordinatorTask);
// Ignoring the exception
}
};
}

private PrismContext getPrismContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* See {@link #updateStatisticsInTaskPrism(boolean)}.
*
* 3. From task.prism to the repository. This takes a lot of time, so it is driven by time interval.
* See {@link #updateAndStoreStatisticsIntoRepository(boolean, OperationResult)} and {@link #storeStatisticsIntoRepositoryIfTimePassed(OperationResult)}
* See {@link #updateAndStoreStatisticsIntoRepository(boolean, OperationResult)} and {@link #storeStatisticsIntoRepositoryIfTimePassed(Runnable, OperationResult)}
* methods.
*
* Statistics collection is always started by calling {@link #startCollectingStatistics(StatisticsCollectionStrategy)} method.
Expand Down Expand Up @@ -70,8 +70,10 @@ public interface RunningTaskStatisticsCollector extends ProgressCollector {
* Stores statistics from `task.prism` to the repository, if the specified time interval passed.
*
* The time interval is there to avoid excessive repository operations. (Writing a large task can take quite a long time.)
*
* FIXME this hack with additional updater
*/
void storeStatisticsIntoRepositoryIfTimePassed(OperationResult result);
void storeStatisticsIntoRepositoryIfTimePassed(Runnable additionalUpdater, OperationResult result);

/**
* Stores statistics from `task.prism` to the repository. Costly operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,12 @@ private void updateOperationalStatsInTaskPrism() {
}

@Override
public void storeStatisticsIntoRepositoryIfTimePassed(OperationResult result) {
public void storeStatisticsIntoRepositoryIfTimePassed(Runnable additionalUpdater, OperationResult result) {
if (lastOperationStatsUpdateTimestamp == null ||
System.currentTimeMillis() - lastOperationStatsUpdateTimestamp > operationStatsUpdateInterval) {
if (additionalUpdater != null) {
additionalUpdater.run();
}
storeStatisticsIntoRepository(result);
}
}
Expand All @@ -226,7 +229,6 @@ public void storeStatisticsIntoRepositoryIfTimePassed(OperationResult result) {
public void storeStatisticsIntoRepository(OperationResult result) {
try {
addPendingModification(createContainerDeltaIfPersistent(TaskType.F_OPERATION_STATS, getStoredOperationStatsOrClone()));
// FIXME addPendingModification(createContainerDeltaIfPersistent(TaskType.F_STRUCTURED_PROGRESS, getStructuredProgressOrClone()));
addPendingModification(createPropertyDeltaIfPersistent(TaskType.F_PROGRESS, getProgress()));
addPendingModification(createPropertyDeltaIfPersistent(TaskType.F_EXPECTED_TOTAL, getExpectedTotal()));
flushPendingModifications(result);
Expand All @@ -251,7 +253,7 @@ public void setStatisticsRepoStoreInterval(long interval) {
public void incrementProgressAndStoreStatisticsIfTimePassed(OperationResult result) {
incrementProgressTransient();
updateStatisticsInTaskPrism(true);
storeStatisticsIntoRepositoryIfTimePassed(result);
storeStatisticsIntoRepositoryIfTimePassed(null, result);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void run(RunningLightweightTask task) {
op.succeeded();
parentTask.incrementProgressTransient();
parentTask.updateStatisticsInTaskPrism(false);
parentTask.storeStatisticsIntoRepositoryIfTimePassed(new OperationResult("store stats"));
parentTask.storeStatisticsIntoRepositoryIfTimePassed(null, new OperationResult("store stats"));
} catch (InterruptedException e) {
LOGGER.trace("Handler for task {} interrupted", task);
op.failed(e);
Expand Down

0 comments on commit d6c7147

Please sign in to comment.