You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by sa...@apache.org on 2014/01/06 11:46:02 UTC

git commit: updated refs/heads/master to 1069f56

Updated Branches:
  refs/heads/master 62c934365 -> 1069f56f8


CLOUDSTACK-5406: Not able to take snapshot becasue of secondary_storage limit of 400 gb exceeded even though we have not really consumed this limit in secondary store.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1069f56f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1069f56f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1069f56f

Branch: refs/heads/master
Commit: 1069f56f8e6ab22f1dd63f00e7cfe7c7d71be8bf
Parents: 62c9343
Author: Sanjay Tripathi <sa...@citrix.com>
Authored: Mon Jan 6 15:39:06 2014 +0530
Committer: Sanjay Tripathi <sa...@citrix.com>
Committed: Mon Jan 6 16:09:09 2014 +0530

----------------------------------------------------------------------
 .../storage/snapshot/SnapshotManagerImpl.java   | 33 ++++++--------------
 1 file changed, 10 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1069f56f/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index c19e3ec..998a941 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -322,16 +322,10 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
                 UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, snapshot.getName(),
                     null, null, volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid());
             }
-
             _resourceLimitMgr.incrementResourceCount(snapshotOwner.getId(), ResourceType.snapshot);
 
         } catch (Exception e) {
             s_logger.debug("Failed to create snapshot", e);
-            if (backup) {
-                _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize()));
-            } else {
-                _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.primary_storage, new Long(volume.getSize()));
-            }
             throw new CloudRuntimeException("Failed to create snapshot", e);
         }
 
@@ -427,6 +421,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
             s_logger.error("Unable to find snaphot strategy to handle snapshot with id '" + snapshotId + "'");
             return false;
         }
+        SnapshotDataStoreVO snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Image);
 
         try {
             boolean result = snapshotStrategy.deleteSnapshot(snapshotId);
@@ -436,7 +431,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
                         snapshotCheck.getName(), null, null, 0L, snapshotCheck.getClass().getName(), snapshotCheck.getUuid());
                 }
                 _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.snapshot);
-                _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.secondary_storage, new Long(snapshotCheck.getSize()));
+                _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.secondary_storage, new Long(snapshotStoreRef.getSize()));
             }
             return result;
         } catch (Exception e) {
@@ -621,11 +616,12 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
                     s_logger.error("Unable to find snaphot strategy to handle snapshot with id '" + snapshot.getId() + "'");
                     continue;
                 }
+                SnapshotDataStoreVO snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Image);
 
                 if (snapshotStrategy.deleteSnapshot(snapshot.getId())) {
                     if (snapshot.getRecurringType() == Type.MANUAL) {
                         _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.snapshot);
-                        _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.secondary_storage, new Long(snapshot.getSize()));
+                        _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.secondary_storage, new Long(snapshotStoreRef.getSize()));
                     }
 
                     // Log event after successful deletion
@@ -954,16 +950,15 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
                 UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, snapshot.getName(),
                     null, null, volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid());
                 _resourceLimitMgr.incrementResourceCount(snapshotOwner.getId(), ResourceType.snapshot);
+                SnapshotDataStoreVO snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Image);
+                // Correct the resource count of snapshot in case of delta snapshots.
+                _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize() - snapshotStoreRef.getSize()));
             } catch (Exception e) {
                 s_logger.debug("post process snapshot failed", e);
             }
         } catch (Exception e) {
             s_logger.debug("Failed to create snapshot", e);
-            if (backup) {
-                _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize()));
-            } else {
-                _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.primary_storage, new Long(volume.getSize()));
-            }
+            _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize()));
             throw new CloudRuntimeException("Failed to create snapshot", e);
         }
         return snapshot;
@@ -1068,11 +1063,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
 
         try {
             _resourceLimitMgr.checkResourceLimit(owner, ResourceType.snapshot);
-            if (backup) {
-                _resourceLimitMgr.checkResourceLimit(owner, ResourceType.secondary_storage, new Long(volume.getSize()));
-            } else {
-                _resourceLimitMgr.checkResourceLimit(owner, ResourceType.primary_storage, new Long(volume.getSize()));
-            }
+            _resourceLimitMgr.checkResourceLimit(owner, ResourceType.secondary_storage, new Long(volume.getSize()));
         } catch (ResourceAllocationException e) {
             if (snapshotType != Type.MANUAL) {
                 String msg = "Snapshot resource limit exceeded for account id : " + owner.getId() + ". Failed to create recurring snapshots";
@@ -1111,11 +1102,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
         if (snapshot == null) {
             throw new CloudRuntimeException("Failed to create snapshot for volume: " + volume.getId());
         }
-        if (backup) {
-            _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, new Long(volume.getSize()));
-        } else {
-            _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, new Long(volume.getSize()));
-        }
+        _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, new Long(volume.getSize()));
         return snapshot;
     }