Skip to content

Commit 0026863

Browse files
committed
bug 10177: fix multiple local secondary storage: when we starting vm, only choose the local secondary storage that related to the planned computing host
status 10177: resolved, fixed
1 parent 7f6a3bc commit 0026863

7 files changed

Lines changed: 64 additions & 11 deletions

File tree

‎server/src/com/cloud/api/ApiResponseHelper.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,16 +1456,28 @@ public void createTemplateResponse(List<TemplateResponse> responses, Pair<Long,
14561456
VMTemplateVO template = ApiDBUtils.findTemplateById(templateZonePair.first());
14571457

14581458
for (VMTemplateHostVO templateHostRef : templateHostRefsForTemplate) {
1459+
14591460
if (readyOnly) {
14601461
if (templateHostRef.getDownloadState() != Status.DOWNLOADED) {
14611462
continue;
14621463
}
1464+
boolean foundTheSameTemplate = false;
14631465
for (TemplateResponse res : responses) {
14641466
if (res.getId() == templateHostRef.getTemplateId()) {
1467+
foundTheSameTemplate = true;
14651468
continue;
14661469
}
14671470
}
1471+
if (foundTheSameTemplate) {
1472+
continue;
1473+
}
1474+
}
1475+
1476+
HostVO host = ApiDBUtils.findHostById(templateHostRef.getHostId());
1477+
if (host.getType() == Host.Type.LocalSecondaryStorage && host.getStatus() != com.cloud.host.Status.Up) {
1478+
continue;
14681479
}
1480+
14691481
TemplateResponse templateResponse = new TemplateResponse();
14701482
templateResponse.setId(template.getId());
14711483
templateResponse.setName(template.getName());
@@ -1501,7 +1513,6 @@ public void createTemplateResponse(List<TemplateResponse> responses, Pair<Long,
15011513
templateResponse.setDomainName(ApiDBUtils.findDomainById(owner.getDomainId()).getName());
15021514
}
15031515

1504-
HostVO host = ApiDBUtils.findHostById(templateHostRef.getHostId());
15051516
templateResponse.setHostId(host.getId());
15061517
templateResponse.setHostName(host.getName());
15071518

‎server/src/com/cloud/storage/StorageManager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public interface StorageManager extends Manager {
7979
* @param zoneId
8080
* @return secondary storage host
8181
*/
82-
public VMTemplateHostVO findVmTemplateHost(long templateId, long dcId, Long podId);
82+
public VMTemplateHostVO findVmTemplateHost(long templateId, StoragePool pool);
8383

8484
/**
8585
* Moves a volume from its current storage pool to a storage pool with enough capacity in the specified zone, pod, or cluster

‎server/src/com/cloud/storage/StorageManagerImpl.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
import com.cloud.vm.dao.SecondaryStorageVmDao;
183183
import com.cloud.vm.dao.UserVmDao;
184184
import com.cloud.vm.dao.VMInstanceDao;
185+
185186
import java.util.Random;
186187

187188
@Local(value = { StorageManager.class, StorageService.class })
@@ -2964,7 +2965,21 @@ public StoragePool getStoragePool(long id) {
29642965
}
29652966

29662967
@Override
2967-
public VMTemplateHostVO findVmTemplateHost(long templateId, long dcId, Long podId) {
2968+
public VMTemplateHostVO findVmTemplateHost(long templateId, StoragePool pool) {
2969+
long dcId = pool.getDataCenterId();
2970+
Long podId = pool.getPodId();
2971+
2972+
//FIXME, for cloudzone, the local secondary storoge
2973+
if (pool.isLocal() && pool.getPoolType() == StoragePoolType.Filesystem) {
2974+
List<StoragePoolHostVO> sphs = _storagePoolHostDao.listByPoolId(pool.getId());
2975+
if (!sphs.isEmpty()) {
2976+
StoragePoolHostVO localStoragePoolHost = sphs.get(0);
2977+
return _templateHostDao.findLocalSecondaryStorageByHostTemplate(localStoragePoolHost.getHostId(), templateId);
2978+
} else {
2979+
return null;
2980+
}
2981+
}
2982+
29682983
List<HostVO> secHosts = _hostDao.listSecondaryStorageHosts(dcId);
29692984
if (secHosts.size() == 1) {
29702985
VMTemplateHostVO templateHostVO = _templateHostDao.findByHostTemplate(secHosts.get(0).getId(), templateId);

‎server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ protected boolean checkPool(ExcludeList avoid, StoragePoolVO pool, DiskProfile d
228228
if ((template != null) && !tmpinstalled) {
229229
// If the template that was passed into this allocator is not installed in the storage pool,
230230
// add 3 * (template size on secondary storage) to the running total
231-
VMTemplateHostVO templateHostVO = _storageMgr.findVmTemplateHost(template.getId(), plan.getDataCenterId(), plan.getPodId());
231+
VMTemplateHostVO templateHostVO = _storageMgr.findVmTemplateHost(template.getId(), pool);
232232

233233
if (templateHostVO == null) {
234234
s_logger.info("Did not find template downloaded on secondary hosts in zone " + plan.getDataCenterId());

‎server/src/com/cloud/storage/dao/VMTemplateHostDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ public interface VMTemplateHostDao extends GenericDao<VMTemplateHostVO, Long> {
5959
List<VMTemplateHostVO> listByZoneTemplate(long dcId, long templateId, boolean readyOnly);
6060

6161
void deleteByHost(Long hostId);
62+
63+
VMTemplateHostVO findLocalSecondaryStorageByHostTemplate(long hostId, long templateId);
6264

6365
}

‎server/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import org.apache.log4j.Logger;
3434

35+
import com.cloud.host.Host;
3536
import com.cloud.host.HostVO;
3637
import com.cloud.host.dao.HostDao;
3738
import com.cloud.storage.VMTemplateHostVO;
@@ -58,6 +59,7 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
5859
protected final SearchBuilder<VMTemplateHostVO> TemplateStatusSearch;
5960
protected final SearchBuilder<VMTemplateHostVO> TemplateStatesSearch;
6061
protected SearchBuilder<VMTemplateHostVO> ZONE_TEMPLATE_SEARCH;
62+
protected SearchBuilder<VMTemplateHostVO> LOCAL_SECONDARY_STORAGE_SEARCH;
6163

6264

6365
protected static final String UPDATE_TEMPLATE_HOST_REF =
@@ -132,6 +134,18 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
132134
hostSearch.and("zone_id", hostSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
133135
ZONE_TEMPLATE_SEARCH.join("tmplHost", hostSearch, hostSearch.entity().getId(), ZONE_TEMPLATE_SEARCH.entity().getHostId(), JoinBuilder.JoinType.INNER);
134136
ZONE_TEMPLATE_SEARCH.done();
137+
138+
LOCAL_SECONDARY_STORAGE_SEARCH = createSearchBuilder();
139+
LOCAL_SECONDARY_STORAGE_SEARCH.and("template_id", LOCAL_SECONDARY_STORAGE_SEARCH.entity().getTemplateId(), SearchCriteria.Op.EQ);
140+
LOCAL_SECONDARY_STORAGE_SEARCH.and("state", LOCAL_SECONDARY_STORAGE_SEARCH.entity().getDownloadState(), SearchCriteria.Op.EQ);
141+
SearchBuilder<HostVO> localSecondaryHost = _hostDao.createSearchBuilder();
142+
localSecondaryHost.and("private_ip_address", localSecondaryHost.entity().getPrivateIpAddress(), SearchCriteria.Op.EQ);
143+
localSecondaryHost.and("state", localSecondaryHost.entity().getStatus(), SearchCriteria.Op.EQ);
144+
localSecondaryHost.and("data_center_id", localSecondaryHost.entity().getDataCenterId(), SearchCriteria.Op.EQ);
145+
localSecondaryHost.and("type", localSecondaryHost.entity().getType(), SearchCriteria.Op.EQ);
146+
LOCAL_SECONDARY_STORAGE_SEARCH.join("host", localSecondaryHost, localSecondaryHost.entity().getId(), LOCAL_SECONDARY_STORAGE_SEARCH.entity().getHostId(), JoinBuilder.JoinType.INNER);
147+
LOCAL_SECONDARY_STORAGE_SEARCH.done();
148+
135149
return result;
136150
}
137151
@Override
@@ -296,12 +310,9 @@ public List<VMTemplateHostVO> listByZoneTemplate(long dcId, long templateId, boo
296310
sc.setJoinParameters("tmplHost", "zone_id", dcId);
297311
if (readyOnly) {
298312
sc.setParameters("state", VMTemplateHostVO.Status.DOWNLOADED);
299-
List<VMTemplateHostVO> tmplHost = new ArrayList<VMTemplateHostVO>();
300-
tmplHost.add(findOneBy(sc));
301-
return tmplHost;
302-
} else {
303-
return listBy(sc);
304-
}
313+
}
314+
return listBy(sc);
315+
305316
}
306317

307318
@Override
@@ -330,6 +341,20 @@ public VMTemplateHostVO findByHostTemplate(long hostId, long templateId, boolean
330341
else
331342
return lockOneRandomRow(sc, true);
332343
}
344+
345+
//Based on computing node host id, and template id, find out the corresponding template_host_ref, assuming local secondary storage and computing node is in the same zone, and private ip
346+
@Override
347+
public VMTemplateHostVO findLocalSecondaryStorageByHostTemplate(long hostId, long templateId) {
348+
HostVO computingHost = _hostDao.findById(hostId);
349+
SearchCriteria<VMTemplateHostVO> sc = LOCAL_SECONDARY_STORAGE_SEARCH.create();
350+
sc.setJoinParameters("host", "private_ip_address", computingHost.getPrivateIpAddress());
351+
sc.setJoinParameters("host", "state", com.cloud.host.Status.Up);
352+
sc.setJoinParameters("host", "data_center_id", computingHost.getDataCenterId());
353+
sc.setJoinParameters("host", "type", Host.Type.LocalSecondaryStorage);
354+
sc.setParameters("template_id", templateId);
355+
sc.setParameters("state", VMTemplateHostVO.Status.DOWNLOADED);
356+
return findOneBy(sc);
357+
}
333358

334359
@Override
335360
public void deleteByHost(Long hostId) {

‎server/src/com/cloud/template/TemplateManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public VMTemplateStoragePoolVO prepareTemplateForCreate(VMTemplateVO template, S
350350
}
351351
}
352352

353-
templateHostRef = _storageMgr.findVmTemplateHost(templateId, pool.getDataCenterId(), pool.getPodId());
353+
templateHostRef = _storageMgr.findVmTemplateHost(templateId, pool);
354354

355355
if (templateHostRef == null) {
356356
s_logger.debug("Unable to find a secondary storage host who has completely downloaded the template.");

0 commit comments

Comments
 (0)