Updated Branches: refs/heads/object_store b4a996dd4 -> 896095760
CLOUDSTACK-2634:all delta snapshots relating to volume should be created in the same secondary storage as the first snapshot. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/89609576 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/89609576 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/89609576 Branch: refs/heads/object_store Commit: 896095760502595aa43be343dcbf3abf79a98ae2 Parents: b4a996d Author: Min Chen <min.c...@citrix.com> Authored: Thu May 23 10:45:47 2013 -0700 Committer: Min Chen <min.c...@citrix.com> Committed: Thu May 23 10:45:47 2013 -0700 ---------------------------------------------------------------------- .../storage/snapshot/SnapshotServiceImpl.java | 19 ++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/89609576/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java ---------------------------------------------------------------------- diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java index 25c283a..5717c17 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java @@ -30,6 +30,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event; +import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; @@ -259,6 +260,22 @@ public class SnapshotServiceImpl implements SnapshotService { } + // if a snapshot has parent snapshot, the new snapshot should be stored in the same store as its parent since + // we are taking delta snapshot + private DataStore findSnapshotImageStore(SnapshotInfo snapshot){ + if ( snapshot.getParent() == null ){ + return dataStoreMgr.getImageStore(snapshot.getDataCenterId()); + } else{ + SnapshotInfo parentSnapshot = snapshot.getParent(); + // Note that DataStore information in parentSnapshot is for primary data store here, we need to + // find the image store where the parent snapshot backup is located + SnapshotDataStoreVO parentSnapshotOnBackupStore = _snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image); + return dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(), + parentSnapshotOnBackupStore.getRole()); + } + } + + @Override public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) { SnapshotObject snapObj = (SnapshotObject)snapshot; @@ -268,7 +285,7 @@ public class SnapshotServiceImpl implements SnapshotService { snapObj.processEvent(Snapshot.Event.BackupToSecondary); - DataStore imageStore = this.dataStoreMgr.getImageStore(snapshot.getDataCenterId()); + DataStore imageStore = this.findSnapshotImageStore(snapshot); if (imageStore == null) { throw new CloudRuntimeException("can not find an image stores"); }