CLOUDSTACK-3472: [Object_Store_Refactor] System VMs are not coming up in

initial attempt, but they are coming up after multiple attempts.
This commit is contained in:
Min Chen 2013-07-19 15:38:37 -07:00
parent e2f14167f2
commit 1694e53b1d
4 changed files with 40 additions and 10 deletions

View File

@ -257,7 +257,7 @@ public class VMTemplateStoragePoolVO implements VMTemplateStorageResourceAssoc,
@Override
public String toString() {
return new StringBuilder("TmplPool[").append(id).append("-").append(templateId).append("-").append("poolId")
return new StringBuilder("TmplPool[").append(id).append("-").append(templateId).append("-").append(poolId)
.append("-").append(installPath).append("]").toString();
}

View File

@ -70,8 +70,12 @@ public class TemplateDataFactoryImpl implements TemplateDataFactory {
}
}
if (!found) {
s_logger.debug("template " + templateId + " is not in store:" + store.getId() + ", type:" + store.getRole());
if (s_logger.isDebugEnabled()) {
if (!found) {
s_logger.debug("template " + templateId + " is not in store:" + store.getId() + ", type:" + store.getRole());
} else {
s_logger.debug("template " + templateId + " is already in store:" + store.getId() + ", type:" + store.getRole());
}
}
TemplateObject tmpl = TemplateObject.getTemplate(templ, store);

View File

@ -228,13 +228,26 @@ public class PrimaryDataStoreImpl implements PrimaryDataStore {
VMTemplateStoragePoolVO templateStoragePoolRef = templatePoolDao.findByPoolTemplate(this.getId(),
obj.getId());
if (templateStoragePoolRef == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Not found (templateId: " + obj.getId() + ", poolId: " + this.getId() + ") in template_spool_ref");
}
try {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Persisting (templateId: " + obj.getId() + ", poolId: " + this.getId() + ") to template_spool_ref");
}
templateStoragePoolRef = new VMTemplateStoragePoolVO(this.getId(), obj.getId());
templateStoragePoolRef = templatePoolDao.persist(templateStoragePoolRef);
} catch (Throwable t) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Failed to insert (templateId: " + obj.getId() + ", poolId: " + this.getId() + ") to template_spool_ref", t);
}
templateStoragePoolRef = templatePoolDao.findByPoolTemplate(this.getId(), obj.getId());
if (templateStoragePoolRef == null) {
throw new CloudRuntimeException("Failed to create template storage pool entry");
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Another thread already inserts " + templateStoragePoolRef.getId() + " to template_spool_ref", t);
}
}
}
}

View File

@ -146,6 +146,7 @@ public class VolumeServiceImpl implements VolumeService {
}
@Override
public ChapInfo getChapInfo(VolumeInfo volumeInfo, DataStore dataStore) {
DataStoreDriver dataStoreDriver = dataStore.getDriver();
@ -353,8 +354,12 @@ public class VolumeServiceImpl implements VolumeService {
VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
if (templatePoolRef == null) {
throw new CloudRuntimeException("Failed to find template " + template.getUniqueName()
+ " in VMTemplateStoragePool");
throw new CloudRuntimeException("Failed to find template " + template.getUniqueName() + " in storage pool " + dataStore.getId());
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found template " + template.getUniqueName() + " in storage pool " + dataStore.getId() + " with VMTemplateStoragePool id: "
+ templatePoolRef.getId());
}
}
long templatePoolRefId = templatePoolRef.getId();
CreateBaseImageContext<CreateCmdResult> context = new CreateBaseImageContext<CreateCmdResult>(null, volume,
@ -364,8 +369,14 @@ public class VolumeServiceImpl implements VolumeService {
int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(
configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds");
}
templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds);
if (templatePoolRef == null) {
if (s_logger.isDebugEnabled()) {
s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId);
}
templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
if (templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready ) {
s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId + ", But Template " + template.getUniqueName() + " is already copied to primary storage, skip copying");
@ -375,17 +386,15 @@ public class VolumeServiceImpl implements VolumeService {
throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + templatePoolRefId);
}
if (s_logger.isDebugEnabled()) {
s_logger.info("lock is acquired for VMTemplateStoragePool " + templatePoolRefId);
}
try {
// lock acquired
if (templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready ) {
s_logger.info("Template " + template.getUniqueName() + " is already copied to primary storage, skip copying");
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future);
return;
}
// remove the leftover hanging entry
dataStore.delete(templateOnPrimaryStoreObj);
// create a new entry to restart copying process
templateOnPrimaryStoreObj = dataStore.create(template);
templateOnPrimaryStoreObj.processEvent(Event.CreateOnlyRequested);
motionSrv.copyAsync(template, templateOnPrimaryStoreObj, caller);
} catch (Throwable e) {
@ -394,6 +403,10 @@ public class VolumeServiceImpl implements VolumeService {
VolumeApiResult result = new VolumeApiResult(volume);
result.setResult(e.toString());
future.complete(result);
} finally {
if (s_logger.isDebugEnabled()) {
s_logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId);
}
_tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
}
return;