From ebf9897293a826d068b57c49c273bf4b9fd7f72e Mon Sep 17 00:00:00 2001 From: Edison Su Date: Wed, 12 Nov 2014 12:07:49 -0800 Subject: [PATCH] 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 Conflicts: engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java --- .../storage/snapshot/XenserverSnapshotStrategy.java | 9 +++++++++ .../storage/datastore/ObjectInDataStoreManagerImpl.java | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) 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 adb24bda90f..35167ce0c81 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 @@ -202,6 +202,15 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase { return true; } + if (Snapshot.State.Error.equals(snapshotVO.getState())) { + List storeRefs = snapshotStoreDao.findBySnapshotId(snapshotId); + for (SnapshotDataStoreVO ref : storeRefs) { + snapshotStoreDao.expunge(ref.getId()); + } + snapshotDao.remove(snapshotId); + return true; + } + if (snapshotVO.getState() == Snapshot.State.CreatedOnPrimary) { s_logger.debug("delete snapshot on primary storage:"); snapshotVO.setState(Snapshot.State.Destroyed); 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 9d47ce674c7..c5ec63b6dd4 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java @@ -44,6 +44,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; @@ -117,7 +118,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);