You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2020/11/06 10:40:15 UTC

[GitHub] [cloudstack] DaanHoogland commented on a change in pull request #4428: Moved dedicated hosts to the end of the resultset when selecting an e…

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



##########
File path: engine/storage/src/main/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
##########
@@ -128,9 +132,24 @@ 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 ");
+        if (dedicatedHosts.size() > 0) {
+            Collections.shuffle(dedicatedHosts); // Randomize dedicated hosts as well.
+            sbuilder.append("field(t.id, ");
+            Iterator<Long> hostIt = dedicatedHosts.iterator();
+            while (hostIt.hasNext()) { // put dedicated hosts at the end of the result set
+                sbuilder.append("'" + hostIt.next() + "'");
+                if (hostIt.hasNext()) {
+                    sbuilder.append(",");
+                }
+            }
+            sbuilder.append(")," );
+        }

Review comment:
       pretty please, @Spaceman1984 




----------------------------------------------------------------
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:
users@infra.apache.org