Skip to content

Commit 3b69432

Browse files
committed
Enhance secondary storage copy limit check to consider image stores by zone scope
1 parent bbc0560 commit 3b69432

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateServiceImpl.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,29 @@ private boolean hasReachedSecStorageCopyLimit(VMTemplateVO template, long zoneId
304304
if (copyLimit <= 0) {
305305
return false;
306306
}
307-
List<TemplateDataStoreVO> existing = _vmTemplateStoreDao.listByTemplateZoneDownloadStatus(
308-
template.getId(), zoneId,
309-
Status.DOWNLOADED, Status.DOWNLOAD_IN_PROGRESS, Status.NOT_DOWNLOADED);
310-
int currentCopies = existing == null ? 0 : existing.size();
311-
return currentCopies >= copyLimit;
307+
List<DataStore> stores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
308+
if (stores == null || stores.isEmpty()) {
309+
return false;
310+
}
311+
int count = 0;
312+
for (DataStore ds : stores) {
313+
List<TemplateDataStoreVO> rows = _vmTemplateStoreDao.listByTemplateStore(template.getId(), ds.getId());
314+
if (rows == null) {
315+
continue;
316+
}
317+
for (TemplateDataStoreVO row : rows) {
318+
State st = row.getState();
319+
Status ds_state = row.getDownloadState();
320+
if (st != State.Failed && st != State.Destroyed
321+
&& ds_state != Status.ABANDONED && ds_state != Status.DOWNLOAD_ERROR) {
322+
count++;
323+
break;
324+
}
325+
}
326+
}
327+
logger.debug("Template [{}] secstorage copy check in zone [{}]: count={}, limit={}",
328+
template.getUniqueName(), zoneId, count, copyLimit);
329+
return count >= copyLimit;
312330
}
313331

314332
protected boolean shouldDownloadTemplateToStore(VMTemplateVO template, DataStore store) {

0 commit comments

Comments
 (0)