CLOUDSTACK-8603: Random list VM failures at scale (more than 1000 VMs) when VM 
has resource tags There is no 'removed' field on the resource_tags table. So 
'id' based search may return a record or null in case record is deleted. Added 
a check for null or empty in search resource tags based on 'id'.

Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>

This closes #551


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5d9f851d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5d9f851d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5d9f851d

Branch: refs/heads/reporter
Commit: 5d9f851deb1a12e4a07297353ea715f9cf13e677
Parents: 3a19a89
Author: Koushik Das <kous...@apache.org>
Authored: Wed Jul 1 23:17:46 2015 +0530
Committer: Rohit Yadav <rohit.ya...@shapeblue.com>
Committed: Fri Jul 3 15:25:11 2015 +0530

----------------------------------------------------------------------
 .../api/query/dao/ResourceTagJoinDaoImpl.java   | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5d9f851d/server/src/com/cloud/api/query/dao/ResourceTagJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/ResourceTagJoinDaoImpl.java 
b/server/src/com/cloud/api/query/dao/ResourceTagJoinDaoImpl.java
index a496753..3ec10dd 100644
--- a/server/src/com/cloud/api/query/dao/ResourceTagJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/ResourceTagJoinDaoImpl.java
@@ -149,20 +149,24 @@ public class ResourceTagJoinDaoImpl extends 
GenericDaoBase<ResourceTagJoinVO, Lo
     public ResourceTagJoinVO searchById(Long id) {
         SearchCriteria<ResourceTagJoinVO> sc = tagIdSearch.create();
         sc.setParameters("id", id);
-        List<ResourceTagJoinVO> vms = searchIncludingRemoved(sc, null, null, 
false);
-        assert vms != null && vms.size() == 1 : "No tag found for tag id " + 
id;
-        return vms.get(0);
+        List<ResourceTagJoinVO> tags = searchIncludingRemoved(sc, null, null, 
false);
+        if (tags != null && tags.size() > 0) {
+            return tags.get(0);
+        } else {
+            return null;
+        }
     }
 
     @Override
     public ResourceTagJoinVO newResourceTagView(ResourceTag vr) {
-
         SearchCriteria<ResourceTagJoinVO> sc = tagIdSearch.create();
         sc.setParameters("id", vr.getId());
-        List<ResourceTagJoinVO> vms = searchIncludingRemoved(sc, null, null, 
false);
-        assert vms != null && vms.size() == 1 : "No tag found for tag id " + 
vr.getId();
-        return vms.get(0);
-
+        List<ResourceTagJoinVO> tags = searchIncludingRemoved(sc, null, null, 
false);
+        if (tags != null && tags.size() > 0) {
+            return tags.get(0);
+        } else {
+            return null;
+        }
     }
 
 }

Reply via email to