Skip to content

Commit 70505e4

Browse files
Updating to back up snapshot to secondary not already there in the case of creating a volume
1 parent 960cace commit 70505e4

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
4545
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
4646
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService;
47+
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy;
48+
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy.SnapshotOperation;
4749
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
50+
import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory;
4851
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
4952
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
5053
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
@@ -188,6 +191,8 @@ public enum UserVmCloneType {
188191
StorageManager storageMgr;
189192
@Inject
190193
protected UserVmCloneSettingDao _vmCloneSettingDao;
194+
@Inject
195+
StorageStrategyFactory _storageStrategyFactory;
191196

192197
private final StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine;
193198
protected List<StoragePoolAllocator> _storagePoolAllocators;
@@ -393,10 +398,23 @@ public VolumeInfo createVolumeFromSnapshot(Volume volume, Snapshot snapshot, Use
393398
DataStoreRole dataStoreRole = getDataStoreRole(snapshot);
394399
SnapshotInfo snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole);
395400

396-
// Try it again with primary if we intentionally didn't back up to secondary,
397-
// as when snapshot.backup.rightafter is set to false
398-
if(snapInfo == null && dataStoreRole != DataStoreRole.Primary) {
401+
402+
if(snapInfo == null && dataStoreRole == DataStoreRole.Image) {
403+
// snapshot is not backed up to secondary, let's do that now.
399404
snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary);
405+
406+
if (snapInfo == null) {
407+
throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId());
408+
}
409+
// We need to copy the snapshot onto secondary.
410+
SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.BACKUP);
411+
snapshotStrategy.backupSnapshot(snapInfo);
412+
413+
// Attempt to grab it again.
414+
snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole);
415+
if (snapInfo == null) {
416+
throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId() + " on secondary and could not create backup");
417+
}
400418
}
401419
// don't try to perform a sync if the DataStoreRole of the snapshot is equal to DataStoreRole.Primary
402420
if (!DataStoreRole.Primary.equals(dataStoreRole)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
8585
@Override
8686
public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
8787
SnapshotInfo parentSnapshot = snapshot.getParent();
88+
8889
if (parentSnapshot != null && snapshot.getPath().equalsIgnoreCase(parentSnapshot.getPath())) {
8990
s_logger.debug("backup an empty snapshot");
90-
9191
// don't need to backup this snapshot
9292
SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image);
9393
if (parentSnapshotOnBackupStore != null && parentSnapshotOnBackupStore.getState() == State.Ready) {

0 commit comments

Comments
 (0)