mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Cleanup volume information from db when deleted (#4551)
* Cleanup volume information from db when deleted * reuse search builder * revert change Co-authored-by: Pearl Dsilva <pearl.dsilva@shapeblue.com>
This commit is contained in:
parent
949cf71491
commit
ea7d3b34d1
@ -55,4 +55,6 @@ public interface VolumeDataStoreDao extends GenericDao<VolumeDataStoreVO, Long>,
|
|||||||
boolean updateVolumeId(long srcVolId, long destVolId);
|
boolean updateVolumeId(long srcVolId, long destVolId);
|
||||||
|
|
||||||
List<VolumeDataStoreVO> listVolumeDownloadUrlsByZoneId(long zoneId);
|
List<VolumeDataStoreVO> listVolumeDownloadUrlsByZoneId(long zoneId);
|
||||||
|
|
||||||
|
List<VolumeDataStoreVO> listByVolume(long volumeId, long storeId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
package org.apache.cloudstack.storage.motion;
|
package org.apache.cloudstack.storage.motion;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -44,6 +45,8 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
|||||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||||
import org.apache.cloudstack.storage.RemoteHostEndPoint;
|
import org.apache.cloudstack.storage.RemoteHostEndPoint;
|
||||||
import org.apache.cloudstack.storage.command.CopyCommand;
|
import org.apache.cloudstack.storage.command.CopyCommand;
|
||||||
|
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
|
||||||
|
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||||
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
|
import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
|
||||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@ -85,6 +88,8 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
DataStoreManager dataStoreMgr;
|
DataStoreManager dataStoreMgr;
|
||||||
@Inject
|
@Inject
|
||||||
StorageCacheManager cacheMgr;
|
StorageCacheManager cacheMgr;
|
||||||
|
@Inject
|
||||||
|
VolumeDataStoreDao volumeDataStoreDao;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
StorageManager storageManager;
|
StorageManager storageManager;
|
||||||
@ -324,6 +329,15 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteVolumeOnSecondaryStore(DataObject objectInStore) {
|
||||||
|
ImageStoreEntity store = (ImageStoreEntity) objectInStore.getDataStore();
|
||||||
|
store.delete(objectInStore);
|
||||||
|
List<VolumeDataStoreVO> volumesOnStore = volumeDataStoreDao.listByVolume(objectInStore.getId(), store.getId());
|
||||||
|
for (VolumeDataStoreVO volume : volumesOnStore) {
|
||||||
|
volumeDataStoreDao.remove(volume.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) {
|
protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) {
|
||||||
String value = configDao.getValue(Config.CopyVolumeWait.key());
|
String value = configDao.getValue(Config.CopyVolumeWait.key());
|
||||||
int _copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
|
int _copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
|
||||||
@ -359,10 +373,9 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DataObject objOnImageStore = imageStore.create(srcData);
|
DataObject objOnImageStore = imageStore.create(srcData);
|
||||||
objOnImageStore.processEvent(Event.CreateOnlyRequested);
|
|
||||||
|
|
||||||
Answer answer = null;
|
Answer answer = null;
|
||||||
try {
|
try {
|
||||||
|
objOnImageStore.processEvent(Event.CreateOnlyRequested);
|
||||||
answer = copyObject(srcData, objOnImageStore);
|
answer = copyObject(srcData, objOnImageStore);
|
||||||
|
|
||||||
if (answer == null || !answer.getResult()) {
|
if (answer == null || !answer.getResult()) {
|
||||||
@ -401,11 +414,12 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
objOnImageStore.processEvent(Event.OperationFailed);
|
objOnImageStore.processEvent(Event.OperationFailed);
|
||||||
imageStore.delete(objOnImageStore);
|
imageStore.delete(objOnImageStore);
|
||||||
}
|
}
|
||||||
|
s_logger.error("Failed to perform operation: "+ e.getLocalizedMessage());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
objOnImageStore.processEvent(Event.OperationSuccessed);
|
objOnImageStore.processEvent(Event.OperationSuccessed);
|
||||||
imageStore.delete(objOnImageStore);
|
deleteVolumeOnSecondaryStore(objOnImageStore);
|
||||||
return answer;
|
return answer;
|
||||||
} else {
|
} else {
|
||||||
DataObject cacheData = cacheMgr.createCacheObject(srcData, destScope);
|
DataObject cacheData = cacheMgr.createCacheObject(srcData, destScope);
|
||||||
|
|||||||
@ -62,7 +62,6 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
|
|||||||
private SearchBuilder<VolumeDataStoreVO> uploadVolumeStateSearch;
|
private SearchBuilder<VolumeDataStoreVO> uploadVolumeStateSearch;
|
||||||
private static final String EXPIRE_DOWNLOAD_URLS_FOR_ZONE = "update volume_store_ref set download_url_created=? where download_url_created is not null and store_id in (select id from image_store where data_center_id=?)";
|
private static final String EXPIRE_DOWNLOAD_URLS_FOR_ZONE = "update volume_store_ref set download_url_created=? where download_url_created is not null and store_id in (select id from image_store where data_center_id=?)";
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DataStoreManager storeMgr;
|
DataStoreManager storeMgr;
|
||||||
@Inject
|
@Inject
|
||||||
@ -119,7 +118,6 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
|
|||||||
uploadVolumeStateSearch.join("volumeOnlySearch", volumeOnlySearch, volumeOnlySearch.entity().getId(), uploadVolumeStateSearch.entity().getVolumeId(), JoinType.LEFT);
|
uploadVolumeStateSearch.join("volumeOnlySearch", volumeOnlySearch, volumeOnlySearch.entity().getId(), uploadVolumeStateSearch.entity().getVolumeId(), JoinType.LEFT);
|
||||||
uploadVolumeStateSearch.and("destroyed", uploadVolumeStateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
|
uploadVolumeStateSearch.and("destroyed", uploadVolumeStateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
|
||||||
uploadVolumeStateSearch.done();
|
uploadVolumeStateSearch.done();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,6 +330,15 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
|
|||||||
return listBy(sc);
|
return listBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<VolumeDataStoreVO> listByVolume(long volumeId, long storeId) {
|
||||||
|
SearchCriteria<VolumeDataStoreVO> sc = storeVolumeSearch.create();
|
||||||
|
sc.setParameters("store_id", storeId);
|
||||||
|
sc.setParameters("volume_id", volumeId);
|
||||||
|
sc.setParameters("destroyed", false);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VolumeDataStoreVO> listUploadedVolumesByStoreId(long id) {
|
public List<VolumeDataStoreVO> listUploadedVolumesByStoreId(long id) {
|
||||||
SearchCriteria<VolumeDataStoreVO> sc = uploadVolumeSearch.create();
|
SearchCriteria<VolumeDataStoreVO> sc = uploadVolumeSearch.create();
|
||||||
@ -340,7 +347,6 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
|
|||||||
return listIncludingRemovedBy(sc);
|
return listIncludingRemovedBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void expireDnldUrlsForZone(Long dcId){
|
public void expireDnldUrlsForZone(Long dcId){
|
||||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||||
|
|||||||
@ -1585,6 +1585,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||||||
for (DataStore store : imageStores) {
|
for (DataStore store : imageStores) {
|
||||||
try {
|
try {
|
||||||
List<VolumeDataStoreVO> destroyedStoreVOs = _volumeStoreDao.listDestroyed(store.getId());
|
List<VolumeDataStoreVO> destroyedStoreVOs = _volumeStoreDao.listDestroyed(store.getId());
|
||||||
|
destroyedStoreVOs.addAll(_volumeDataStoreDao.listByVolumeState(Volume.State.Expunged));
|
||||||
s_logger.debug("Secondary storage garbage collector found " + destroyedStoreVOs.size() + " volumes to cleanup on volume_store_ref for store: " + store.getName());
|
s_logger.debug("Secondary storage garbage collector found " + destroyedStoreVOs.size() + " volumes to cleanup on volume_store_ref for store: " + store.getName());
|
||||||
for (VolumeDataStoreVO destroyedStoreVO : destroyedStoreVOs) {
|
for (VolumeDataStoreVO destroyedStoreVO : destroyedStoreVOs) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user