Yair Zaslavsky has uploaded a new change for review. Change subject: core: Treat "only in db" zombie tasks ......................................................................
core: Treat "only in db" zombie tasks When system restarts, there may be some tasks that exist only in the DB (form previous run). If this occurs, these tasks are not polled, and will not be removed from DB. The following mechanism introduces zombie tasks handling for these tasks as well. Tasks that are added to db using "createTask" from commands are also added to the "polling tasks" map so they should not be added to the "only in db" collection for zombie task treatment. Change-Id: Ie13ae21eaadb1bb621a7fc8ad471e60387a3699b Signed-off-by: Yair Zaslavsky <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskManager.java 1 file changed, 25 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/55/12055/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskManager.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskManager.java index 8f8bed6..6affedf 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskManager.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskManager.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -55,6 +56,7 @@ /** Map which consist all tasks that currently are monitored **/ private Map<Guid, SPMAsyncTask> _tasks; + private List<AsyncTasks> tasksInDbAfterRestart = null; /** Indication if _tasks has changed for logging process. **/ private boolean logChangedMap = true; @@ -70,6 +72,7 @@ private AsyncTaskManager() { _tasks = new HashMap<Guid, SPMAsyncTask>(); + tasksInDbAfterRestart = DbFacade.getInstance().getAsyncTaskDao().getAll(); SchedulerUtil scheduler = SchedulerUtilQuartzImpl.getInstance(); scheduler.scheduleAFixedDelayJob(this, "_timer_Elapsed", new Class[] {}, @@ -88,6 +91,9 @@ @OnTimerMethodAnnotation("_timer_Elapsed") public synchronized void _timer_Elapsed() { + long timeForZombieTasks = DateTime.getNow() + .AddMinutes((-1) * Config.<Integer> GetValue(ConfigValues.AsyncTaskZombieTaskLifeInMinutes)).getTime(); + if (ThereAreTasksToPoll()) { PollAndUpdateAsyncTasks(); @@ -102,8 +108,11 @@ // check for zombie tasks if (_tasks.size() > 0) { - cleanZombieTasks(); + cleanPolledZombieTasks(timeForZombieTasks); } + } + if (tasksInDbAfterRestart.size() > 0) { + cleanOnlyInDbZombieTasks(timeForZombieTasks); } } @@ -169,12 +178,9 @@ && (task.getState() != AsyncTaskState.ClearFailed); } - private void cleanZombieTasks() { - long maxTime = DateTime.getNow() - .AddMinutes((-1) * Config.<Integer> GetValue(ConfigValues.AsyncTaskZombieTaskLifeInMinutes)).getTime(); + private void cleanPolledZombieTasks(long timeForZombieTasks) { for (SPMAsyncTask task : _tasks.values()) { - - if (task.getParameters().getDbAsyncTask().getStartTime().getTime() < maxTime) { + if (task.getParameters().getDbAsyncTask().getStartTime().getTime() < timeForZombieTasks) { AuditLogableBase logable = new AuditLogableBase(); logable.addCustomValue("CommandName", task.getParameters().getDbAsyncTask().getaction_type().toString()); logable.addCustomValue("Date", task.getParameters().getDbAsyncTask().getStartTime().toString()); @@ -203,6 +209,19 @@ } } + private void cleanOnlyInDbZombieTasks(long timeForZombieTasks) { + Iterator<AsyncTasks> tasksInDbIterator = tasksInDbAfterRestart.iterator(); + while (tasksInDbIterator.hasNext()) { + AsyncTasks task = tasksInDbIterator.next(); + if (!_tasks.containsKey(task.gettask_id())) { + if (task.getStartTime().getTime() < timeForZombieTasks) { + tasksInDbIterator.remove(); + DbFacade.getInstance().getAsyncTaskDao().remove(task.gettask_id()); + } + } + } + } + private int NumberOfTasksToPoll() { int retValue = 0; for (SPMAsyncTask task : _tasks.values()) { -- To view, visit http://gerrit.ovirt.org/12055 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie13ae21eaadb1bb621a7fc8ad471e60387a3699b Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yair Zaslavsky <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
