kioie commented on a change in pull request #3480: [WIP DO NOT MERGE] engine, 
server, services: fix for respecting secondary storage threshold limit
URL: https://github.com/apache/cloudstack/pull/3480#discussion_r302391772
 
 

 ##########
 File path: 
engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
 ##########
 @@ -146,17 +145,30 @@ public ImageStoreEntity getImageStore(String uuid) {
     @Override
     public DataStore getImageStore(List<DataStore> imageStores) {
         if (imageStores.size() > 1) {
-            Collections.shuffle(imageStores); // Randomize image store list.
+            imageStores.sort(new Comparator<DataStore>() { // Sort data stores 
based on free capacity
+                @Override
+                public int compare(DataStore store1, DataStore store2) {
+                    return 
Long.compare(_statsCollector.imageStoreCurrentFreeCapacity(store1),
+                            
_statsCollector.imageStoreCurrentFreeCapacity(store2));
+                }
+            });
             Iterator<DataStore> i = imageStores.iterator();
-            DataStore imageStore = null;
             while(i.hasNext()) {
-                imageStore = i.next();
+                DataStore imageStore = i.next();
                 // Return image store if used percentage is less then 
threshold value i.e. 90%.
                 if (_statsCollector.imageStoreHasEnoughCapacity(imageStore)) {
                     return imageStore;
                 }
             }
+        } else if (imageStores.size() == 1) {
+            if 
(_statsCollector.imageStoreHasEnoughCapacity(imageStores.get(0))) {
+                return imageStores.get(0);
+            }
         }
-        return imageStores.get(0);
+
+        // No store with space found
+        s_logger.error(String.format("Can't find an image storage in zone with 
less than %d usage",
+                
Math.round(_statsCollector.getImageStoreCapacityThreshold()*100)));
+        return null;
     }
 
 Review comment:
   Besides checking for whether the store is below the threshold, are you also 
considering doing a check if the image will fit in the imagestore and what 
capacity remains afterwards....for example, if the current used capacity is at 
89% and the image might move it to even upto 99%....or is that check happening 
elsewhere?

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


With regards,
Apache Git Services

Reply via email to