From 0db879d053951f7ef52224284928b8946a9ceb6a Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 10 Feb 2011 20:11:45 -0800 Subject: [PATCH] reduce lock granularity --- .../storage/snapshot/SnapshotManagerImpl.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index df490b42ef2..cafafeabe19 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -344,19 +344,9 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma if (poolId == null) { throw new CloudRuntimeException("You cannot take a snapshot of a volume until it has been attached to an instance"); } - VolumeVO volume = _volsDao.acquireInLockTable(volumeId, 10); - if( volume == null ) { - _snapshotDao.expunge(snapshotId); - volume = _volsDao.findById(volumeId); - if( volume == null ){ - throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volumeId + " doesn't exist"); - } else { - throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volumeId + " is being used, try it later "); - } - } - if (_volsDao.getHypervisorType(volume.getId()).equals(HypervisorType.KVM)) { - StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId()); + if (_volsDao.getHypervisorType(v.getId()).equals(HypervisorType.KVM)) { + StoragePoolVO storagePool = _storagePoolDao.findById(v.getPoolId()); ClusterVO cluster = _clusterDao.findById(storagePool.getClusterId()); List hosts = _hostDao.listByCluster(cluster.getId()); if (hosts != null && !hosts.isEmpty()) { @@ -381,6 +371,16 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma SnapshotVO snapshot = null; boolean backedUp = false; + VolumeVO volume = _volsDao.acquireInLockTable(volumeId, 10); + if( volume == null ) { + _snapshotDao.expunge(snapshotId); + volume = _volsDao.findById(volumeId); + if( volume == null ){ + throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volumeId + " doesn't exist"); + } else { + throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volumeId + " is being used, try it later "); + } + } try { snapshot = createSnapshotOnPrimary(volume, policyId, snapshotId); if (snapshot != null && snapshot.getStatus() == Snapshot.Status.CreatedOnPrimary ) {