Changeset 24996
- Timestamp:
- Aug 4, 2009, 11:42:45 AM (17 years ago)
- Location:
- trunk/Nebulous
- Files:
-
- 1 added
- 4 edited
-
Changes (modified) (1 diff)
-
MANIFEST (modified) (1 diff)
-
bin/neb-cull (modified) (6 diffs)
-
lib/Nebulous/Client.pm (modified) (8 diffs)
-
t/72_neb-cull.t (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous/Changes
r24930 r24996 8 8 - add Nebulous::Client->prune() method 9 9 - add Nebulous::Client->there_can_be_only_one() method 10 - add neb-cull --one_only flag 10 11 11 12 0.10 -
trunk/Nebulous/MANIFEST
r24930 r24996 102 102 t/70_neb-ls.t 103 103 t/71_client_there_can_be_only_one.t 104 t/72_neb-cull.t 104 105 t/90_nebclient.t 105 106 t/TEST.PL -
trunk/Nebulous/bin/neb-cull
r16183 r24996 16 16 use Pod::Usage qw( pod2usage ); 17 17 18 my ($server, $volume );18 my ($server, $volume, $one_only); 19 19 20 20 $server = $ENV{'NEB_SERVER'} unless $server; … … 23 23 'server|s=s' => \$server, 24 24 'volume|v=s' => \$volume, 25 'one_only|o' => \$one_only, 25 26 ) || pod2usage( 2 ); 26 27 … … 40 41 unless defined $neb; 41 42 43 my @cull_args; 44 push @cull_args, $key; 42 45 if (defined $volume) { 43 $neb->cull($key, $volume) 44 or die "failed to replicate Nebulous key: $key"; 46 push @cull_args, $volume; 47 } 48 49 if ($one_only) { 50 my $status = $neb->there_can_be_only_one(@cull_args); 51 if ($status == 0) { 52 die "not enough instances of Nebulous key: $key"; 53 } 54 if (not defined $status or $status < 1) { 55 die "failed to cull Nebulous key: $key - " . $neb->err 56 if defined $neb->err; 57 die "failed to cull Nebulous key: $key"; 58 } 45 59 } else { 46 $neb->cull($key) 47 or die "failed to replicate Nebulous key: $key"; 60 unless (defined $neb->cull(@cull_args)) { 61 die "failed to cull Nebulous key: $key - " . $neb->err; 62 } 48 63 } 49 64 … … 58 73 =head1 SYNOPSIS 59 74 60 neb-cull [--server <URL>] [--volume <volume name>] <key>75 neb-cull [--server <URL>] [--volume <volume name>] [--one_only] <key> 61 76 62 77 =head1 DESCRIPTION … … 77 92 78 93 Symbolic name of the volume to create the new instance on. 94 95 Optional. 96 97 =item * --one_only|-o 98 99 Removes all but one instances of an object. Any inaccessible instances are 100 removed. If C<--volume> is specified, and an instance exists on that volume, 101 all instances but the one on that volume are removed. 79 102 80 103 Optional. … … 110 133 =head1 COPYRIGHT 111 134 112 Copyright (C) 2007-200 8Joshua Hoblitt. All rights reserved.135 Copyright (C) 2007-2009 Joshua Hoblitt. All rights reserved. 113 136 114 137 This program is free software; you can redistribute it and/or modify it under -
trunk/Nebulous/lib/Nebulous/Client.pm
r24930 r24996 297 297 my $instances = $stats[6]; 298 298 if (defined $instances and $instances < 2) { 299 $ log->debug("can not cull - not enough instances");299 $self->set_err("can not cull - not enough instances"); 300 300 $log->debug("leaving"); 301 301 … … 305 305 $locations = $self->find_instances($key, $vol_name); 306 306 unless (defined $locations) { 307 $ log->debug( "no instances" );307 $self->set_err( "no instances" ); 308 308 $log->debug( "leaving" ); 309 309 … … 313 313 $locations = $self->find_instances($key); 314 314 unless ($locations) { 315 $ log->debug("no instances");315 $self->set_err( "no instances" ); 316 316 $log->debug("leaving"); 317 317 … … 320 320 321 321 if (scalar @{ $locations } < 2) { 322 $ log->debug("can not cull - not enough instances");322 $self->set_err("can not cull - not enough instances"); 323 323 $log->debug("leaving"); 324 324 … … 365 365 if (not defined $self->prune($key)) { 366 366 # use the prune() method to also determine if $key is valid 367 $removed = undef; 368 return; 367 die "invalid key: $key"; 369 368 } 370 369 … … 377 376 if (defined $locations) { 378 377 my $instances = $self->find_instances($key); 378 if (scalar @$instances < 2) { 379 die "not enough instances"; 380 } 379 381 foreach my $victim (@$instances) { 380 382 next if $victim eq $locations->[0]; … … 387 389 # start at one so cull() is called one less time then the # of 388 390 # instances 391 if ($stats->[6] < 2) { 392 die "not enough instances"; 393 } 389 394 for (my $i = 1; $i < $stats->[6]; $i++) { 390 395 $self->cull($key); … … 395 400 }; 396 401 if ($@) { 402 if ($@ =~ qr/invalid key/) { 403 $self->set_err($@); 404 return; 405 } 397 406 $log->logdie($@); 398 407 }
Note:
See TracChangeset
for help on using the changeset viewer.
