mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-9560 Root volume of deleted VM left unremoved
(cherry picked from commit 5568ee93ad08f998822dc0428e511dc8e8609014) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
26bcb9afd8
commit
b70879cbac
@ -27,6 +27,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -2253,15 +2254,19 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
|
||||
// Cleanup expired volume URLs
|
||||
List<VolumeDataStoreVO> volumesOnImageStoreList = _volumeStoreDao.listVolumeDownloadUrls();
|
||||
HashSet<Long> expiredVolumeIds = new HashSet<Long>();
|
||||
HashSet<Long> activeVolumeIds = new HashSet<Long>();
|
||||
for(VolumeDataStoreVO volumeOnImageStore : volumesOnImageStoreList){
|
||||
|
||||
long volumeId = volumeOnImageStore.getVolumeId();
|
||||
try {
|
||||
long downloadUrlCurrentAgeInSecs = DateUtil.getTimeDifference(DateUtil.now(), volumeOnImageStore.getExtractUrlCreated());
|
||||
if(downloadUrlCurrentAgeInSecs < _downloadUrlExpirationInterval){ // URL hasnt expired yet
|
||||
activeVolumeIds.add(volumeId);
|
||||
continue;
|
||||
}
|
||||
|
||||
s_logger.debug("Removing download url " + volumeOnImageStore.getExtractUrl() + " for volume id " + volumeOnImageStore.getVolumeId());
|
||||
expiredVolumeIds.add(volumeId);
|
||||
s_logger.debug("Removing download url " + volumeOnImageStore.getExtractUrl() + " for volume id " + volumeId);
|
||||
|
||||
// Remove it from image store
|
||||
ImageStoreEntity secStore = (ImageStoreEntity) _dataStoreMgr.getDataStore(volumeOnImageStore.getDataStoreId(), DataStoreRole.Image);
|
||||
@ -2274,6 +2279,16 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
" for volume id " + volumeOnImageStore.getVolumeId(), th);
|
||||
}
|
||||
}
|
||||
for(Long volumeId : expiredVolumeIds)
|
||||
{
|
||||
if(activeVolumeIds.contains(volumeId)) {
|
||||
continue;
|
||||
}
|
||||
Volume volume = _volumeDao.findById(volumeId);
|
||||
if (volume != null && volume.getState() == Volume.State.Expunged) {
|
||||
_volumeDao.remove(volumeId);
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup expired template URLs
|
||||
List<TemplateDataStoreVO> templatesOnImageStoreList = _templateStoreDao.listTemplateDownloadUrls();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user