IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29890


Ignore:
Timestamp:
Dec 1, 2010, 12:44:13 PM (15 years ago)
Author:
bills
Message:

Add new method to allow a client to find out if a storage object exists.
Fix bugs in method there_can_be_only_one

File:
1 edited

Legend:

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

    r28525 r29890  
    379379        {
    380380            # volume
    381             type        => SCALAR,
     381            type        => SCALAR|UNDEF,
    382382            optional    => 1,
    383383        },
     
    401401        }
    402402
     403        # set the number of user copies to 1 to prevent replication
     404        $self->setxattr($key, 'user.copies', 1, 'replace');
     405
    403406        if (defined $locations) {
    404             my $instances = $self->find_instances($key);
    405             if (scalar @$instances < 2) {
    406                 die "not enough instances";
     407            my $instances = $self->find_instances($key, undef, 'find them all');
     408            if (scalar @$instances == 1) {
     409                # only one instance nothing to do
     410                return 0;
     411            }
     412            if (scalar @$instances == 0) {
     413                die "no instances";
    407414            }
    408415            foreach my $victim (@$instances) {
     
    416423            # start at one so cull() is called one less time then the # of
    417424            # instances
    418             if ($stats->[6] < 2) {
    419                 die "not enough instances";
     425            if ($stats->[6] ==  1) {
     426                # only one instance nothing to do
     427                return 0;
     428            }
     429            if ($stats->[6] == 0) {
     430                die "no instances";
    420431            }
    421432            for (my $i = 1; $i < $stats->[6]; $i++) {
     
    439450}
    440451
     452sub storage_object_exists
     453{
     454    my $self = shift;
     455
     456    # HI!
     457
     458    my ($key) = validate_pos(@_,
     459        {
     460            type => SCALAR,
     461        },
     462    );
     463
     464    $log->debug( "entered - @_" );
     465
     466    my $found = 0;
     467    eval {
     468        my $objects = $self->find_objects($key);
     469        if  ($objects) {
     470            $found = (scalar @$objects) > 0;
     471        }
     472    };
     473    if ($@) {
     474        if ($@ =~ qr/invalid key/) {
     475            $self->set_err($@);
     476            return;
     477        }
     478        $log->logdie($@);
     479    }
     480
     481    $log->debug("leaving");
     482
     483    return $found;
     484}
    441485
    442486sub lock
Note: See TracChangeset for help on using the changeset viewer.