Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,6 @@ List<VMInstanceVO> searchRemovedByRemoveDate(final Date startDate, final Date en
List<VMInstanceVO> listDeleteProtectedVmsByAccountId(long accountId);

List<VMInstanceVO> listDeleteProtectedVmsByDomainIds(Set<Long> domainIds);

List<VMInstanceVO> listByIds(List<Long> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1336,4 +1336,17 @@ public List<VMInstanceVO> listDeleteProtectedVmsByDomainIds(Set<Long> domainIds)
Filter filter = new Filter(VMInstanceVO.class, null, false, 0L, 10L);
return listBy(sc, filter);
}

@Override
public List<VMInstanceVO> listByIds(List<Long> ids) {
if (ids == null || ids.isEmpty()) {
return new ArrayList<>();
}
SearchBuilder<VMInstanceVO> sb = createSearchBuilder();
sb.and("id", sb.entity().getId(), Op.IN);
sb.done();
SearchCriteria<VMInstanceVO> sc = sb.create();
sc.setParameters("id", ids.toArray());
return listBy(sc);
}
}
21 changes: 19 additions & 2 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,10 @@ public void connectHostsToPool(DataStore primaryStore, List<Long> hostIds, Scope
if (CollectionUtils.isEmpty(hostIds)) {
return;
}
Map<Long, HostVO> hostMap = new HashMap<>();
for (HostVO h : _hostDao.listByIds(hostIds)) {
hostMap.put(h.getId(), h);
}
CopyOnWriteArrayList<Long> poolHostIds = new CopyOnWriteArrayList<>();
ExecutorService executorService = Executors.newFixedThreadPool(Math.max(1, Math.min(hostIds.size(),
StoragePoolHostConnectWorkers.value())));
Expand All @@ -1856,10 +1860,14 @@ public void connectHostsToPool(DataStore primaryStore, List<Long> hostIds, Scope
if (exceptionOccurred.get()) {
return null;
}
HostVO host = hostMap.get(hostId);
if (host == null) {
logger.warn("Host [{}] not found, skipping pool connection for {}", hostId, primaryStore);
return null;
}
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<Exception>() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) throws Exception {
HostVO host = _hostDao.findById(hostId);
try {
connectHostToSharedPool(host, primaryStore.getId());
poolHostIds.add(hostId);
Expand Down Expand Up @@ -2126,9 +2134,18 @@ public void cleanupStorage(boolean recurring) {
cleanupSecondaryStorage(recurring);

List<VolumeVO> vols = volumeDao.listVolumesToBeDestroyed(new Date(System.currentTimeMillis() - ((long)StorageCleanupDelay.value() << 10)));
List<Long> rootVolumeVmIds = vols.stream()
.filter(v -> Type.ROOT.equals(v.getVolumeType()) && v.getInstanceId() != null)
.map(VolumeVO::getInstanceId)
.distinct()
.collect(Collectors.toList());
Map<Long, VMInstanceVO> vmMap = new HashMap<>();
for (VMInstanceVO vm : _vmInstanceDao.listByIds(rootVolumeVmIds)) {
vmMap.put(vm.getId(), vm);
}
for (VolumeVO vol : vols) {
if (Type.ROOT.equals(vol.getVolumeType())) {
VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(vol.getInstanceId());
VMInstanceVO vmInstanceVO = vol.getInstanceId() != null ? vmMap.get(vol.getInstanceId()) : null;
if (vmInstanceVO != null && vmInstanceVO.getState() == State.Destroyed) {
logger.debug("ROOT volume [{}] will not be expunged because the VM is [{}], therefore this volume will be expunged with the VM"
+ " cleanup job.", vol, vmInstanceVO.getState());
Expand Down
Loading