From 414081154942ff03bd4b73dd834eeec559608799 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Wed, 12 Nov 2014 12:07:49 -0800 Subject: [PATCH] CLOUDSTACK-7947: double check if parent snapshot is removed or not, when creating new snapshot Reviewed-by: Min --- .../storage/snapshot/XenserverSnapshotStrategy.java | 4 ++++ .../storage/datastore/ObjectInDataStoreManagerImpl.java | 9 ++++++++- .../com/cloud/storage/snapshot/SnapshotManagerImpl.java | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) 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 8d6886ebfb9..90efcde999c 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 storeRefs = snapshotStoreDao.findBySnapshotId(snapshotId); + for (SnapshotDataStoreVO ref : storeRefs) { + snapshotStoreDao.expunge(ref.getId()); + } snapshotDao.remove(snapshotId); return true; } 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 fbce8609e6d..fa91e4f63bb 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; @@ -119,7 +120,13 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { ss.setPhysicalSize(snapshotInfo.getSize()); // this physical size will get updated with actual size once the snapshot backup is done. 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); diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index bcb22421b90..04a04891689 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -26,7 +26,6 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.cloudstack.api.command.user.snapshot.UpdateSnapshotPolicyCmd; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -34,6 +33,7 @@ import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotPolicyCmd; import org.apache.cloudstack.api.command.user.snapshot.DeleteSnapshotPoliciesCmd; import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd; import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd; +import org.apache.cloudstack.api.command.user.snapshot.UpdateSnapshotPolicyCmd; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; @@ -1148,4 +1148,6 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, return snapshot; } + + }