|
27 | 27 | import java.util.Collections; |
28 | 28 | import java.util.Date; |
29 | 29 | import java.util.HashMap; |
| 30 | +import java.util.HashSet; |
30 | 31 | import java.util.Iterator; |
31 | 32 | import java.util.List; |
32 | 33 | import java.util.Map; |
@@ -2253,27 +2254,41 @@ public void cleanupDownloadUrls(){ |
2253 | 2254 |
|
2254 | 2255 | // Cleanup expired volume URLs |
2255 | 2256 | List<VolumeDataStoreVO> volumesOnImageStoreList = _volumeStoreDao.listVolumeDownloadUrls(); |
| 2257 | + HashSet<Long> expiredVolumeIds = new HashSet<Long>(); |
| 2258 | + HashSet<Long> activeVolumeIds = new HashSet<Long>(); |
2256 | 2259 | for(VolumeDataStoreVO volumeOnImageStore : volumesOnImageStoreList){ |
2257 | 2260 |
|
| 2261 | + long volumeId = volumeOnImageStore.getVolumeId(); |
2258 | 2262 | try { |
2259 | 2263 | long downloadUrlCurrentAgeInSecs = DateUtil.getTimeDifference(DateUtil.now(), volumeOnImageStore.getExtractUrlCreated()); |
2260 | 2264 | if(downloadUrlCurrentAgeInSecs < _downloadUrlExpirationInterval){ // URL hasnt expired yet |
| 2265 | + activeVolumeIds.add(volumeId); |
2261 | 2266 | continue; |
2262 | 2267 | } |
2263 | | - |
2264 | | - s_logger.debug("Removing download url " + volumeOnImageStore.getExtractUrl() + " for volume id " + volumeOnImageStore.getVolumeId()); |
| 2268 | + expiredVolumeIds.add(volumeId); |
| 2269 | + s_logger.debug("Removing download url " + volumeOnImageStore.getExtractUrl() + " for volume id " + volumeId); |
2265 | 2270 |
|
2266 | 2271 | // Remove it from image store |
2267 | 2272 | ImageStoreEntity secStore = (ImageStoreEntity) _dataStoreMgr.getDataStore(volumeOnImageStore.getDataStoreId(), DataStoreRole.Image); |
2268 | 2273 | secStore.deleteExtractUrl(volumeOnImageStore.getInstallPath(), volumeOnImageStore.getExtractUrl(), Upload.Type.VOLUME); |
2269 | 2274 |
|
2270 | | - // Now expunge it from DB since this entry was created only for download purpose |
| 2275 | + // Now expunge it from DB since this entry was created only for download purpose |
2271 | 2276 | _volumeStoreDao.expunge(volumeOnImageStore.getId()); |
2272 | 2277 | }catch(Throwable th){ |
2273 | 2278 | s_logger.warn("Caught exception while deleting download url " +volumeOnImageStore.getExtractUrl() + |
2274 | 2279 | " for volume id " + volumeOnImageStore.getVolumeId(), th); |
2275 | 2280 | } |
2276 | 2281 | } |
| 2282 | + for(Long volumeId : expiredVolumeIds) |
| 2283 | + { |
| 2284 | + if(activeVolumeIds.contains(volumeId)) { |
| 2285 | + continue; |
| 2286 | + } |
| 2287 | + Volume volume = _volumeDao.findById(volumeId); |
| 2288 | + if (volume != null && volume.getState() == Volume.State.Expunged) { |
| 2289 | + _volumeDao.remove(volumeId); |
| 2290 | + } |
| 2291 | + } |
2277 | 2292 |
|
2278 | 2293 | // Cleanup expired template URLs |
2279 | 2294 | List<TemplateDataStoreVO> templatesOnImageStoreList = _templateStoreDao.listTemplateDownloadUrls(); |
|
0 commit comments