Changeset 26292 for trunk/Nebulous
- Timestamp:
- Nov 30, 2009, 1:54:49 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/Nebulous/lib/Nebulous/Client.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous/lib/Nebulous/Client.pm
r25121 r26292 315 315 my $locations; 316 316 if (defined $vol_name) { 317 $locations = $self->find_instances ($key, $vol_name);317 $locations = $self->find_instances_for_cull($key, $vol_name); 318 318 } else { 319 $locations = $self->find_instances ($key);319 $locations = $self->find_instances_for_cull($key); 320 320 } 321 321 … … 326 326 return; 327 327 } 328 329 my $uri = $self->delete_instance($key, @$locations[0]); 328 329 # Calculate which is the best instance to remove. First, see if we have two copies 330 # on one volume, if so, delete the first of those copies. 331 my $delete_index = -1; 332 333 for (my $i = 0 ; $i <= $#{ $locations }; $i++) { 334 for (my $j = $i + 1; $j <= $#{ $locations }; $j++) { 335 if (@$locations[$i]->{vol_id} eq @$locations[$j]->{vol_id}) { 336 $delete_index = $i; 337 } 338 } 339 } 340 # If we don't have two copies on one volume, see if we have two copies on a single 341 # cabinet. If so, delete the first of those copies. 342 if ($delete_index == -1) { 343 for (my $i = 0 ; $i <= $#{ $locations }; $i++) { 344 for (my $j = $i + 1; $j <= $#{ $locations }; $j++) { 345 if (@$locations[$i]->{cab_id} eq @$locations[$j]->{cab_id}) { 346 $delete_index = $i; 347 } 348 } 349 } 350 } 351 # Fail-safe. We didn't have any duplicates (the instances are "well-mixed"), so 352 # delete the first. 353 if ($delete_index == -1) { 354 $delete_index = 0; 355 } 356 my $uri = $self->delete_instance($key, @$locations[$delete_index]->{uri}); 330 357 331 358 eval { 332 _nuke_file(_get_file_path(@$locations[ 0]));359 _nuke_file(_get_file_path(@$locations[$delete_index]->{uri})); 333 360 }; 334 361 if ($@) { … … 758 785 } 759 786 787 sub find_instances_for_cull 788 { 789 my $self = shift; 790 791 my ( $key, @params ) = validate_pos( @_, 792 { 793 type => SCALAR, 794 }, 795 { 796 #volume 797 type => SCALAR|UNDEF, 798 optional => 1, 799 }, 800 ); 801 802 $log->debug( "entered - @_" ); 803 804 my $response = $self->{ 'server' }->find_instances_for_cull( $key, @params ); 805 if ( $response->fault ) { 806 $self->set_err($response->faultstring); 807 # check to see if this failure is because $key doesn't exist 808 if ($response->faultstring =~ /is valid object key/) { 809 $log->debug( "leaving" ); 810 return; 811 } 812 # key is valid but no instances are on the specified volume 813 if ($response->faultstring =~ /no instances on storage volume/) { 814 $log->debug( "leaving" ); 815 return; 816 } 817 818 $log->logdie("unhandled fault - ", $self->err); 819 } 820 821 my $uris = $response->result; 822 823 $log->debug( "server found: @$uris" ); 824 825 $log->debug( "leaving" ); 826 827 return $uris; 828 } 829 760 830 761 831 sub find
Note:
See TracChangeset
for help on using the changeset viewer.
