bug 10512: lock on snapshot entry instead of volume entry

status 10512: resolved fixed
This commit is contained in:
anthony 2011-06-29 18:53:41 -07:00
parent ed614c4f52
commit b6eafd7102
2 changed files with 17 additions and 7 deletions

View File

@ -627,8 +627,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
Long templateId = template.getId();
Long tmpltAccountId = template.getAccountId();
if (!_volsDao.lockInLockTable(volumeId.toString(), 10)) {
throw new CloudRuntimeException("failed to upgrade snapshot " + snapshotId + " due to volume:" + volumeId + " is being used, try it later ");
if (!_snapshotDao.lockInLockTable(snapshotId.toString(), 10)) {
throw new CloudRuntimeException("failed to upgrade snapshot " + snapshotId + " due to this snapshot is being used, try it later ");
}
UpgradeSnapshotCommand cmd = new UpgradeSnapshotCommand(null, secondaryStoragePoolUrl, dcId, accountId, volumeId, templateId, tmpltAccountId, null, snapshot.getBackupSnapshotId(),
snapshot.getName(), "2.1");
@ -637,7 +637,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
answer = sendToPool(pool, cmd);
} catch (StorageUnavailableException e) {
} finally {
_volsDao.unlockFromLockTable(volumeId.toString());
_snapshotDao.unlockFromLockTable(snapshotId.toString());
}
if ((answer != null) && answer.getResult()) {
_snapshotDao.updateSnapshotVersion(volumeId, "2.1", "2.2");
@ -655,7 +655,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
String basicErrMsg = "Failed to create volume from " + snapshot.getName();
CreateVolumeFromSnapshotAnswer answer;
if (!_snapshotDao.lockInLockTable(snapshotId.toString(), 10)) {
throw new CloudRuntimeException("failed to create volume from " + snapshotId + " due to original volume:" + volumeId + " is being used, try it later ");
throw new CloudRuntimeException("failed to create volume from " + snapshotId + " due to this snapshot is being used, try it later ");
}
try {
answer = (CreateVolumeFromSnapshotAnswer) sendToPool(pool, createVolumeFromSnapshotCommand);

View File

@ -1545,14 +1545,24 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
// This can be sent to a KVM host too.
CreatePrivateTemplateAnswer answer = null;
if (!_volsDao.lockInLockTable(volumeId.toString(), 10)) {
throw new CloudRuntimeException("Creating template failed due to volume:" + volumeId + " is being used, try it later ");
if (snapshotId != null) {
if (!_snapshotDao.lockInLockTable(snapshotId.toString(), 10)) {
throw new CloudRuntimeException("Creating template from snapshot failed due to snapshot:" + snapshotId + " is being used, try it later ");
}
} else {
if (!_volsDao.lockInLockTable(volumeId.toString(), 10)) {
throw new CloudRuntimeException("Creating template from volume failed due to volume:" + volumeId + " is being used, try it later ");
}
}
try {
answer = (CreatePrivateTemplateAnswer) _storageMgr.sendToPool(pool, cmd);
} catch (StorageUnavailableException e) {
} finally {
_volsDao.unlockFromLockTable(volumeId.toString());
if (snapshotId != null) {
_snapshotDao.unlockFromLockTable(snapshotId.toString());
} else {
_volsDao.unlockFromLockTable(volumeId.toString());
}
}
if ((answer != null) && answer.getResult()) {
privateTemplate = _templateDao.findById(templateId);