Updated Branches:
  refs/heads/master 178953e96 -> 7e093a949

CS-15823 Failed snapshot should be marked as Error and cleanup asynchronously


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

Branch: refs/heads/master
Commit: 7e093a949d2445d320b1fba330ad802dc14db1b8
Parents: 178953e
Author: Mice Xia <[email protected]>
Authored: Wed Aug 15 11:06:25 2012 +0800
Committer: Mice Xia <[email protected]>
Committed: Wed Aug 15 11:06:25 2012 +0800

----------------------------------------------------------------------
 .../src/com/cloud/storage/StorageManagerImpl.java  |   11 +++++++++++
 server/src/com/cloud/storage/dao/SnapshotDao.java  |    1 +
 .../src/com/cloud/storage/dao/SnapshotDaoImpl.java |    7 +++++++
 .../storage/snapshot/SnapshotManagerImpl.java      |    9 ++-------
 4 files changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7e093a94/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java 
b/server/src/com/cloud/storage/StorageManagerImpl.java
index 20dde8b..3fe4605 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -2260,6 +2260,17 @@ public class StorageManagerImpl implements 
StorageManager, Manager, ClusterManag
                             s_logger.warn("Unable to destroy " + vol.getId(), 
e);
                         }
                     }
+                    
+                    // remove snapshots in Error state
+                    List<SnapshotVO> snapshots = 
_snapshotDao.listAllByStatus(Snapshot.Status.Error);
+                    for (SnapshotVO snapshotVO : snapshots) {
+                        try{
+                            _snapshotDao.expunge(snapshotVO.getId());
+                        }catch (Exception e) {
+                            s_logger.warn("Unable to destroy " + 
snapshotVO.getId(), e);
+                        }
+                    }
+                    
                 } finally {
                     scanLock.unlock();
                 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7e093a94/server/src/com/cloud/storage/dao/SnapshotDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/SnapshotDao.java 
b/server/src/com/cloud/storage/dao/SnapshotDao.java
index 4bf54de..b32d278 100644
--- a/server/src/com/cloud/storage/dao/SnapshotDao.java
+++ b/server/src/com/cloud/storage/dao/SnapshotDao.java
@@ -41,4 +41,5 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, 
Long> {
     public Long countSnapshotsForAccount(long accountId);
        List<SnapshotVO> listByInstanceId(long instanceId, Snapshot.Status... 
status);
        List<SnapshotVO> listByStatus(long volumeId, Snapshot.Status... status);
+    List<SnapshotVO> listAllByStatus(Snapshot.Status... status);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7e093a94/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java 
b/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
index ac4bb6f..65e2f5f 100644
--- a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
+++ b/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
@@ -307,4 +307,11 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
         txn.commit();
         return result;
     }
+    
+    @Override
+    public List<SnapshotVO> listAllByStatus(Snapshot.Status... status) {
+        SearchCriteria<SnapshotVO> sc = this.StatusSearch.create();
+        sc.setParameters("status", (Object[])status);
+        return listBy(sc, null);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7e093a94/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 6e3f9c1..2f0c640 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -372,9 +372,6 @@ public class SnapshotManagerImpl implements 
SnapshotManager, SnapshotService, Ma
             if (answer != null) {
                 s_logger.error(answer.getDetails());
             }
-
-            // delete from the snapshots table
-            _snapshotDao.expunge(snapshotId);
             throw new CloudRuntimeException("Creating snapshot for volume " + 
volumeId + " on primary storage failed.");
         }
 
@@ -424,7 +421,6 @@ public class SnapshotManagerImpl implements 
SnapshotManager, SnapshotService, Ma
                 if (hosts != null && !hosts.isEmpty()) {
                     HostVO host = hosts.get(0);
                     if (!hostSupportSnapsthot(host)) {
-                        _snapshotDao.expunge(snapshotId);
                         throw new CloudRuntimeException("KVM Snapshot is not 
supported on cluster: " + host.getId());
                     }
                 }
@@ -435,14 +431,13 @@ public class SnapshotManagerImpl implements 
SnapshotManager, SnapshotService, Ma
                 UserVmVO userVm = _vmDao.findById(volume.getInstanceId());
                 if (userVm != null) {
                     if (userVm.getState().equals(State.Destroyed) || 
userVm.getState().equals(State.Expunging)) {
-                        _snapshotDao.expunge(snapshotId);
                         throw new CloudRuntimeException("Creating snapshot 
failed due to volume:" + volumeId + " is associated with vm:" + 
userVm.getInstanceName() + " is in "
                                 + userVm.getState().toString() + " state");
                     }
                     
                     if(userVm.getHypervisorType() == HypervisorType.VMware || 
userVm.getHypervisorType() == HypervisorType.KVM) {
-                       List<SnapshotVO> activeSnapshots = 
_snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.Status.Creating, 
 Snapshot.Status.CreatedOnPrimary,  Snapshot.Status.BackingUp);
-                       if(activeSnapshots.size() > 1)
+                        List<SnapshotVO> activeSnapshots = 
_snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.Status.Creating, 
 Snapshot.Status.CreatedOnPrimary,  Snapshot.Status.BackingUp);
+                        if(activeSnapshots.size() > 1)
                             throw new CloudRuntimeException("There is other 
active snapshot tasks on the instance to which the volume is attached, please 
try again later");
                     }
                 }

Reply via email to