IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24927


Ignore:
Timestamp:
Jul 24, 2009, 5:29:35 PM (17 years ago)
Author:
jhoblitt
Message:

there_can_be_only_one

File:
1 edited

Legend:

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

    r24920 r24927  
    339339
    340340    return $uri;
     341}
     342
     343
     344sub there_can_be_only_one
     345{
     346    my $self = shift;
     347
     348    my ($key, $vol_name) = validate_pos(@_,
     349        {
     350            type => SCALAR,
     351        },
     352        {
     353            # volume
     354            type        => SCALAR,
     355            optional    => 1,
     356        },
     357    );
     358
     359    $log->debug( "entered - @_" );
     360
     361    my $locations;
     362    eval {
     363        # first - strip off any inaccesible instances
     364        $self->prune($key);
     365
     366        # check to see if there is an instance on $vol_name that should be the
     367        # sole survivor
     368        if (defined $vol_name) {
     369            $locations = $self->find_instances($key, $vol_name);
     370        }
     371
     372        if (defined $locations) {
     373            my $instances = $self->find_instances($key);
     374            foreach my $victim (@$instances) {
     375                next if $victim eq $locations->[0];
     376                $self->delete_instance($key, $victim);
     377            }
     378        } else {
     379            # nuke whatever
     380            my @stats = $self->stat($key);
     381            foreach (1 .. $stats[6]) {
     382                $self->cull($key);
     383            }
     384        }
     385
     386    };
     387    if ($@) {
     388        $log->logdie($@);
     389    }
     390
     391    $log->debug("leaving");
     392
     393    return $locations->[0];
    341394}
    342395
Note: See TracChangeset for help on using the changeset viewer.