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:29:14 UTC

git commit: updated refs/heads/4.3 to 96823d3

Updated Branches:
  refs/heads/4.3 69cb7de34 -> 96823d3a6


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/96823d3a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/96823d3a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/96823d3a

Branch: refs/heads/4.3
Commit: 96823d3a629bdb8318072b2932c3a74824f54fac
Parents: 69cb7de
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 15:48:23 2014 +0530

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


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/96823d3a/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 70fca7b..40ae606 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -317,18 +317,10 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
                         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);
         }
 
@@ -423,6 +415,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);
@@ -433,8 +426,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
                             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) {
@@ -618,12 +610,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
@@ -957,18 +949,15 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
                         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;
@@ -1074,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";
@@ -1115,13 +1100,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;
     }