Skip to content

Commit 4140811

Browse files
committed
CLOUDSTACK-7947:
double check if parent snapshot is removed or not, when creating new snapshot Reviewed-by: Min
1 parent 2ccecce commit 4140811

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ public boolean deleteSnapshot(Long snapshotId) {
198198
}
199199

200200
if (Snapshot.State.Error.equals(snapshotVO.getState())) {
201+
List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotId(snapshotId);
202+
for (SnapshotDataStoreVO ref : storeRefs) {
203+
snapshotStoreDao.expunge(ref.getId());
204+
}
201205
snapshotDao.remove(snapshotId);
202206
return true;
203207
}

‎engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.cloud.agent.api.to.S3TO;
4646
import com.cloud.exception.ConcurrentOperationException;
4747
import com.cloud.storage.DataStoreRole;
48+
import com.cloud.storage.SnapshotVO;
4849
import com.cloud.storage.VMTemplateStoragePoolVO;
4950
import com.cloud.storage.dao.SnapshotDao;
5051
import com.cloud.storage.dao.VMTemplateDao;
@@ -119,7 +120,13 @@ public DataObject create(DataObject obj, DataStore dataStore) {
119120
ss.setPhysicalSize(snapshotInfo.getSize()); // this physical size will get updated with actual size once the snapshot backup is done.
120121
SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshotInfo.getVolumeId());
121122
if (snapshotDataStoreVO != null) {
122-
ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
123+
//Double check the snapshot is removed or not
124+
SnapshotVO parentSnap = snapshotDao.findById(snapshotDataStoreVO.getSnapshotId());
125+
if (parentSnap != null) {
126+
ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
127+
} else {
128+
s_logger.debug("find inconsistent db for snapshot " + snapshotDataStoreVO.getSnapshotId());
129+
}
123130
}
124131
ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
125132
ss = snapshotDataStoreDao.persist(ss);

‎server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
import javax.inject.Inject;
2727
import javax.naming.ConfigurationException;
2828

29-
import org.apache.cloudstack.api.command.user.snapshot.UpdateSnapshotPolicyCmd;
3029
import org.apache.log4j.Logger;
3130
import org.springframework.stereotype.Component;
3231

3332
import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotPolicyCmd;
3433
import org.apache.cloudstack.api.command.user.snapshot.DeleteSnapshotPoliciesCmd;
3534
import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd;
3635
import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
36+
import org.apache.cloudstack.api.command.user.snapshot.UpdateSnapshotPolicyCmd;
3737
import org.apache.cloudstack.context.CallContext;
3838
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
3939
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
@@ -1148,4 +1148,6 @@ public Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAlloc
11481148
return snapshot;
11491149
}
11501150

1151+
1152+
11511153
}

0 commit comments

Comments
 (0)