Repository: cloudstack
Updated Branches:
  refs/heads/4.4 86c425ec8 -> 0e312a7a7


CLOUDSTACK-7301, CLOUDSTACK-7947: double check if parent snapshot is removed or 
not

when creating new snapshot, check if parent snapshot is removed or not

Reviewed-by: Min
(cherry picked from commit bd799653293f9dc257ab68a3b04f6ea769e08e36)
Signed-off-by: Rohit Yadav <[email protected]>

Conflicts:
        
engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java

(cherry picked from commit ebf9897293a826d068b57c49c273bf4b9fd7f72e)
Signed-off-by: Rohit Yadav <[email protected]>

Conflicts:
        
engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java


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

Branch: refs/heads/4.4
Commit: 0e312a7a779424519166d5bc2812672bbf7474a4
Parents: 86c425e
Author: Edison Su <[email protected]>
Authored: Wed Nov 12 12:07:49 2014 -0800
Committer: Rohit Yadav <[email protected]>
Committed: Thu Dec 18 18:27:56 2014 +0530

----------------------------------------------------------------------
 .../storage/snapshot/XenserverSnapshotStrategy.java         | 4 ++++
 .../storage/datastore/ObjectInDataStoreManagerImpl.java     | 9 ++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0e312a7a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
index 8d6886e..90efcde 100644
--- 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
+++ 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
@@ -198,6 +198,10 @@ public class XenserverSnapshotStrategy extends 
SnapshotStrategyBase {
         }
 
         if (Snapshot.State.Error.equals(snapshotVO.getState())) {
+            List<SnapshotDataStoreVO> storeRefs = 
snapshotStoreDao.findBySnapshotId(snapshotId);
+            for (SnapshotDataStoreVO ref : storeRefs) {
+                snapshotStoreDao.expunge(ref.getId());
+            }
             snapshotDao.remove(snapshotId);
             return true;
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0e312a7a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
 
b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
index 82164ee..008d625 100644
--- 
a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
+++ 
b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
@@ -45,6 +45,7 @@ import com.cloud.agent.api.to.DataObjectType;
 import com.cloud.agent.api.to.S3TO;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.SnapshotVO;
 import com.cloud.storage.VMTemplateStoragePoolVO;
 import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.VMTemplateDao;
@@ -118,7 +119,13 @@ public class ObjectInDataStoreManagerImpl implements 
ObjectInDataStoreManager {
                 ss.setSize(snapshotInfo.getSize()); // this is the virtual 
size of snapshot in primary storage.
                 SnapshotDataStoreVO snapshotDataStoreVO = 
snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), 
snapshotInfo.getVolumeId());
                 if (snapshotDataStoreVO != null) {
-                    
ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
+                    //Double check the snapshot is removed or not
+                    SnapshotVO parentSnap = 
snapshotDao.findById(snapshotDataStoreVO.getSnapshotId());
+                    if (parentSnap != null) {
+                        
ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
+                    } else {
+                        s_logger.debug("find inconsistent db for snapshot " + 
snapshotDataStoreVO.getSnapshotId());
+                    }
                 }
                 ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
                 ss = snapshotDataStoreDao.persist(ss);

Reply via email to