mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Clean up entries in template_store_ref, volume_store_ref and
snapshot_store_ref in case of operation failure.
This commit is contained in:
parent
2f6d94462e
commit
8f549db518
@ -28,5 +28,5 @@ public interface StorageCacheManager {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
DataObject getCacheObject(DataObject data, Scope scope);
|
DataObject getCacheObject(DataObject data, Scope scope);
|
||||||
DataObject deleteCacheObject(DataObject data);
|
boolean deleteCacheObject(DataObject data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,8 +81,6 @@ public class SnapshotDataStoreVO implements StateObject<ObjectInDataStoreStateMa
|
|||||||
@Column (name="install_path")
|
@Column (name="install_path")
|
||||||
private String installPath;
|
private String installPath;
|
||||||
|
|
||||||
@Column(name = GenericDao.REMOVED_COLUMN)
|
|
||||||
Date removed;
|
|
||||||
|
|
||||||
@Column(name="update_count", updatable = true, nullable=false)
|
@Column(name="update_count", updatable = true, nullable=false)
|
||||||
protected long updatedCount;
|
protected long updatedCount;
|
||||||
|
|||||||
@ -368,6 +368,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
|
int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
|
||||||
|
|
||||||
DataObject cacheData = null;
|
DataObject cacheData = null;
|
||||||
|
Answer answer = null;
|
||||||
try {
|
try {
|
||||||
if (needCacheStorage(srcData, destData)) {
|
if (needCacheStorage(srcData, destData)) {
|
||||||
cacheData = cacheMgr.getCacheObject(srcData, destData.getDataStore().getScope());
|
cacheData = cacheMgr.getCacheObject(srcData, destData.getDataStore().getScope());
|
||||||
@ -375,14 +376,19 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
|||||||
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait);
|
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait);
|
||||||
cmd.setCacheTO(cacheData.getTO());
|
cmd.setCacheTO(cacheData.getTO());
|
||||||
EndPoint ep = selector.select(srcData, destData);
|
EndPoint ep = selector.select(srcData, destData);
|
||||||
Answer answer = ep.sendMessage(cmd);
|
answer = ep.sendMessage(cmd);
|
||||||
return answer;
|
|
||||||
} else {
|
} else {
|
||||||
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait);
|
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait);
|
||||||
EndPoint ep = selector.select(srcData, destData);
|
EndPoint ep = selector.select(srcData, destData);
|
||||||
Answer answer = ep.sendMessage(cmd);
|
answer = ep.sendMessage(cmd);
|
||||||
return answer;
|
|
||||||
}
|
}
|
||||||
|
// clean up cache entry in case of failure
|
||||||
|
if (answer == null || !answer.getResult()) {
|
||||||
|
if (cacheData != null) {
|
||||||
|
cacheMgr.deleteCacheObject(cacheData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return answer;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
s_logger.debug("copy snasphot failed: " + e.toString());
|
s_logger.debug("copy snasphot failed: " + e.toString());
|
||||||
if (cacheData != null) {
|
if (cacheData != null) {
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class TemplateObject implements TemplateInfo {
|
|||||||
@Inject
|
@Inject
|
||||||
VMTemplateDao imageDao;
|
VMTemplateDao imageDao;
|
||||||
@Inject
|
@Inject
|
||||||
ObjectInDataStoreManager ojbectInStoreMgr;
|
ObjectInDataStoreManager objectInStoreMgr;
|
||||||
@Inject VMTemplatePoolDao templatePoolDao;
|
@Inject VMTemplatePoolDao templatePoolDao;
|
||||||
@Inject TemplateDataStoreDao templateStoreDao;
|
@Inject TemplateDataStoreDao templateStoreDao;
|
||||||
|
|
||||||
@ -191,10 +191,15 @@ public class TemplateObject implements TemplateInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ojbectInStoreMgr.update(this, event);
|
objectInStoreMgr.update(this, event);
|
||||||
} catch (NoTransitionException e) {
|
} catch (NoTransitionException e) {
|
||||||
s_logger.debug("failed to update state", e);
|
s_logger.debug("failed to update state", e);
|
||||||
throw new CloudRuntimeException("Failed to update state" + e.toString());
|
throw new CloudRuntimeException("Failed to update state" + e.toString());
|
||||||
|
} finally{
|
||||||
|
// in case of OperationFailed, expunge the entry
|
||||||
|
if ( event == ObjectInDataStoreStateMachine.Event.OperationFailed){
|
||||||
|
objectInStoreMgr.delete(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,10 +252,15 @@ public class TemplateObject implements TemplateInfo {
|
|||||||
this.stateTransit(templEvent);
|
this.stateTransit(templEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ojbectInStoreMgr.update(this, event);
|
objectInStoreMgr.update(this, event);
|
||||||
} catch (NoTransitionException e) {
|
} catch (NoTransitionException e) {
|
||||||
s_logger.debug("failed to update state", e);
|
s_logger.debug("failed to update state", e);
|
||||||
throw new CloudRuntimeException("Failed to update state" + e.toString());
|
throw new CloudRuntimeException("Failed to update state" + e.toString());
|
||||||
|
} finally{
|
||||||
|
// in case of OperationFailed, expunge the entry
|
||||||
|
if ( event == ObjectInDataStoreStateMachine.Event.OperationFailed){
|
||||||
|
objectInStoreMgr.delete(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +276,7 @@ public class TemplateObject implements TemplateInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInstallPath() {
|
public String getInstallPath() {
|
||||||
DataObjectInStore obj = ojbectInStoreMgr.findObject(this, this.dataStore);
|
DataObjectInStore obj = objectInStoreMgr.findObject(this, this.dataStore);
|
||||||
return obj.getInstallPath();
|
return obj.getInstallPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -59,14 +59,17 @@ public class SnapshotObject implements SnapshotInfo {
|
|||||||
protected SnapshotDao snapshotDao;
|
protected SnapshotDao snapshotDao;
|
||||||
@Inject
|
@Inject
|
||||||
protected VolumeDao volumeDao;
|
protected VolumeDao volumeDao;
|
||||||
@Inject protected VolumeDataFactory volFactory;
|
@Inject
|
||||||
@Inject protected SnapshotStateMachineManager stateMachineMgr;
|
protected VolumeDataFactory volFactory;
|
||||||
|
@Inject
|
||||||
|
protected SnapshotStateMachineManager stateMachineMgr;
|
||||||
@Inject
|
@Inject
|
||||||
SnapshotDataFactory snapshotFactory;
|
SnapshotDataFactory snapshotFactory;
|
||||||
@Inject
|
@Inject
|
||||||
ObjectInDataStoreManager ojbectInStoreMgr;
|
ObjectInDataStoreManager objectInStoreMgr;
|
||||||
@Inject
|
@Inject
|
||||||
SnapshotDataStoreDao snapshotStoreDao;
|
SnapshotDataStoreDao snapshotStoreDao;
|
||||||
|
|
||||||
public SnapshotObject() {
|
public SnapshotObject() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -144,20 +147,22 @@ public class SnapshotObject implements SnapshotInfo {
|
|||||||
return DataObjectType.SNAPSHOT;
|
return DataObjectType.SNAPSHOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUuid() {
|
public String getUuid() {
|
||||||
return this.snapshot.getUuid();
|
return this.snapshot.getUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processEvent(
|
public void processEvent(ObjectInDataStoreStateMachine.Event event) {
|
||||||
ObjectInDataStoreStateMachine.Event event) {
|
|
||||||
try {
|
try {
|
||||||
ojbectInStoreMgr.update(this, event);
|
objectInStoreMgr.update(this, event);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
s_logger.debug("Failed to update state:" + e.toString());
|
s_logger.debug("Failed to update state:" + e.toString());
|
||||||
throw new CloudRuntimeException("Failed to update state: " + e.toString());
|
throw new CloudRuntimeException("Failed to update state: " + e.toString());
|
||||||
|
} finally {
|
||||||
|
if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
|
||||||
|
objectInStoreMgr.delete(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +178,7 @@ public class SnapshotObject implements SnapshotInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return this.ojbectInStoreMgr.findObject(this, getDataStore()).getInstallPath();
|
return this.objectInStoreMgr.findObject(this, getDataStore()).getInstallPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -216,18 +221,16 @@ public class SnapshotObject implements SnapshotInfo {
|
|||||||
return this.snapshot.getDomainId();
|
return this.snapshot.getDomainId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getDataCenterId() {
|
public Long getDataCenterId() {
|
||||||
return this.snapshot.getDataCenterId();
|
return this.snapshot.getDataCenterId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processEvent(Snapshot.Event event)
|
public void processEvent(Snapshot.Event event) throws NoTransitionException {
|
||||||
throws NoTransitionException {
|
|
||||||
stateMachineMgr.processEvent(this.snapshot, event);
|
stateMachineMgr.processEvent(this.snapshot, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SnapshotVO getSnapshotVO(){
|
public SnapshotVO getSnapshotVO() {
|
||||||
return this.snapshot;
|
return this.snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,14 +245,15 @@ public class SnapshotObject implements SnapshotInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
|
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
|
||||||
SnapshotDataStoreVO snapshotStore = this.snapshotStoreDao.findByStoreSnapshot(this.getDataStore().getRole(),
|
try {
|
||||||
this.getDataStore().getId(), this.getId());
|
SnapshotDataStoreVO snapshotStore = this.snapshotStoreDao.findByStoreSnapshot(this.getDataStore().getRole(), this.getDataStore().getId(),
|
||||||
|
this.getId());
|
||||||
if (answer instanceof CreateObjectAnswer) {
|
if (answer instanceof CreateObjectAnswer) {
|
||||||
SnapshotObjectTO snapshotTO = (SnapshotObjectTO)((CreateObjectAnswer) answer).getData();
|
SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CreateObjectAnswer) answer).getData();
|
||||||
snapshotStore.setInstallPath(snapshotTO.getPath());
|
snapshotStore.setInstallPath(snapshotTO.getPath());
|
||||||
this.snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
|
this.snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
|
||||||
} else if (answer instanceof CopyCmdAnswer) {
|
} else if (answer instanceof CopyCmdAnswer) {
|
||||||
SnapshotObjectTO snapshotTO = (SnapshotObjectTO)((CopyCmdAnswer) answer).getNewData();
|
SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CopyCmdAnswer) answer).getNewData();
|
||||||
snapshotStore.setInstallPath(snapshotTO.getPath());
|
snapshotStore.setInstallPath(snapshotTO.getPath());
|
||||||
if (snapshotTO.getParentSnapshotPath() == null) {
|
if (snapshotTO.getParentSnapshotPath() == null) {
|
||||||
snapshotStore.setParentSnapshotId(0L);
|
snapshotStore.setParentSnapshotId(0L);
|
||||||
@ -258,12 +262,18 @@ public class SnapshotObject implements SnapshotInfo {
|
|||||||
} else {
|
} else {
|
||||||
throw new CloudRuntimeException("Unknown answer: " + answer.getClass());
|
throw new CloudRuntimeException("Unknown answer: " + answer.getClass());
|
||||||
}
|
}
|
||||||
|
} catch (RuntimeException ex) {
|
||||||
|
if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
|
||||||
|
objectInStoreMgr.delete(this);
|
||||||
|
}
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
this.processEvent(event);
|
this.processEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectInDataStoreStateMachine.State getStatus() {
|
public ObjectInDataStoreStateMachine.State getStatus() {
|
||||||
return this.ojbectInStoreMgr.findObject(this, store).getObjectInStoreState();
|
return this.objectInStoreMgr.findObject(this, store).getObjectInStoreState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -59,7 +59,7 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
@Inject
|
@Inject
|
||||||
VolumeDataStoreDao volumeStoreDao;
|
VolumeDataStoreDao volumeStoreDao;
|
||||||
@Inject
|
@Inject
|
||||||
ObjectInDataStoreManager ojbectInStoreMgr;
|
ObjectInDataStoreManager objectInStoreMgr;
|
||||||
@Inject
|
@Inject
|
||||||
VMInstanceDao vmInstanceDao;
|
VMInstanceDao vmInstanceDao;
|
||||||
private Object payload;
|
private Object payload;
|
||||||
@ -159,7 +159,7 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
if (this.dataStore == null) {
|
if (this.dataStore == null) {
|
||||||
throw new CloudRuntimeException("datastore must be set before using this object");
|
throw new CloudRuntimeException("datastore must be set before using this object");
|
||||||
}
|
}
|
||||||
DataObjectInStore obj = ojbectInStoreMgr.findObject(this.volumeVO.getId(), DataObjectType.VOLUME, this.dataStore.getId(), this.dataStore.getRole());
|
DataObjectInStore obj = objectInStoreMgr.findObject(this.volumeVO.getId(), DataObjectType.VOLUME, this.dataStore.getId(), this.dataStore.getRole());
|
||||||
if (obj.getState() != ObjectInDataStoreStateMachine.State.Ready) {
|
if (obj.getState() != ObjectInDataStoreStateMachine.State.Ready) {
|
||||||
return this.dataStore.getUri() +
|
return this.dataStore.getUri() +
|
||||||
"&" + EncodingType.OBJTYPE + "=" + DataObjectType.VOLUME +
|
"&" + EncodingType.OBJTYPE + "=" + DataObjectType.VOLUME +
|
||||||
@ -187,11 +187,11 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
try {
|
try {
|
||||||
Volume.Event volEvent = null;
|
Volume.Event volEvent = null;
|
||||||
if ( this.dataStore.getRole() == DataStoreRole.ImageCache){
|
if ( this.dataStore.getRole() == DataStoreRole.ImageCache){
|
||||||
ojbectInStoreMgr.update(this, event);
|
objectInStoreMgr.update(this, event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.dataStore.getRole() == DataStoreRole.Image) {
|
if (this.dataStore.getRole() == DataStoreRole.Image) {
|
||||||
ojbectInStoreMgr.update(this, event);
|
objectInStoreMgr.update(this, event);
|
||||||
if (event == ObjectInDataStoreStateMachine.Event.CreateRequested) {
|
if (event == ObjectInDataStoreStateMachine.Event.CreateRequested) {
|
||||||
volEvent = Volume.Event.UploadRequested;
|
volEvent = Volume.Event.UploadRequested;
|
||||||
} else if (event == ObjectInDataStoreStateMachine.Event.OperationSuccessed) {
|
} else if (event == ObjectInDataStoreStateMachine.Event.OperationSuccessed) {
|
||||||
@ -225,6 +225,11 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
s_logger.debug("Failed to update state", e);
|
s_logger.debug("Failed to update state", e);
|
||||||
throw new CloudRuntimeException("Failed to update state:" + e.toString());
|
throw new CloudRuntimeException("Failed to update state:" + e.toString());
|
||||||
|
} finally{
|
||||||
|
// in case of OperationFailed, expunge the entry
|
||||||
|
if ( event == ObjectInDataStoreStateMachine.Event.OperationFailed){
|
||||||
|
objectInStoreMgr.delete(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -249,7 +254,7 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
if (this.dataStore.getRole() == DataStoreRole.Primary) {
|
if (this.dataStore.getRole() == DataStoreRole.Primary) {
|
||||||
return this.volumeVO.getPath();
|
return this.volumeVO.getPath();
|
||||||
} else {
|
} else {
|
||||||
DataObjectInStore objInStore = this.ojbectInStoreMgr.findObject(this, dataStore);
|
DataObjectInStore objInStore = this.objectInStoreMgr.findObject(this, dataStore);
|
||||||
return objInStore.getInstallPath();
|
return objInStore.getInstallPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,18 +384,19 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
|
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
|
||||||
|
try {
|
||||||
if (this.dataStore.getRole() == DataStoreRole.Primary) {
|
if (this.dataStore.getRole() == DataStoreRole.Primary) {
|
||||||
if (answer instanceof CopyCmdAnswer) {
|
if (answer instanceof CopyCmdAnswer) {
|
||||||
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer;
|
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
|
||||||
VolumeVO vol = this.volumeDao.findById(this.getId());
|
VolumeVO vol = this.volumeDao.findById(this.getId());
|
||||||
VolumeObjectTO newVol = (VolumeObjectTO)cpyAnswer.getNewData();
|
VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
|
||||||
vol.setPath(newVol.getPath());
|
vol.setPath(newVol.getPath());
|
||||||
vol.setSize(newVol.getSize());
|
vol.setSize(newVol.getSize());
|
||||||
vol.setPoolId(this.getDataStore().getId());
|
vol.setPoolId(this.getDataStore().getId());
|
||||||
volumeDao.update(vol.getId(), vol);
|
volumeDao.update(vol.getId(), vol);
|
||||||
} else if (answer instanceof CreateObjectAnswer) {
|
} else if (answer instanceof CreateObjectAnswer) {
|
||||||
CreateObjectAnswer createAnswer =(CreateObjectAnswer)answer;
|
CreateObjectAnswer createAnswer = (CreateObjectAnswer) answer;
|
||||||
VolumeObjectTO newVol = (VolumeObjectTO)createAnswer.getData();
|
VolumeObjectTO newVol = (VolumeObjectTO) createAnswer.getData();
|
||||||
VolumeVO vol = this.volumeDao.findById(this.getId());
|
VolumeVO vol = this.volumeDao.findById(this.getId());
|
||||||
vol.setPath(newVol.getPath());
|
vol.setPath(newVol.getPath());
|
||||||
vol.setSize(newVol.getSize());
|
vol.setSize(newVol.getSize());
|
||||||
@ -399,14 +405,20 @@ public class VolumeObject implements VolumeInfo {
|
|||||||
}
|
}
|
||||||
} else if (this.dataStore.getRole() == DataStoreRole.Image) {
|
} else if (this.dataStore.getRole() == DataStoreRole.Image) {
|
||||||
if (answer instanceof DownloadAnswer) {
|
if (answer instanceof DownloadAnswer) {
|
||||||
DownloadAnswer dwdAnswer = (DownloadAnswer)answer;
|
DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
|
||||||
VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
|
VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
|
||||||
volStore.setInstallPath(dwdAnswer.getInstallPath());
|
volStore.setInstallPath(dwdAnswer.getInstallPath());
|
||||||
volStore.setChecksum(dwdAnswer.getCheckSum());
|
volStore.setChecksum(dwdAnswer.getCheckSum());
|
||||||
this.volumeStoreDao.update(volStore.getId(), volStore);
|
this.volumeStoreDao.update(volStore.getId(), volStore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (RuntimeException ex) {
|
||||||
|
if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
|
||||||
|
objectInStoreMgr.delete(this);
|
||||||
|
}
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
this.processEvent(event);
|
this.processEvent(event);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user