CLOUDSTACK-9685: delete snapshot on primary associated with a volume when that volume is deleted

as that snapshot will never be going to use again and also it will fill up primary storage

(cherry picked from commit 336df84f17)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Anshul Gangwar 2016-12-20 15:17:08 +05:30 committed by Rohit Yadav
parent 765ab549ca
commit e6855db78a
3 changed files with 13 additions and 2 deletions

View File

@ -130,7 +130,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
SnapshotDataStoreVO oldestSnapshotOnPrimary = snapshotStoreDao.findOldestSnapshotForVolume(snapshot.getVolumeId(), DataStoreRole.Primary);
VolumeVO volume = volumeDao.findById(snapshot.getVolumeId());
if (oldestSnapshotOnPrimary != null) {
if (oldestSnapshotOnPrimary.getDataStoreId() == volume.getPoolId()) {
if (oldestSnapshotOnPrimary.getDataStoreId() == volume.getPoolId() && oldestSnapshotOnPrimary.getId() != parentSnapshotOnPrimaryStore.getId()) {
int _deltaSnapshotMax = NumbersUtil.parseInt(configDao.getValue("snapshot.delta.max"),
SnapshotManager.DELTAMAX);
int deltaSnap = _deltaSnapshotMax;
@ -152,7 +152,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
} else {
fullBackup = false;
}
} else {
} else if (oldestSnapshotOnPrimary.getId() != parentSnapshotOnPrimaryStore.getId()){
// if there is an snapshot entry for previousPool(primary storage) of migrated volume, delete it becasue CS created one more snapshot entry for current pool
snapshotStoreDao.remove(oldestSnapshotOnPrimary.getId());
}

View File

@ -68,6 +68,8 @@ import org.apache.cloudstack.storage.command.CopyCmdAnswer;
import org.apache.cloudstack.storage.command.DeleteCommand;
import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
import org.apache.cloudstack.storage.image.store.TemplateObject;
@ -141,6 +143,8 @@ public class VolumeServiceImpl implements VolumeService {
@Inject
VMTemplatePoolDao _tmpltPoolDao;
@Inject
SnapshotDataStoreDao _snapshotStoreDao;
@Inject
VolumeDao _volumeDao;
@Inject
EndPointSelector _epSelector;
@ -359,6 +363,10 @@ public class VolumeServiceImpl implements VolumeService {
s_logger.info("Volume " + vo.getId() + " is not referred anywhere, remove it from volumes table");
volDao.remove(vo.getId());
}
SnapshotDataStoreVO snapStoreVo = _snapshotStoreDao.findByVolume(vo.getId(), DataStoreRole.Primary);
if(snapStoreVo != null){
_snapshotStoreDao.remove(snapStoreVo.getId());
}
} else {
vo.processEvent(Event.OperationFailed);
apiResult.setResult(result.getResult());

View File

@ -561,6 +561,9 @@ public class XenServerStorageProcessor implements StorageProcessor {
String errorMsg = null;
try {
final VDI vdi = VDI.getByUuid(conn, volume.getPath());
for(VDI svdi : vdi.getSnapshots(conn)) {
deleteVDI(conn, svdi);
}
deleteVDI(conn, vdi);
return new Answer(null);
} catch (final BadServerResponse e) {