Skip to content

Commit

Permalink
Merge pull request #228 from sjones4/topic-volume-deleted-expire
Browse files Browse the repository at this point in the history
EC2 volume deleted status metadata expiry
  • Loading branch information
obino committed Nov 21, 2020
2 parents 7373c52 + 968690f commit 4123044
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public Volume apply( final String input ) {
size = Integer.parseInt( storageVolume.getSize( ) );
}
if ( newState.isPresent( ) ) {
if ( State.ANNIHILATED == newState.get( ) && isDeleteExpired( volumeToUpdate ) ) {
Entities.delete( volumeToUpdate );
return volumeToUpdate;
}
volumeState = newState.get( );
}
volumeToUpdate.setState( volumeState );
Expand All @@ -197,10 +201,6 @@ public Volume apply( final String input ) {
LOG.error( ex );
Logs.extreme( ).error( ex, ex );
}
//TODO:GRZE: expire deleted/failed volumes in the future.
// if ( State.ANNIHILATED.equals( v.getState( ) ) && State.ANNIHILATED.equals( v.getState( ) ) && v.lastUpdateMillis( ) > VOLUME_DELETE_TIMEOUT ) {
// Entities.delete( v );
// }
buf.append( " Resulting new-state: [" ).append( volumeToUpdate.getState( ) ).append("]");
LOG.debug( buf.toString( ) );
return volumeToUpdate;
Expand Down Expand Up @@ -233,13 +233,19 @@ public Volume apply( final String input ) {
}

if ( volume.getSize( ) <= 0 ||
isDeleteExpired( volume ) ||
( newState.isPresent( ) && newState.get( ) != volume.getState( ) ) ) {
Entities.asTransaction( Volume.class, updateVolume ).apply( volume.getDisplayName( ) );
} else {
LOG.debug( buf.toString( ) + " unchanged" );
}
}

static boolean isDeleteExpired( final Volume volume ) {
return State.ANNIHILATED == volume.getState( )
&& volume.getSplitTime( TimeUnit.MINUTES ) > Volumes.DELETED_TIME;
}

static Optional<State> calculateState( final Volume volumeToUpdate, final String storageStatus ) {
Optional<State> state = Optional.of( volumeToUpdate.getState( ) );
if ( storageStatus != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
import com.eucalyptus.compute.common.internal.blockstorage.Volume;
import com.eucalyptus.compute.common.internal.blockstorage.VolumeTag;
import com.eucalyptus.compute.common.internal.identifier.ResourceIdentifiers;
import com.eucalyptus.configurable.ConfigurableClass;
import com.eucalyptus.configurable.ConfigurableField;
import com.eucalyptus.entities.Entities;
import com.eucalyptus.entities.TransactionException;
import com.eucalyptus.entities.TransactionResource;
Expand All @@ -92,8 +94,15 @@

import edu.ucsb.eucalyptus.cloud.VolumeSizeExceededException;

@ConfigurableClass( root = "cloud.volumes",
description = "Parameters controlling storage volumes." )
public class Volumes {
private static Logger LOG = Logger.getLogger( Volumes.class );
private static final Logger LOG = Logger.getLogger( Volumes.class );

@ConfigurableField( description = "Amount of time (in minutes) that a deleted volume will continue to be reported.",
initial = "60" )
public static Integer DELETED_TIME = 60;


@QuantityMetricFunction( VolumeMetadata.class )
public enum CountVolumes implements Function<OwnerFullName, Long> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import java.util.Collection;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nullable;
import javax.persistence.CascadeType;
Expand Down Expand Up @@ -167,7 +168,13 @@ public String mapState( ) {
return "unavailable";
}
}


public synchronized long getSplitTime( final TimeUnit units ) {
final long time = System.currentTimeMillis( );
final long split = time - super.getLastUpdateTimestamp( ).getTime( );
return units.convert( split, TimeUnit.MILLISECONDS );
}

public com.eucalyptus.compute.common.Volume morph( final com.eucalyptus.compute.common.Volume vol ) {
vol.setAvailabilityZone( this.getPartition( ) );
vol.setCreateTime( this.getCreationTimestamp( ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ public ArrayList<com.eucalyptus.compute.common.Volume> apply( final Set<String>
// build response volumes
for ( final Volume foundVol : filteredVolumes ) {
if ( State.ANNIHILATED.equals( foundVol.getState( ) ) ) {
Entities.delete( foundVol );
if ( filterPredicate.apply( foundVol ) ) {
replyVolumes.add( foundVol.morph( new com.eucalyptus.compute.common.Volume( ) ) );
}
Expand Down Expand Up @@ -923,9 +922,6 @@ public ArrayList<VolumeStatusItemType> apply( final Set<String> input ) {
volumes,
Predicates.and( new TrackingPredicate<>( volumeIds ), requestedAndAccessible ) );
for ( final Volume foundVol : filteredVolumes ) {
if ( State.ANNIHILATED.equals( foundVol.getState( ) ) ) {
Entities.delete( foundVol );
}
replyVolumes.add( volumeTransform.apply( foundVol ) );
}
return replyVolumes;
Expand Down

0 comments on commit 4123044

Please sign in to comment.