Spaceman1984 commented on a change in pull request #4428:
URL: https://github.com/apache/cloudstack/pull/4428#discussion_r512719682



##########
File path: 
engine/storage/src/main/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
##########
@@ -128,9 +131,15 @@ protected EndPoint findEndPointInScope(Scope scope, String 
sqlBase, Long poolId)
             }
         }
 
+        List<Long> dedicatedHosts = dedicatedResourceDao.listAllHosts();
+
         // TODO: order by rand() is slow if there are lot of hosts
         sbuilder.append(") t where t.value<>'true' or t.value is null");    
//Added for exclude cluster's subquery
-        sbuilder.append(" ORDER by rand() limit 1");
+        sbuilder.append(" ORDER by ");
+        for (Long hostId: dedicatedHosts){ // put dedicated hosts at the end 
of the result set
+            sbuilder.append("field(t.id, '" + hostId +"')," );
+        }
+        sbuilder.append(" rand() limit 1");

Review comment:
       ```
   select t.id from (
       select h.id, cd.value 
       from host h 
       join storage_pool_host_ref s on h.id = s.host_id  
       join cluster c on c.id=h.cluster_id 
       left join cluster_details cd on c.id=cd.cluster_id 
       and cd.name='cluster.storage.operations.exclude' 
       where h.status = 'Up' 
       and h.type = 'Routing' 
       and h.resource_state = 'Enabled' 
       and s.pool_id = 1
       and h.data_center_id = 1
   ) t 
   where t.value<>'true' 
   or t.value is null ORDER BY field(t.id, '2'), field(t.id, '5'), rand() limit 
1
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to