Bug 9548 [Cloud Stack Upgrade - 2.1.8 to 2.2.4] System VM's Volumes Recreation is not happening on an event of New Volume creation Failures

Changes:
- Reason was that the old volume's templateId was being updated before volume creation was attempted. So on the retry, we dint find a difference in volume's templateId and VM's templateId and did not enter the recreation logic.

- Fix is to update the new volume's templateId with the VM's templateId while creating the new volume. The old volume's templateId stays the same and the volume is marked as 'Destroy' when a new volume is created.
This commit is contained in:
prachi 2011-04-26 11:35:24 -07:00
parent 5db28c57e4
commit 6e39019b6a
2 changed files with 20 additions and 8 deletions

View File

@ -326,9 +326,13 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
return true;
}
VolumeVO allocateDuplicateVolume(VolumeVO oldVol) {
VolumeVO allocateDuplicateVolume(VolumeVO oldVol, Long templateId) {
VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(), oldVol.getName(), oldVol.getDataCenterId(), oldVol.getDomainId(), oldVol.getAccountId(), oldVol.getDiskOfferingId(), oldVol.getSize());
newVol.setTemplateId(oldVol.getTemplateId());
if(templateId != null){
newVol.setTemplateId(templateId);
}else{
newVol.setTemplateId(oldVol.getTemplateId());
}
newVol.setDeviceId(oldVol.getDeviceId());
newVol.setInstanceId(oldVol.getInstanceId());
return _volsDao.persist(newVol);
@ -2548,7 +2552,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
vol.setRecreatable(true);
newVol = vol;
} else {
newVol = switchVolume(vol);
newVol = switchVolume(vol, vm);
newVol.setRecreatable(true);
// update the volume->storagePool map since volumeId has changed
if (dest.getStorageForDisks() != null && dest.getStorageForDisks().containsKey(vol)) {
@ -2597,12 +2601,22 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
@DB
protected VolumeVO switchVolume(VolumeVO existingVolume) throws StorageUnavailableException {
protected VolumeVO switchVolume(VolumeVO existingVolume, VirtualMachineProfile<? extends VirtualMachine> vm) throws StorageUnavailableException {
Transaction txn = Transaction.currentTxn();
try {
txn.start();
_volsDao.update(existingVolume, Volume.Event.Destroy);
VolumeVO newVolume = allocateDuplicateVolume(existingVolume);
Long templateIdToUse = null;
Long volTemplateId = existingVolume.getTemplateId();
long vmTemplateId = vm.getTemplateId();
if (volTemplateId != null && volTemplateId.longValue() != vmTemplateId) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("switchVolume: Old Volume's templateId: "+volTemplateId + " does not match the VM's templateId: "+vmTemplateId+", updating templateId in the new Volume");
}
templateIdToUse = vmTemplateId;
}
VolumeVO newVolume = allocateDuplicateVolume(existingVolume, templateIdToUse);
txn.commit();
return newVolume;
} catch (ConcurrentOperationException e) {

View File

@ -598,10 +598,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
if (volTemplateId.longValue() != template.getId()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Root Volume " + vol + " of " + vm.getType().toString()
+ " System VM is ready, but volume's templateId does not match the System VM Template, updating templateId and reassigning a new pool");
+ " System VM is ready, but volume's templateId does not match the System VM Template, let the planner reassign a new pool");
}
vol.setTemplateId(template.getId());
_volsDao.update(vol.getId(), vol);
continue;
}
}