cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [3/3] git commit: updated refs/heads/object_store_migration to 216d034
Date Sat, 26 Oct 2013 05:49:49 GMT
Forgot to update store role of template_store_ref and snapshot_store_ref
in prepareSecondaryStorageForMigrationCmd.

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

Branch: refs/heads/object_store_migration
Commit: 216d0343ed3a97455f23616949fb918e75a54ad9
Parents: 0f0370b
Author: Min Chen <min.chen@citrix.com>
Authored: Fri Oct 25 22:46:07 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Fri Oct 25 22:46:07 2013 -0700

----------------------------------------------------------------------
 .../datastore/db/SnapshotDataStoreDao.java      |  2 ++
 .../datastore/db/TemplateDataStoreDao.java      |  2 ++
 .../image/db/SnapshotDataStoreDaoImpl.java      | 20 +++++++++++++++++--
 .../image/db/TemplateDataStoreDaoImpl.java      | 21 ++++++++++++++++++--
 .../image/db/VolumeDataStoreDaoImpl.java        | 21 ++++++++++++++++----
 .../com/cloud/storage/StorageManagerImpl.java   | 10 ++++++----
 6 files changed, 64 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/216d0343/engine/schema/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
index 9cde86d..dfa03ad 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
@@ -48,4 +48,6 @@ StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Even
     void deleteSnapshotRecordsOnPrimary();
 
     List<SnapshotDataStoreVO> listOnCache(long snapshotId);
+
+    void updateStoreRoleToCache(long storeId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/216d0343/engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
index 95cbdb6..93adaaf 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
@@ -68,4 +68,6 @@ StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Even
     TemplateDataStoreVO findReadyOnCache(long templateId);
 
     List<TemplateDataStoreVO> listOnCache(long templateId);
+
+    void updateStoreRoleToCachce(long storeId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/216d0343/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
index d566b31..053c806 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
@@ -250,12 +250,13 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
     @Override
     public void duplicateCacheRecordsOnRegionStore(long storeId) {
         // find all records on image cache
-        SearchCriteria<SnapshotDataStoreVO> sc = cacheSearch.create();
-        sc.setParameters("store_id", storeId);
+        SearchCriteria<SnapshotDataStoreVO> sc = storeSnapshotSearch.create();
+        sc.setParameters("store_role", DataStoreRole.ImageCache);
         sc.setParameters("destroyed", false);
         List<SnapshotDataStoreVO> snapshots = listBy(sc);
         // create an entry for each record, but with empty install path since the content
is not yet on region-wide store yet
         if (snapshots != null) {
+            s_logger.info("Duplicate " + snapshots.size() + " snapshot cache store records
to region store");
             for (SnapshotDataStoreVO snap : snapshots) {
                 SnapshotDataStoreVO ss = new SnapshotDataStoreVO();
                 ss.setSnapshotId(snap.getId());
@@ -281,4 +282,19 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
         return search(sc, null);
     }
 
+    @Override
+    public void updateStoreRoleToCache(long storeId) {
+        SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", storeId);
+        sc.setParameters("destroyed", false);
+        List<SnapshotDataStoreVO> snaps = listBy(sc);
+        if (snaps != null) {
+            s_logger.info("Update to cache store role for " + snaps.size() + " entries in
snapshot_store_ref");
+            for (SnapshotDataStoreVO snap : snaps) {
+                snap.setRole(DataStoreRole.ImageCache);
+                update(snap.getId(), snap);
+            }
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/216d0343/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
index b7c70cc..bc43e6c 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
@@ -376,12 +376,13 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
     @Override
     public void duplicateCacheRecordsOnRegionStore(long storeId) {
         // find all records on image cache
-        SearchCriteria<TemplateDataStoreVO> sc = cacheSearch.create();
-        sc.setParameters("store_id", storeId);
+        SearchCriteria<TemplateDataStoreVO> sc = templateRoleSearch.create();
+        sc.setParameters("store_role", DataStoreRole.ImageCache);
         sc.setParameters("destroyed", false);
         List<TemplateDataStoreVO> tmpls = listBy(sc);
         // create an entry for each record, but with empty install path since the content
is not yet on region-wide store yet
         if (tmpls != null) {
+            s_logger.info("Duplicate " + tmpls.size() + " template cache store records to
region store");
             for (TemplateDataStoreVO tmpl : tmpls) {
                 TemplateDataStoreVO ts = new TemplateDataStoreVO();
                 ts.setTemplateId(tmpl.getTemplateId());
@@ -413,8 +414,24 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
             }
 
         }
+    }
+
 
+    @Override
+    public void updateStoreRoleToCachce(long storeId) {
+        SearchCriteria<TemplateDataStoreVO> sc = storeSearch.create();
+        sc.setParameters("store_id", storeId);
+        sc.setParameters("destroyed", false);
+        List<TemplateDataStoreVO> tmpls = listBy(sc);
+        if (tmpls != null) {
+            s_logger.info("Update to cache store role for " + tmpls.size() + " entries in
template_store_ref");
+            for (TemplateDataStoreVO tmpl : tmpls) {
+                tmpl.setDataStoreRole(DataStoreRole.ImageCache);
+                update(tmpl.getId(), tmpl);
+            }
+        }
 
     }
 
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/216d0343/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
index ef0a8c5..9324cd7 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
@@ -16,16 +16,20 @@
 // under the License.
 package org.apache.cloudstack.storage.image.db;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
 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.Event;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
@@ -46,6 +50,9 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO,
Lo
     private SearchBuilder<VolumeDataStoreVO> storeSearch;
     private SearchBuilder<VolumeDataStoreVO> cacheSearch;
     private SearchBuilder<VolumeDataStoreVO> storeVolumeSearch;
+    
+    @Inject
+    DataStoreManager storeMgr;
 
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException
{
@@ -191,12 +198,18 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO,
Lo
     @Override
     public void duplicateCacheRecordsOnRegionStore(long storeId) {
         // find all records on image cache
-        SearchCriteria<VolumeDataStoreVO> sc = cacheSearch.create();
-        sc.setParameters("store_id", storeId);
-        sc.setParameters("destroyed", false);
-        List<VolumeDataStoreVO> vols = listBy(sc);
+        List<DataStore> cacheStores = storeMgr.listImageCacheStores();
+        if (cacheStores == null || cacheStores.size() == 0) {
+            return;
+        }
+        List<VolumeDataStoreVO> vols = new ArrayList<VolumeDataStoreVO>();
+        for (DataStore store : cacheStores) {
+            // check if the volume is stored there
+            vols.addAll(listByStoreId(store.getId()));
+        }
         // create an entry for each record, but with empty install path since the content
is not yet on region-wide store yet
         if (vols != null) {
+            s_logger.info("Duplicate " + vols.size() + " volume cache store records to region
store");
             for (VolumeDataStoreVO vol : vols) {
                 VolumeDataStoreVO vs = new VolumeDataStoreVO();
                 vs.setVolumeId(vol.getId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/216d0343/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index 8e199ee..75850f4 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -159,15 +159,14 @@ import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericSearchBuilder;
 import com.cloud.utils.db.GlobalLock;
 import com.cloud.utils.db.JoinBuilder;
-import com.cloud.utils.db.TransactionCallback;
-import com.cloud.utils.db.TransactionCallbackNoReturn;
-import com.cloud.utils.db.TransactionLegacy;
-import com.cloud.utils.db.TransactionStatus;
 import com.cloud.utils.db.JoinBuilder.JoinType;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.Transaction;
+import com.cloud.utils.db.TransactionCallbackNoReturn;
+import com.cloud.utils.db.TransactionLegacy;
+import com.cloud.utils.db.TransactionStatus;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine.State;
@@ -1264,6 +1263,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
         DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
         DataStore secStore = dataStoreMgr.getDataStore(storeId, DataStoreRole.Image);
         lifeCycle.migrateToObjectStore(secStore);
+        // update store_role in template_store_ref and snapshot_store_ref to ImageCache
+        _templateStoreDao.updateStoreRoleToCachce(storeId);
+        _snapshotStoreDao.updateStoreRoleToCache(storeId);
         // converted to an image cache store
         return (ImageStore)_dataStoreMgr.getDataStore(storeId, DataStoreRole.ImageCache);
     }


Mime
View raw message