Repository: cloudstack Updated Branches: refs/heads/4.3 a15acb8e7 -> ebf989729
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 Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ebf98972 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ebf98972 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ebf98972 Branch: refs/heads/4.3 Commit: ebf9897293a826d068b57c49c273bf4b9fd7f72e Parents: a15acb8 Author: Edison Su <[email protected]> Authored: Wed Nov 12 12:07:49 2014 -0800 Committer: Rohit Yadav <[email protected]> Committed: Thu Dec 18 18:26:24 2014 +0530 ---------------------------------------------------------------------- .../storage/snapshot/XenserverSnapshotStrategy.java | 9 +++++++++ .../storage/datastore/ObjectInDataStoreManagerImpl.java | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ebf98972/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 adb24bd..35167ce 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<SnapshotDataStoreVO> 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); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ebf98972/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 9d47ce6..c5ec63b 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);
