Sahina Bose has uploaded a new change for review.

Change subject: engine: Fixed issue with gluster task cleanup
......................................................................

engine: Fixed issue with gluster task cleanup

In case there are empty clusters or other clusters with
non-operational hosts, the orphan tasks
in db were not getting cleared for operational clusters
either.
Changed the logic to handle the task cleanup cluster-wise.

Change-Id: I70cc24e278d112d889dc2d08ee72fce22a457195
Bug-Url: https://bugzilla.redhat.com/1022996
Signed-off-by: Sahina Bose <sab...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java
1 file changed, 25 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/97/21497/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java
index 8b94e9b..7e53143 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.bll.gluster;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -69,8 +70,7 @@
         log.debug("Refreshing gluster tasks list");
         List<VDSGroup> clusters = getClusterDao().getAll();
 
-        List<Guid> tasksFromClusters = new ArrayList<>();
-        boolean cleanOrphanTasks = true;
+        Map<Guid, Set<Guid>> tasksFromClustersMap = new HashMap<>();
         for (VDSGroup cluster : clusters) {
             if 
(!getGlusterTaskUtils().supportsGlusterAsyncTasksFeature(cluster)) {
                 continue;
@@ -79,16 +79,15 @@
                 Map<Guid, GlusterAsyncTask> runningTasks = 
getProvider().getTaskListForCluster(cluster.getId());
                 if (runningTasks != null) {
                     updateTasksInCluster(cluster, runningTasks);
-                    tasksFromClusters.addAll(runningTasks.keySet());
                 }
+                tasksFromClustersMap.put(cluster.getId(), runningTasks == null 
? null: runningTasks.keySet());
             } catch (VdcBLLException e) {
-                cleanOrphanTasks = false;
+                log.error("Error updating tasks from CLI", e);
             }
         }
 
-        if (cleanOrphanTasks) {
-            cleanUpOrphanTasks(tasksFromClusters);
-        }
+        cleanUpOrphanTasks(tasksFromClustersMap);
+
 
     }
 
@@ -258,21 +257,35 @@
         return JobRepositoryFactory.getJobRepository();
     }
 
-    private void cleanUpOrphanTasks(List<Guid> runningTasksinCluster) {
-      //Populate the list of tasks that need to be monitored from database
+    /**
+     * This method cleans the tasks in DB which the gluster CLI is no longer
+     * aware of.
+     * @param runningTasksinClusterMap - map of cluster id - task list in 
cluster
+     */
+    private void cleanUpOrphanTasks(Map<Guid, Set<Guid>> 
runningTasksinClusterMap) {
+        //Populate the list of tasks that need to be monitored from database
         List<Guid> taskListInDB = getProvider().getMonitoredTaskIDsInDB();
         if (taskListInDB == null || taskListInDB.isEmpty()) {
             return;
         }
 
+        Set<Guid> allRunningTasksInCluster = new HashSet<>();
+        for (Set<Guid> taskSet: runningTasksinClusterMap.values()) {
+            if (taskSet != null) {
+                allRunningTasksInCluster.addAll(taskSet);
+            }
+        }
+
         //if task is in DB but not in running task list
         final Set<Guid> tasksNotRunning = new HashSet<Guid>(taskListInDB);
-        tasksNotRunning.removeAll(runningTasksinCluster);
+        tasksNotRunning.removeAll(allRunningTasksInCluster);
 
         for (Guid taskId: tasksNotRunning) {
             GlusterVolumeEntity vol= 
getVolumeDao().getVolumeByGlusterTask(taskId);
-            if (vol != null && vol.getStatus() != GlusterStatus.UP) {
-                //the volume is not UP. Hence gluster may not have been able 
to return tasks for the volume
+            if (vol != null && vol.getStatus() != GlusterStatus.UP &&  
!runningTasksinClusterMap.keySet().contains((vol.getClusterId()))) {
+                // the volume is not UP. Hence gluster may not have been able 
to return tasks for the volume
+                // also handling the case where gluster was not able to return 
any tasks from this cluster - the keyset will not
+                // contain the cluster id in such case
                 continue;
             }
 


-- 
To view, visit http://gerrit.ovirt.org/21497
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I70cc24e278d112d889dc2d08ee72fce22a457195
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Sahina Bose <sab...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to