mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-4325: if userdispersing algorithm is used, then zone wide storages never been picked up
This commit is contained in:
parent
ae617b6a35
commit
37d58313c9
|
|
@ -223,7 +223,6 @@
|
|||
<ref bean="LocalStoragePoolAllocator"/>
|
||||
<ref bean="clusterScopeStoragePoolAllocator"/>
|
||||
<ref bean="zoneWideStoragePoolAllocator"/>
|
||||
<ref bean="garbageCollectingStoragePoolAllocator"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
|
|
|||
|
|
@ -322,7 +322,6 @@
|
|||
<ref bean="LocalStoragePoolAllocator"/>
|
||||
<ref bean="clusterScopeStoragePoolAllocator"/>
|
||||
<ref bean="zoneWideStoragePoolAllocator"/>
|
||||
<ref bean="garbageCollectingStoragePoolAllocator"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
|
|||
List<VolumeVO> findReadyRootVolumesByInstance(long instanceId);
|
||||
|
||||
List<Long> listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId);
|
||||
|
||||
List<Long> listZoneWidePoolIdsByVolumeCount(long dcId, long accountId);
|
||||
/**
|
||||
* Gets the Total Primary Storage space allocated for an account
|
||||
*
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
|||
|
||||
private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? "
|
||||
+ " AND pool.pod_id = ? AND pool.cluster_id = ? " + " GROUP BY pool.id ORDER BY 2 ASC ";
|
||||
|
||||
private static final String ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? "
|
||||
+ " AND pool.scope = 'ZONE' AND pool.status='Up' " + " GROUP BY pool.id ORDER BY 2 ASC ";
|
||||
@Override
|
||||
public List<VolumeVO> findDetachedByAccount(long accountId) {
|
||||
SearchCriteria<VolumeVO> sc = DetachedAccountIdSearch.create();
|
||||
|
|
@ -480,6 +481,30 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> listZoneWidePoolIdsByVolumeCount(long dcId, long accountId) {
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
PreparedStatement pstmt = null;
|
||||
List<Long> result = new ArrayList<Long>();
|
||||
try {
|
||||
String sql = ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT;
|
||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
||||
pstmt.setLong(1, accountId);
|
||||
pstmt.setLong(2, dcId);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
result.add(rs.getLong(1));
|
||||
}
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("DB Exception on: " + ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e);
|
||||
} catch (Throwable e) {
|
||||
throw new CloudRuntimeException("Caught: " + ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB(txn = false)
|
||||
public Pair<Long, Long> getNonDestroyedCountAndTotalByPool(long poolId) {
|
||||
|
|
|
|||
|
|
@ -17,10 +17,13 @@
|
|||
package org.apache.cloudstack.storage.allocator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.user.Account;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
|
|
@ -101,4 +104,35 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator {
|
|||
}
|
||||
return suitablePools;
|
||||
}
|
||||
@Override
|
||||
protected List<StoragePool> reorderPoolsByNumberOfVolumes(DeploymentPlan plan, List<StoragePool> pools,
|
||||
Account account) {
|
||||
if (account == null) {
|
||||
return pools;
|
||||
}
|
||||
long dcId = plan.getDataCenterId();
|
||||
|
||||
List<Long> poolIdsByVolCount = _volumeDao.listZoneWidePoolIdsByVolumeCount(dcId,
|
||||
account.getAccountId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("List of pools in ascending order of number of volumes for account id: "
|
||||
+ account.getAccountId() + " is: " + poolIdsByVolCount);
|
||||
}
|
||||
|
||||
// now filter the given list of Pools by this ordered list
|
||||
Map<Long, StoragePool> poolMap = new HashMap<Long, StoragePool>();
|
||||
for (StoragePool pool : pools) {
|
||||
poolMap.put(pool.getId(), pool);
|
||||
}
|
||||
List<Long> matchingPoolIds = new ArrayList<Long>(poolMap.keySet());
|
||||
|
||||
poolIdsByVolCount.retainAll(matchingPoolIds);
|
||||
|
||||
List<StoragePool> reorderedPools = new ArrayList<StoragePool>();
|
||||
for (Long id : poolIdsByVolCount) {
|
||||
reorderedPools.add(poolMap.get(id));
|
||||
}
|
||||
|
||||
return reorderedPools;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue