IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41005


Ignore:
Timestamp:
Oct 31, 2019, 10:29:48 AM (7 years ago)
Author:
eugene
Message:

cull needs to stop if Ncopies <= min_copies (not < min_copies); there_can_be_only_one removes the invalid instances via prune and thus only needs to check the valid instances; handle invalid object key error in delete_instance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20191011/Nebulous/lib/Nebulous/Client.pm

    r40991 r41005  
    209209        },
    210210    );
    211 
     211   
    212212    $log->debug( "entered - @_" );
    213213
     
    310310    my $stats = $self->stat($key);
    311311    my $instances = $stats->[6];
     312
    312313    if ((not defined $instances) or ($instances == 0)) {
    313314        $self->set_err("can not cull - no instances");
     
    315316        return;
    316317    }
    317     if ($instances < $min_copies) {
     318    if ($instances <= $min_copies) {
    318319        $self->set_err("can not cull - not enough instances");
    319320        $log->debug("leaving");
     
    403404    eval {
    404405        # first - strip off any inaccesible instances
     406        # these are not counted in the 'removed' number
    405407        if (not defined $self->prune($key)) {
    406408            # use the prune() method to also determine if $key is valid
    407409            die "invalid key: $key";
    408410        }
    409 
    410         # check to see if there is an instance on $vol_name that should be the
    411         # sole survivor
     411       
     412        # check to see if there is an instance on $vol_name that
     413        # should be the sole survivor.  This is a bit dangerous : what
     414        # if the only instance is on an invalid volume?  what if an
     415        # invalid volume is specified?
     416
    412417        if (defined $vol_name) {
    413418            $locations = $self->find_instances($key, $vol_name);
     419            if (not defined $locations) {
     420                die "no instances on requested node";
     421            }
     422            if (scalar @$locations == 0) {
     423                die "no instances on requested node";
     424            }
    414425        }
    415426
     
    418429
    419430        if (defined $locations) {
    420             # XXX this is an example of passing 'find_invalid' to find_instances
    421             my $instances = $self->find_instances($key, undef, 'find them all');
    422             if (not defined $instances) {
     431            # first delete the valid instances (except the one we own)
     432            my $instances_valid = $self->find_instances($key, undef, 0); # find all valid instances
     433            if (not defined $instances_valid) {
     434                # there should have been at least one valid instance?
    423435                die "no instances";
    424436            }
    425             if (scalar @$instances == 1) {
    426                 # only one instance nothing to do
    427                 return 0;
    428             }
    429             if (scalar @$instances == 0) {
     437            if (scalar @$instances_valid == 0) {
     438                # there should have been at least one valid instance?
    430439                die "no instances";
    431440            }
    432             foreach my $victim (@$instances) {
    433                 next if $victim eq $locations->[0];
    434                 $self->delete_instance($key, $victim);
    435                 $removed++;
    436             }
     441
     442            # we have more than one instance, delete the others
     443            if (scalar @$instances_valid > 1) {
     444                foreach my $victim (@$instances_valid) {
     445                    next if $victim eq $locations->[0];
     446                    $self->delete_instance($key, $victim);
     447                    $removed ++;
     448                }
     449            }
     450            # the prune above should have deleted any invalid instances, so we only
     451            # need to worry about the valid instances;
    437452        } else {
    438453            # nuke whatever
     
    918933    unless(defined($params[0])) {
    919934        $params[0] = hostname() . ".0";
    920 #       print STDERR "Setting host to $params[0]\n";
     935        # print STDERR "Setting host to $params[0]\n";
    921936    }
    922937
     
    11871202
    11881203    $log->debug( "entered - @_" );
    1189 
    11901204
    11911205    my $locations;
     
    13801394        }
    13811395
     1396        if ($response->faultstring =~ /is valid object key/) {
     1397            $log->logdie("parameter #1 to delete_instance did not pass the 'is valid object key' callback");
     1398        }
     1399
    13821400        $log->logdie("unhandled fault - ", $self->err);
    13831401    }
     
    15421560}
    15431561
     1562sub set_log_level
     1563{
     1564    my $self = shift;
     1565
     1566    my $log_level = shift;
     1567
     1568    $log->level($log_level);
     1569
     1570    return $self;
     1571}
     1572
    15441573
    154515741;
Note: See TracChangeset for help on using the changeset viewer.