From a53d39c1b687df22768613d556637c34354cb96b Mon Sep 17 00:00:00 2001 From: Sanjay Tripathi Date: Tue, 4 Nov 2014 13:27:17 +0530 Subject: [PATCH] CLOUDSTACK-7835: Deleted volumes with null UUID and no removed timestamp in database still appear. Also removed CREATING -> DESTROY via DESTROYREQUESTED, which was causing the volume to get stuck in expunging state. --- api/src/com/cloud/storage/Volume.java | 1 - .../storage/volume/VolumeServiceImpl.java | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/api/src/com/cloud/storage/Volume.java b/api/src/com/cloud/storage/Volume.java index b67a39557c5..91ad9551ec1 100755 --- a/api/src/com/cloud/storage/Volume.java +++ b/api/src/com/cloud/storage/Volume.java @@ -69,7 +69,6 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba s_fsm.addTransition(Creating, Event.OperationRetry, Creating); s_fsm.addTransition(Creating, Event.OperationFailed, Allocated); s_fsm.addTransition(Creating, Event.OperationSucceeded, Ready); - s_fsm.addTransition(Creating, Event.DestroyRequested, Destroy); s_fsm.addTransition(Creating, Event.CreateRequested, Creating); s_fsm.addTransition(Ready, Event.ResizeRequested, Resizing); s_fsm.addTransition(Resizing, Event.OperationSucceeded, Ready); diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index d97ad600cc8..1297da95b40 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -1021,11 +1021,20 @@ public class VolumeServiceImpl implements VolumeService { srcVolume.processEvent(Event.OperationSuccessed); destVolume.processEvent(Event.OperationSuccessed, result.getAnswer()); _volumeDao.updateUuid(srcVolume.getId(), destVolume.getId()); - destroyVolume(srcVolume.getId()); - srcVolume = volFactory.getVolume(srcVolume.getId()); - AsyncCallFuture destroyFuture = expungeVolumeAsync(srcVolume); - destroyFuture.get(); - future.complete(res); + try { + destroyVolume(srcVolume.getId()); + srcVolume = volFactory.getVolume(srcVolume.getId()); + AsyncCallFuture destroyFuture = expungeVolumeAsync(srcVolume); + // If volume destroy fails, this could be because of vdi is still in use state, so wait and retry. + if (destroyFuture.get().isFailed()) { + Thread.sleep(5 * 1000); + destroyFuture = expungeVolumeAsync(srcVolume); + destroyFuture.get(); + } + future.complete(res); + } catch (Exception e) { + s_logger.debug("failed to clean up volume on storage", e); + } return null; } catch (Exception e) { s_logger.debug("Failed to process copy volume callback", e);