Updated Branches: refs/heads/4.3-forward 900c51103 -> e00241f41
CLOUDSTACK-6049: Give priority to cache stores where data object is already there instead of randomly picking one in case there are multiple cache stores in the scope. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e00241f4 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e00241f4 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e00241f4 Branch: refs/heads/4.3-forward Commit: e00241f41d6542cf1c5d93216fed55609cd7746a Parents: 900c511 Author: Min Chen <[email protected]> Authored: Thu Feb 6 17:11:36 2014 -0800 Committer: Min Chen <[email protected]> Committed: Thu Feb 6 17:11:36 2014 -0800 ---------------------------------------------------------------------- .../api/storage/StorageCacheManager.java | 2 + .../cache/allocator/StorageCacheAllocator.java | 3 ++ .../allocator/StorageCacheRandomAllocator.java | 39 ++++++++++++++++++++ .../cache/manager/StorageCacheManagerImpl.java | 13 +++++++ .../motion/AncientDataMotionStrategy.java | 2 +- 5 files changed, 58 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e00241f4/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java ---------------------------------------------------------------------- diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java index 92724c9..92263a7 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java @@ -20,6 +20,8 @@ package org.apache.cloudstack.engine.subsystem.api.storage; public interface StorageCacheManager { DataStore getCacheStorage(Scope scope); + + DataStore getCacheStorage(DataObject data, Scope scope); DataObject createCacheObject(DataObject data, Scope scope); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e00241f4/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheAllocator.java ---------------------------------------------------------------------- diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheAllocator.java b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheAllocator.java index 4259d9e..9f0052f 100644 --- a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheAllocator.java +++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheAllocator.java @@ -18,9 +18,12 @@ */ package org.apache.cloudstack.storage.cache.allocator; +import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.Scope; public interface StorageCacheAllocator { DataStore getCacheStore(Scope scope); + + DataStore getCacheStore(DataObject data, Scope scope); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e00241f4/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java ---------------------------------------------------------------------- diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java index 3b434d1..0054e3d 100644 --- a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java +++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java @@ -23,9 +23,14 @@ import java.util.List; import javax.inject.Inject; +import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; +import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; 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.Scope; +import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager; + import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -36,6 +41,8 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator { private static final Logger s_logger = Logger.getLogger(StorageCacheRandomAllocator.class); @Inject DataStoreManager dataStoreMgr; + @Inject + ObjectInDataStoreManager objectInStoreMgr; @Override public DataStore getCacheStore(Scope scope) { @@ -53,4 +60,36 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator { Collections.shuffle(cacheStores); return cacheStores.get(0); } + + @Override + public DataStore getCacheStore(DataObject data, Scope scope) { + if (scope.getScopeType() != ScopeType.ZONE) { + s_logger.debug("Can only support zone wide cache storage"); + return null; + } + + List<DataStore> cacheStores = dataStoreMgr.getImageCacheStores(scope); + if (cacheStores.size() <= 0) { + s_logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); + return null; + } + + // if there are multiple cache stores, we give priority to the one where data is already there + if (cacheStores.size() > 1) { + for (DataStore store : cacheStores) { + DataObjectInStore obj = objectInStoreMgr.findObject(data, store); + if (obj != null && obj.getState() == ObjectInDataStoreStateMachine.State.Ready) { + s_logger.debug("pick the cache store " + store.getId() + " where data is already there"); + return store; + } + } + + // otherwise, just random pick one + Collections.shuffle(cacheStores); + } + return cacheStores.get(0); + + } + + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e00241f4/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java ---------------------------------------------------------------------- diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java index bb8d67d..7c74729 100644 --- a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java +++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java @@ -90,6 +90,19 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { return null; } + + @Override + public DataStore getCacheStorage(DataObject data, Scope scope) { + for (StorageCacheAllocator allocator : storageCacheAllocator) { + DataStore store = allocator.getCacheStore(data, scope); + if (store != null) { + return store; + } + } + return null; + } + + protected List<DataStore> getCacheStores() { QueryBuilder<ImageStoreVO> sc = QueryBuilder.create(ImageStoreVO.class); sc.and(sc.entity().getRole(), SearchCriteria.Op.EQ,DataStoreRole.ImageCache); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e00241f4/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 f2ed667..d6759cb 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 @@ -201,7 +201,7 @@ AncientDataMotionStrategy implements DataMotionStrategy { protected DataObject cacheSnapshotChain(SnapshotInfo snapshot, Scope scope) { DataObject leafData = null; - DataStore store = cacheMgr.getCacheStorage(scope); + DataStore store = cacheMgr.getCacheStorage(snapshot, scope); while (snapshot != null) { DataObject cacheData = cacheMgr.createCacheObject(snapshot, store); if (leafData == null) {
