Repository navigation
[Enhancement] Cleanup up leftover volumes on Allocated volumes deletion #14497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nvazquez
wants to merge
5
commits into
apache:main
Choose a base branch
from
shapeblue:424-expunge-allocated-vols
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−34
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -429,7 +429,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic | |
|
|
||
| private final StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine; | ||
|
|
||
| private static final Set<Volume.State> STATES_VOLUME_CANNOT_BE_DESTROYED = new HashSet<>(Arrays.asList(Volume.State.Destroy, Volume.State.Expunging, Volume.State.Expunged, Volume.State.Allocated)); | ||
| private static final Set<Volume.State> STATES_VOLUME_CANNOT_BE_DESTROYED = new HashSet<>(Arrays.asList(Volume.State.Destroy, Volume.State.Expunging, Volume.State.Expunged)); | ||
| private static final long GiB_TO_BYTES = 1024 * 1024 * 1024; | ||
|
|
||
| private static final String CUSTOM_DISK_OFFERING_UNIQUE_NAME = "Cloud.com-Custom"; | ||
|
|
@@ -1741,8 +1741,9 @@ private VolumeVO orchestrateResizeVolume(long volumeId, long currentSize, long n | |
| @Override | ||
| @ActionEvent(eventType = EventTypes.EVENT_VOLUME_DELETE, eventDescription = "deleting volume") | ||
| /** | ||
| * Executes the removal of the volume. If the volume is only allocated we do not try to remove it from primary and secondary storage. | ||
| * Otherwise, after the removal in the database, we will try to remove the volume from both primary and secondary storage. | ||
| * Executes the removal of the volume. After the removal in the database, we will try to remove the volume from both primary and secondary storage. | ||
| * Volumes in the {@link Volume.State#Allocated} state that have a backing storage pool are routed through the same destroy/expunge flow so their | ||
| * backend storage is removed; those without a pool are soft-deleted directly. | ||
| */ | ||
| public boolean deleteVolume(long volumeId, Account caller) throws ConcurrentOperationException { | ||
| Volume volume = destroyVolume(volumeId, caller, true, true, null); | ||
|
|
@@ -1810,7 +1811,6 @@ protected VolumeVO retrieveAndValidateVolume(long volumeId, Account caller) { | |
| * <li> {code}Volume.State#Destroy{code}; | ||
| * <li> {code}Volume.State#Expunging{code}; | ||
| * <li> {code}Volume.State#Expunged{code}; | ||
| * <li> {code}Volume.State#Allocated{code}. | ||
| * </ul> | ||
| * | ||
| * The volume is destroyed via {@link VolumeService#destroyVolume(long)} method. | ||
|
|
@@ -1899,6 +1899,21 @@ private void removeVolume(long volumeId) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Directly soft-deletes an {@link Volume.State#Allocated} volume that has no backing storage pool and releases its | ||
| * resource count. Volumes with poolID are left to the normal destroy/expunge flow | ||
| * @return true when the volume was handled here and no further destroy processing is required. | ||
| */ | ||
| protected boolean removeAllocatedVolumeWithoutStorage(VolumeVO volume, Boolean enforceResourceLimitOnDisplayFalse) { | ||
| if (volume.getState() != Volume.State.Allocated || volume.getPoolId() != null) { | ||
| return false; | ||
| } | ||
| removeVolume(volume.getId()); | ||
| _resourceLimitMgr.decrementVolumeResourceCount(volume.getAccountId(), volume.isDisplay(), | ||
| volume.getSize(), _diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId()), enforceResourceLimitOnDisplayFalse); | ||
| return true; | ||
| } | ||
|
|
||
| public boolean stateTransitTo(Volume vol, Volume.Event event) throws NoTransitionException { | ||
| return _volStateMachine.transitTo(vol, event, null, _volsDao); | ||
| } | ||
|
|
@@ -1928,23 +1943,13 @@ public Volume destroyVolume(long volumeId, Account caller, boolean expunge, bool | |
|
|
||
| validateDestroyVolume(volume, caller, expunge, forceExpunge); | ||
|
|
||
| if (expunge && removeAllocatedVolumeWithoutStorage(volume, enforceResourceLimitOnDisplayFalse)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nvazquez in the failed attach case, is the volume path saved before it fails? if its still empty the delete thinks it was never created and only drops the record, so the disk stays on the storage |
||
| return volume; | ||
| } | ||
|
|
||
| destroyVolumeIfPossible(volume); | ||
|
|
||
| if (expunge) { | ||
| // Mark volume as removed if volume has not been created on primary or secondary | ||
| if (volume.getState() == Volume.State.Allocated) { | ||
| _volsDao.remove(volume.getId()); | ||
| try { | ||
| stateTransitTo(volume, Volume.Event.DestroyRequested); | ||
| stateTransitTo(volume, Volume.Event.OperationSucceeded); | ||
| } catch (NoTransitionException e) { | ||
| logger.debug("Failed to destroy volume {}", volume, e); | ||
| return null; | ||
| } | ||
| _resourceLimitMgr.decrementVolumeResourceCount(volume.getAccountId(), volume.isDisplay(), | ||
| volume.getSize(), _diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId()), enforceResourceLimitOnDisplayFalse); | ||
| return volume; | ||
| } | ||
| if (!deleteVolumeFromStorage(volume, caller)) { | ||
| logger.warn("Failed to expunge volume: {}", volume); | ||
| return null; | ||
|
|
@@ -1958,6 +1963,10 @@ public Volume destroyVolume(long volumeId, Account caller, boolean expunge, bool | |
| @Override | ||
| @ActionEvent(eventType = EventTypes.EVENT_VOLUME_DESTROY, eventDescription = "destroying a volume") | ||
| public void destroyVolume(long volumeId) { | ||
| VolumeVO volume = _volsDao.findById(volumeId); | ||
| if (volume != null && removeAllocatedVolumeWithoutStorage(volume, null)) { | ||
| return; | ||
| } | ||
| volService.destroyVolume(volumeId); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nvazquez does this still write the usage delete record? the old code moved the volume to destroyed, which is what records it. without that a volume deleted before it was ever created stays billed