You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/10/26 06:18:48 UTC

[5/8] git commit: updated refs/heads/object_store_migration to 9da56fe

Modify various cache object deletion cases in orchestration layer to
handle cache store migrated from previous secondary storage.

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1722c480
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1722c480
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1722c480

Branch: refs/heads/object_store_migration
Commit: 1722c48087f663c1931814c36802cace1a52d898
Parents: 730832d
Author: Min Chen <mi...@citrix.com>
Authored: Wed Oct 23 15:16:52 2013 -0700
Committer: Min Chen <mi...@citrix.com>
Committed: Wed Oct 23 15:16:52 2013 -0700

----------------------------------------------------------------------
 .../motion/AncientDataMotionStrategy.java       | 30 +++++++++++++-------
 .../storage/image/TemplateServiceImpl.java      |  4 +++
 2 files changed, 24 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1722c480/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
index 5f5f01e..0d21047 100644
--- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
+++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
@@ -22,6 +22,9 @@ import java.util.Map;
 
 import javax.inject.Inject;
 
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
 import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
 import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
@@ -49,8 +52,6 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
 import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
 
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.storage.MigrateVolumeAnswer;
@@ -211,7 +212,8 @@ AncientDataMotionStrategy implements DataMotionStrategy {
                     cacheMgr.deleteCacheObject(srcForCopy);
                 } else {
                     // for template, we want to leave it on cache for performance reason
-                    if (answer == null || !answer.getResult()) {
+                    if ((answer == null || !answer.getResult()) && srcForCopy.getRefCount() < 2) {
+                        // cache object created by this copy, not already there
                         cacheMgr.deleteCacheObject(srcForCopy);
                     } else {
                         cacheMgr.releaseCacheObject(srcForCopy);
@@ -248,6 +250,13 @@ AncientDataMotionStrategy implements DataMotionStrategy {
         }
     }
 
+    protected void releaseSnapshotCacheChain(SnapshotInfo snapshot) {
+        while (snapshot != null) {
+            cacheMgr.releaseCacheObject(snapshot);
+            snapshot = snapshot.getParent();
+        }
+    }
+
     protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) {
         SnapshotInfo snapshot = (SnapshotInfo) snapObj;
         StoragePool pool = (StoragePool) volObj.getDataStore();
@@ -281,7 +290,8 @@ AncientDataMotionStrategy implements DataMotionStrategy {
             throw new CloudRuntimeException(basicErrMsg);
         } finally {
             if (!(storTO instanceof NfsTO)) {
-                deleteSnapshotCacheChain((SnapshotInfo) srcData);
+                // still keep snapshot on cache which may be migrated from previous secondary storage
+                releaseSnapshotCacheChain((SnapshotInfo)srcData);
             }
         }
     }
@@ -307,7 +317,7 @@ AncientDataMotionStrategy implements DataMotionStrategy {
         if (cacheStore == null) {
             // need to find a nfs or cifs image store, assuming that can't copy volume
             // directly to s3
-            ImageStoreEntity imageStore = (ImageStoreEntity) this.dataStoreMgr.getImageStore(destScope.getScopeId());
+            ImageStoreEntity imageStore = (ImageStoreEntity) dataStoreMgr.getImageStore(destScope.getScopeId());
             if (!imageStore.getProtocol().equalsIgnoreCase("nfs") && !imageStore.getProtocol().equalsIgnoreCase("cifs")) {
                 s_logger.debug("can't find a nfs (or cifs) image store to satisfy the need for a staging store");
                 return null;
@@ -316,7 +326,7 @@ AncientDataMotionStrategy implements DataMotionStrategy {
             DataObject objOnImageStore = imageStore.create(srcData);
             objOnImageStore.processEvent(Event.CreateOnlyRequested);
 
-            Answer answer = this.copyObject(srcData, objOnImageStore);
+            Answer answer = copyObject(srcData, objOnImageStore);
             if (answer == null || !answer.getResult()) {
                 if (answer != null) {
                     s_logger.debug("copy to image store failed: " + answer.getDetails());
@@ -362,7 +372,7 @@ AncientDataMotionStrategy implements DataMotionStrategy {
 
     protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) {
         VolumeInfo volume = (VolumeInfo)srcData;
-        StoragePool destPool = (StoragePool)this.dataStoreMgr.getDataStore(destData.getDataStore().getId(), DataStoreRole.Primary);
+        StoragePool destPool = (StoragePool)dataStoreMgr.getDataStore(destData.getDataStore().getId(), DataStoreRole.Primary);
         MigrateVolumeCommand command = new MigrateVolumeCommand(volume.getId(), volume.getPath(), destPool);
         EndPoint ep = selector.select(volume.getDataStore());
         MigrateVolumeAnswer answer = (MigrateVolumeAnswer) ep.sendMessage(command);
@@ -371,14 +381,14 @@ AncientDataMotionStrategy implements DataMotionStrategy {
             throw new CloudRuntimeException("Failed to migrate volume " + volume + " to storage pool " + destPool);
         } else {
             // Update the volume details after migration.
-            VolumeVO volumeVo = this.volDao.findById(volume.getId());
+            VolumeVO volumeVo = volDao.findById(volume.getId());
             Long oldPoolId = volume.getPoolId();
             volumeVo.setPath(answer.getVolumePath());
             volumeVo.setFolder(destPool.getPath());
             volumeVo.setPodId(destPool.getPodId());
             volumeVo.setPoolId(destPool.getId());
             volumeVo.setLastPoolId(oldPoolId);
-            this.volDao.update(volume.getId(), volumeVo);
+            volDao.update(volume.getId(), volumeVo);
         }
 
         return answer;
@@ -452,7 +462,7 @@ AncientDataMotionStrategy implements DataMotionStrategy {
 
         // clean up snapshot copied to staging
         if (needCache && srcData != null) {
-            cacheMgr.deleteCacheObject(srcData);
+            cacheMgr.releaseCacheObject(srcData);  // reduce ref count, but keep it there on cache which is converted from previous secondary storage
         }
         return answer;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1722c480/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
index 163c125..4121e85 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
@@ -42,6 +42,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 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.SnapshotInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.StorageCacheManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
@@ -129,6 +130,8 @@ public class TemplateServiceImpl implements TemplateService {
     TemplateManager _tmpltMgr;
     @Inject
     ConfigurationDao _configDao;
+    @Inject
+    StorageCacheManager _cacheMgr;
 
     class TemplateOpContext<T> extends AsyncRpcContext<T> {
         final TemplateObject template;
@@ -670,6 +673,7 @@ public class TemplateServiceImpl implements TemplateService {
                         throw new CloudRuntimeException("sync template from cache to region wide store failed for image store " + store.getName() + ":"
                                 + result.getResult());
                     }
+                    _cacheMgr.releaseCacheObject(srcTemplate); // reduce reference count for template on cache, so it can recycled by schedule
                 } catch (Exception ex) {
                     throw new CloudRuntimeException("sync template from cache to region wide store failed for image store " + store.getName());
                 }