IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25121 for trunk/Nebulous/lib


Ignore:
Timestamp:
Aug 18, 2009, 5:02:45 PM (17 years ago)
Author:
jhoblitt
Message:

start neb-cull --min_copies

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/lib/Nebulous/Client.pm

    r24996 r25121  
    275275    my $self = shift;
    276276
    277     my ($key, $vol_name) = validate_pos(@_,
     277    my ($key, $vol_name, $min_copies) = validate_pos(@_,
    278278        {
    279279            type => SCALAR,
     
    284284            optional    => 1,
    285285        },
    286     );
    287 
    288     $log->debug( "entered - @_" );
    289 
    290     my $locations;
     286        {
     287            # min copies
     288            type        => SCALAR,
     289            optional    => 1,
     290        },
     291    );
     292
     293    $min_copies ||= 1;
     294
     295    $log->debug( "entered - @_" );
     296
     297    my $stats = $self->stat($key);
     298    my $instances = $stats->[6];
     299    if ((not defined $instances) or ($instances == 0)) {
     300        $self->set_err("can not cull - no instances");
     301        $log->debug("leaving");
     302        return;
     303    }
     304    if ($instances < $min_copies) {
     305        $self->set_err("can not cull - not enough instances");
     306        $log->debug("leaving");
     307
     308        return;
     309    }
     310
    291311    # if vol_name is specified we need to stat the file to find out how many
    292312    # instances there are on all volumes.  Otherwise we wouldn't know if it's
    293313    # safe to remove the last instance on the specified volume.
    294314    # XXX We need some way to determine which is the best instance to remove
     315    my $locations;
    295316    if (defined $vol_name) {
    296         my @stats = $self->stat($key);
    297         my $instances = $stats[6];
    298         if (defined $instances and $instances < 2) {
    299             $self->set_err("can not cull - not enough instances");
    300             $log->debug("leaving");
    301 
    302             return;
    303         }
    304 
    305317        $locations = $self->find_instances($key, $vol_name);
    306         unless (defined $locations) {
    307             $self->set_err( "no instances" );
    308             $log->debug( "leaving" );
    309 
    310             return;
    311         }
    312318    } else {
    313319        $locations = $self->find_instances($key);
    314         unless ($locations) {
    315             $self->set_err( "no instances" );
    316             $log->debug("leaving");
    317 
    318             return;
    319         }
    320 
    321         if (scalar @{ $locations } < 2) {
    322             $self->set_err("can not cull - not enough instances");
    323             $log->debug("leaving");
    324 
    325             return;
    326         }
     320    }
     321
     322    unless (defined $locations) {
     323        $self->set_err( "no instances" );
     324        $log->debug( "leaving" );
     325
     326        return;
    327327    }
    328328
     
    393393            }
    394394            for (my $i = 1; $i < $stats->[6]; $i++) {
    395                 $self->cull($key);
     395                $self->cull($key, "any", 1);
    396396                $removed++;
    397397            }
Note: See TracChangeset for help on using the changeset viewer.